Skip to content

Fix for "only initialized variables can be placed into program memory area" warning #1793

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Lauszus opened this issue Jan 5, 2014 · 5 comments
Labels
Component: Core Related to the code for the standard Arduino API Component: Toolchain The tools used for compilation and uploading to Arduino boards

Comments

@Lauszus
Copy link
Contributor

Lauszus commented Jan 5, 2014

As discussed on the developer mailing list: https://groups.google.com/a/arduino.cc/forum/#!msg/developers/5iaId6nPzqA/jpgd38UdBqQJ.

Here is how I got rid of the incorrect "only initialized variables can be placed into program memory area" warning: https://github.com/felis/USB_Host_Shield_2.0/blob/f676812f84b3212779365b9950927a01209e4045/settings.h#L82-L96. This was done for the USB Host library, but could easily be used in the Arduino core as well.

See: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34734.
The fixed is based on the following comment: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34734#c4.

I have tested it myself on my local copy of the Arduino IDE and it works fine. I can send a pull request for that if you like?

@matthijskooijman
Copy link
Collaborator

I wonder if this workaround would have other side effects. A quick test using below test program shows the generated code (I compared avr-objdump -D output) is identical in both cases, so that sounds good.

  #include <avr/pgmspace.h> 

  //PROGMEM const int foo = 0xdead;
  const int foo __attribute__((section(".progmem.data"))) = 0xdead;

  int main() {
      return pgm_read_word(&foo);
  }

@cmaglie
Copy link
Member

cmaglie commented Feb 5, 2014

@Lauszus after applying your patch the following code:

prog_char a0[] PROGMEM = "Hello!";
prog_char a1[] PROGMEM = "Hi!";

PROGMEM const char *b[] = { a0, a1 };

void setup() {}
void loop() {}

gives an error:

sketch_feb05b.ino:5: error: b causes a section type conflict

any suggestion?

@cmaglie
Copy link
Member

cmaglie commented Feb 5, 2014

For the record, the Robot Control library uses this in:

utility/scripts_Hello_User.h

@Lauszus
Copy link
Contributor Author

Lauszus commented Feb 7, 2014

@cmaglie it looks like the fix is not that good after all then. Anyway this will be fixed when the toolchain hopefully gets updated ;)

@cmaglie
Copy link
Member

cmaglie commented Nov 18, 2014

This was fixed from 1.5.6 with the new toolchain. Closing...

@cmaglie cmaglie closed this as completed Nov 18, 2014
odewdney added a commit to odewdney/Marlin that referenced this issue Jan 3, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Core Related to the code for the standard Arduino API Component: Toolchain The tools used for compilation and uploading to Arduino boards
Projects
None yet
Development

No branches or pull requests

4 participants