ESP32 EEPROM erasure during programming

Hi all,

Working with Arduino IDE and an ESP32 display module -- not familiar with either. Having a weird problem the EEPROM (which I gather is just a set-aside chunk of the main FLASH memory) having "too durable" EEPROM retention.

For reasons, I need the chip to distinguish between a power up after just having been programmed vs. a normal power-up. Normally with PICs I do that by checking if an EEPROM address has a given value. If that value is wrong, then code knows the PIC has never been programmed before or has just been reprogrammed. This is easily done because the Microchip IDE (optionally) erases EEPROM during programming.

The Arduino IDE doesn't seem to do this. Whatever is stored in that EEPROM space is seemingly preserved after programming. Is there some sort of obvious IDE setting to force EEPROM overwrite which I'm overlooking or some clever workaround?

a) The EEPROM emulation for the ESP32 is deprecated. Use Preferences.h instead.
b) you could define a variable "version" in your preferences. On Startup you check if the version in the sketch is the same as in preferences. if not - you know it is the first startup after programming and you can do your things you want to do - and write back the current version to the preferences.

1 Like

EEPROM for the ESP32 has been depreciated use https://docs.arduino.cc/hacking/software/Preferences to save the thing between reloads.

Thanks very much for the answers above. But...wow. Looking at it, that seems a complicated way to go. I'm not getting a good grasp of how any of that works. Sadly, I've yet to find a good kindergarten-level tutorial to walk my feeble mind through it. Any suggestions? Even a textbook could be helpful. But I'll keep digging at it.

Also, is there maybe an alternate IDE out there which might include an EEPROM overwrite function?

In the short term, I'm doing a seriously awful ugly workaround of using a 2nd program to step through EEPROM addresses writing 0's. Then loading my actual program. Killing a fly with an anvil. :roll_eyes:

Hi,
pay attention to this recommendation:
"Preferences works best for storing many small system values, rather than a few large values. If large amounts of data are to be stored, consider using a file library such as LitteFS."

ref: " Preferences — Arduino-ESP32 2.0.14 documentation "

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.