[Solved] PROGMEM issue under Eclipes IDE

Hello peoples,

I am using Jantje's plugin under Eclipse Juno with version 1.0 of Arduino underneath and am developing a small SCADA server for my Freetronics Mega.
All is going along ok, except for the following issue I am having at present.

I wish to make use of storing fixed data, essentially just html strings, in flash using PROGMEM.
With the new version 1.x of Arduino IDE I understand you can use the F("message"); syntax as well.

When I use the Arduino IDE the simple test code compiles ok, but not if I use the same concept within Eclipse with Jantje's plugin.
So the test code is like this;

#include <avr/pgmspace.h>

String flashMessage PROGMEM = "message";

Now when I build this under Eclipse I get a warning message saying;

only initialized variables can be placed into program memory area

Oddly, when I then comment out the PROGMEM line, then save the file, and then un-comment the line and re-save, when I hover over the word PROGMEM I see the macro;

Macro Expabsion __attribute((progmem))

Which is what I would expect.
But if I then go ahead and re-build, I get the initial warning I mentioned.
This warning appears to me more of an error in that it is fatal and the code is not actually built to the point I can up-load it to the Arduino.

If I use the new F("message") syntax in my code, for example in a Serial.print statement, I get the same resulting messages.

I hope I have included enough details to explain my problem and the error.
Any ideas of what I am doing wrong or can do to rectify the situation?

Paul

Now when I build this under Eclipse I get a warning message saying; ... only initialized variables can be placed into program memory area

I believe there's a bug in older versions of the compiler that cause that warning to be produced.

Which compiler are you using?

String flashMessage PROGMEM = "message";

...does that work correctly in either environment?

The installed version of Arduino IDE I have is version 1.0 and is confirmed when I fire up the standard Arduino IDE
My Eclipse setup is configured to point there.

Looking at the Arduino 'versions.txt' file , I have;

avarice: 2.8
avr-libc: 1.6.4
avrdude: 5.4-arduino
bunutils: 2.19
gcc-3: 3.4.6
gcc-4: 4.3.2
gdb:6.8
libusb: 0.1.12
make: 3.81
simulavr: 0.1.2.5

I run on OSX 10.6.8

Coding, I am not sure what you mean when you ask

...does that work correctly in either environment?

From what I can see, PROGMEM verifies without errors in the Arduino IDE, not under Eclipse, which I assume is using the same compiler.

Paul

Further, from the preferences section of Eclipse, under C/C++ General, section 'Paths and Symbols' I see that for both GNU C and GNU C++ I have the following set;

/Appplications/Arduino.app/Contents/Resources/hardware/tools/avr/lib/gcc/avr/4.3.2/include
/Appplications/Arduino.app/Contents/Resources/hardware/tools/avr/avr/4.3.2/include-fixed
/Appplications/Arduino.app/Contents/Resources/hardware/tools/avr/avr/include

Paul

rockwallaby:
Coding, I am not sure what you mean when you ask

...does that work correctly in either environment?

From what I can see, PROGMEM verifies without errors in the Arduino IDE, not under Eclipse, which I assume is using the same compiler.

"Works" as-in...

  Serial.println( flashMessage );

...outputs "message" to the serial port. There is no documented constructor supporting PROGMEM string constants...

http://arduino.cc/en/Reference/StringConstructor

That could be because the documentation is lacking or it could mean that what you are trying to do will only work if you modify the String class.

Since it is only a warning message, it is allowing the code to compile, but it is not using the string from flash, but rather, from a copy from the RAM.

Coding, with reference to what I was attempting with Serial.print here is an example I was the following;
From forum section Arduino Playground - Memory

Serial.println(F("This string will be stored in flash memory"));

I understand what you are saying regarding the string data type, I shall try with another data type and report back.....

rockwallaby . . .

I wanted to confirm that this problem is not due to anything with me using Eclipse and the Arduino plugin, and so the following is just me using the Arduino IDE.

So, to recap, I am running OSX 10.6.8 with Arduino IDE version 1.0 as it comes.
I go into the Arduino preferences and set the 'build verbose' to true so I can see the output of the build on the IDE console.

With the following simple program to simply test what is going on;

#include <avr/pgmspace.h>

PROGMEM prog_uchar data[] = {"message one"};

void setup() {
    Serial.begin(9600);
    delay(500);
    Serial.println(F("Starting"));
    Serial.println(F("message two"));

}

void loop() {
    
}

When I verify this code, I get the errors I mentioned in my initial post and have reproduced them here from a the error part from the Arduino consol at build time;

PROGMEM_test.cpp:6: warning: only initialized variables can be placed into program memory area
PROGMEM_test.cpp: In function 'void setup()':
PROGMEM_test.cpp:11: warning: only initialized variables can be placed into program memory area
PROGMEM_test.cpp:12: warning: only initialized variables can be placed into program memory area

It points to an error with my PROGMEM and also my Serial.print(F("string")) lines.

Uploading and running the code does of course produce the two lines of data on the serial console, but that data is seemingly copied to ram at runtime negating the point of having stored in flash only.

It seems I am having problems with getting any sort of data stored into flash using techniques described on the Arduino playground or reference.

Am I missing something here guys?

rockwallaby . . . chewing and spewing :frowning:

avr-size sketch_oct01a.cpp.elf

text data bss dec hex filename
2118 16 176 2310 906 sketch_oct01a.cpp.elf

...add another println...

Serial.println(F("This is a long message to test the SRAM usage."));

...neither data nor bss changes...

text data bss dec hex filename
2174 16 176 2366 93e sketch_oct01a.cpp.elf

The compiler is incorrectly outputting the warning; ignore it.

Thanks O great 'Coding Awfully',

I can confirm doing the same test does indeed produce those results.

I did find however something small that was also adding to headaches.
In my real code for the projects' RTC using NTP where I had the following worked;

Serial.print('Local Time : ');

However, when put into flash, produced the fatal error;

initializer fails to determine size of '_C'

Changing the quoted text from single to double quotes then works, so;

Serial.print("Local Time : ");

I have downloaded the latest version of Arduino 1.0.1 and noticed no change as yet, the errors are still generated.

Thanks again Coding Goodly, I think I can proceed from here.
Ultimately, I will be placing my html text into files on SD as the project evolves.

rockingwallaby . . . .