Page 1 of 1
On an ESP32: Is using the F()Macro as pointless as using PROGMEM?
Posted: Mon Apr 26, 2021 4:27 pm
by ullixesp
The Arduino pages are full with recommendations on using PROGMEM to keep const data in Flash. However, this is unnecessary, as any const declared data are kept in Flash anyway. PROGMEM on a ESP32 is actually only a dummy, kept for code compatibility. The reason behind it, as I had learned, has to do with von Neumann vs. Harvard architecture.
Equally hotly advised is the use of the F() macro, like in 'F("This is a very long string")'. But my understanding is that the F()macro is only a means to make the string 'progmem'. Which would also be pointless on an ESP32.
Is that true?
Re: On an ESP32: Is using the F()Macro as pointless as using PROGMEM?
Posted: Wed Apr 28, 2021 5:58 am
by ESP_Sprite
Yes.
Re: On an ESP32: Is using the F()Macro as pointless as using PROGMEM?
Posted: Wed Apr 28, 2021 8:06 am
by ullixesp
That's what I had thought.
Now I went ahead and removed all of the F()s in my code (bin total is ~1MB on an ESP32) and looked at code size differences with xtensa-esp32-elf-size. Without the F()s I got a reduction in text of 400 bytes, and in data of 28 bytes.
Not that much after all, yet I had thought the F()s do nothing. And not only that, it seems it is actually counterproductive using F()s on an ESP32. I am surprised.
Re: On an ESP32: Is using the F()Macro as pointless as using PROGMEM?
Posted: Wed Apr 28, 2021 1:24 pm
by lbernstone
Note that const arrays are stored in the program memory (duh) and then mapped directly from flash into memory as needed. So, no flashstringhelper is needed- just a constant assignment. This allows you to store large files (eg javascripts or images) in your code as uint8_t arrays, and update them as part of your firmware. I often have a separate "bytefiles.h" that I include which defines variables like:
Code: Select all
const char* statusHtml = R"literal(
<html>
...
</html>
)literal";
const char favicon_jpg[] = {
0xff, 0xd8, 0xff, 0xe0, 0x00, 0x10, 0x4a, 0x46, 0x49, 0x46, 0x00, 0x01,
...
0xff, 0xd9
};
const int favicon_jpg_len = 4226;
Re: On an ESP32: Is using the F()Macro as pointless as using PROGMEM?
Posted: Fri Apr 30, 2021 7:58 am
by ullixesp
Yes, those 2 constructs look very familiar
. In particular the R-stuff is very helpful for HTML code.
Good to hear that it is not only convenient but also good practise. Thanks.
Re: On an ESP32: Is using the F()Macro as pointless as using PROGMEM?
Posted: Tue May 25, 2021 12:10 pm
by ullixesp
Are these arguments valid only for the ESP32, or is the use of PROGMEM and F()-Macro equally pointless on ESP8266 ?