I have an Uno project I'm trying to port to an ESP32 and working my way through the compiler's error messages. A lot of them have to do with my use of PROGMEM for storing individual and array constants (about 14KB worth) in flash on the AVR. I'd like to store them in flash on the ESP32, but it looks like PROGMEM isn't the way to do it. I haven't been able to track down a consistent explanation for how to do it via Google, so I'm hoping somebody here has been down this path. Thanks for any tips.
No other processor uses the proprietary AVR progmem stuff.
In most other processors you don't have the limitation that the AVR has so you can use const and directly access the data rather the way C/C++ intended rather than have to jump through hoops using progmem and indirect access functions.
All the complexity of using indirect access functions is due to the AVR limitation of not being able to directly access the flash.
That said, most of the other Arduino cores for processors provide AVR progmem emulation to allow moving over AVR proprietary code. So if you have something that was working on the AVR, it may work on the non AVR cores using that cores supplied AVR progmem emulation. It is less efficient in some cases, but does provide portability for AVR specific code.
Not sure what is included in the ESP32 core but the ESP8266 includes progmem emulation so code may "just work".
There are some other potential issues, in that do to the way the proprietary way the AVR progmem macros and types work, there are two ways that declarations could be done and still "work".
One way (the not correct way, IMO) "works" (kind of) in that it works on older version of avr-gcc but may or may not work on the newer versions of avr-gcc depending on how it was used and if it was intermixed with the other way of doing declarations and that way also will spit out warnings in C++ code.
The other way "just works" in older and newer versions of avr-gcc and does not issue any warnings in the newer version of avr-gcc including with C++.
Unfortunately, the original examples of how to use progmem provided by the Arduino IDE web pages was wrong (the incorrect way), while it did "work" on the older versions of avr-gcc, it broke on the newer versions of avr-gcc.
Because of this, there may still be older code there that uses the syntax shown on the Arduino IDE web pages that may have issues with the newer version of gcc which may cause issues with other non AVR cores.
So if you are porting some older AVR code, you may run into this.
Also, some libraries (for example a few of the Adafruit ones) include some of their own progmem mapping macros for non AVR processors. These were needed and helpful when 3rd party non AVR cores were first coming out, but now they often get in the way and can create problems.
Not sure what code you are porting or issues you are running into, but the direction you go depends a little bit on if you ever intend to back to AVR. If not, then you may want to consider ditching all the progmem stuff and simply using the C/C++ language the way it is designed to be used.
Just declare and define you variables and directly access them. Use const if you don't intend to modify them.
--- bill
Thanks, Bill. The AVR code was just written in the last month, but I’ll take out all the PROGMEMs and see how much farther I can get. I’d already confirmed that removing PROGMEM on one line, while leaving the const, allowed the line to compile, but I couldn’t tell if it was being placed into RAM or flash, since the rest of the code wouldn’t compile. I assumed flash, but you know what happens when you assume.
Does the code not compile on the ESP32 with the progmem stuff?
I've not used the ESP32 core but I would have thought it would at least compile given that they have progmem emulation in the ESP8266 core and would think it would be similar if not the same on the ESP32.
--- bill