Pages: [1]   Go Down
Author Topic: What should happen with PROGMEM at Compile or Upload ?  (Read 339 times)
0 Members and 1 Guest are viewing this topic.
Hannover, Germany
Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I want to save SRAM by using only one buffer for serial communication and getting a lot of predefined command sequences from the Flash-Memory, e.g. with <pgm_read_byte_near()> from a source like

PROGMEM prog_uchar testAlloc1[10] = {1,2,3,4,5,6,7,8,9,0};
(also tried: prog_uchar testAlloc1[10] PROGMEM = {1,2,3,4,5,6,7,8,9,0};)

Everything seems to work fine, I do not get any compilation error.
But I wonder, that the number of uploaded bytes is not depending on the usage of more or less PROGMEM allocations as shown above.
Should not these bytes be programmed in Flash and should they not influence the number of bytes as shown after compiling like:
Binary sketch size: 9.640 bytes (of a 524.288 byte maximum) - 1% used
Erase flash
Write 9716 bytes to flash

There is also no influence with declarations of static or volatile.

Now I fear, that my commands at the serial interface could be wrong and I have to search for the errors.
Or is there something else with the upload procedure?
Do they count only the "real code"?
Does someone know, how it works?
« Last Edit: September 07, 2013, 01:20:24 am by DrRobertPatzke » Logged

Hannover, Germany
Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

After several investigations I can reply myself. Here is, what I found:

It seems to be a matter of optimization by the "linker". I can see all data defined via PROGMEM in the object-files (*.o), but not in the result for programming Flash (number of bytes uploaded). As long as I do not really use the data by program! (Creating a reference).
I should have known this, but somehow I was trapped by my not eradicative assembler-thinking. Using assembler DB (Define Byte) is just creating something in code memory and code optimization is not a matter here.

Thanks to Arduinos F() it is easy to handle Flash-Data in SRAM-environment.
I tried the following and it worked perfectly:

Serial.println(F("Text in Flash"));
... is working like ...
prog_uchar myMessageInFlash[] PROGMEM = {"Text in Flash"};
Serial.println(F(myMessageInFlash));
... as well as ...
prog_uchar myMessageInFlash[] PROGMEM = {"Text in Flash"};
char *pointerInSRAM;
pointerInSRAM = (char *) F(myMessageInFlash);
Serial.println(pointerInSRAM);

I hope, I do not lead You to new traps by using that SRAM-pointer. Normally You should fetch Flash-data with functions like <pgm_read_byte_near()>.

Have a nice weekend ...
Logged

Pages: [1]   Go Up
Jump to: