Eeprom emulation for STM32, ESP32 and RP2350

I had an interesting discussion with GPT about nonVolatile storage of (motor) parameters without reflashing the whole chip everytime.
GPT stated, that all of our favourite MCUs have inbuild means to use flash memory to emulate EEprom.
Comparison chart:

It also came up with a SimpleFOC_EEPROM.h proposal, but I’m sure it’s not bulletproof

Your abstraction header (SimpleFOC_EEPROM.h) should expose basic functions like:

bool sys_eeprom_init();
bool sys_eeprom_write(uint16_t address, uint8_t *data, uint16_t length);
bool sys_eeprom_read(uint16_t address, uint8_t *data, uint16_t length);
bool sys_eeprom_commit(); // Crucial for platforms that queue writes

I wanted to start a discussion, whether this is a useful feature (especially when using the webcontroller)
I can provide a few more code snippets GPT spat out, but they should not be taken too seriously.

1 Answer

1

Definitely don’t provide GPT-produced code snippets. Those are fine for your own consumption, but if someone else wants an AI’s output they can prompt it themselves. I say this as a big fan of using AI for coding. Untested, unsolicited AI-produced code is rarely welcome.

I have used the ESP32’s flash memory to emulate an eeprom, and many other people have as well. Depending on your write frequency, wear leveling can be an issue, and the pseudo-filesystems (e.g. littlefs) that ship on these devices try to take that into account. If you plan on writing frequently, there are also tricks you can do to make the most of the flash without erasing too often. For example if you need a 16 bit counter that increments frequently, you can erase 16k of flash and set one bit at a time to get an amortized erase rate of 1/16k per increment.