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?
On an ESP32: Is using the F()Macro as pointless as using PROGMEM?
-
- Posts: 9730
- Joined: Thu Nov 26, 2015 4:08 am
Re: On an ESP32: Is using the F()Macro as pointless as using PROGMEM?
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.
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.
-
- Posts: 828
- Joined: Mon Jul 22, 2019 3:20 pm
Re: On an ESP32: Is using the F()Macro as pointless as using PROGMEM?
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?
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.
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?
Are these arguments valid only for the ESP32, or is the use of PROGMEM and F()-Macro equally pointless on ESP8266 ?
Who is online
Users browsing this forum: No registered users and 59 guests