79335311

Date: 2025-01-07 08:30:58
Score: 1
Natty:
Report link

Not stating what framework you're working with doesn't help us help you, but since you said C/C++, we can cross off several. We'll just start at the top of the popularity contest. For either ESP-IDF or PIOArduino (the supported replacement for the abandoned PlatformIO project), you're looking for the NVS library that accesses key-value pairs in a special partition in Flash that handles wear-leveling and spreads the data over sectors to rotate wear.

https://docs.espressif.com/projects/esp-idf/en/v5.4/esp32s3/api-reference/storage/nvs_flash.html

Find an example of reading/writing a pair at https://github.com/espressif/esp-idf/tree/v5.4/examples/storage/nvs_rw_value

Note that there is a facility to use secure NVS partitions if your device is in danger of being physically compromised and contains high-value KV pairs. You can find further examples in the directories starting with nvs_ at https://github.com/espressif/esp-idf/tree/v5.4/examples/storage

Note that readers in the post-July-2027 future may need to fiddle with the "5.4" in the URLs of this answer once ESP-IDF 5.4 is EOL'ed.

Of course, there is no EEPROM in ESP32. It's actually pretty rare in modern devices, as flash memory is simply less expensive with faster access and longer wear cycles. All ESP32 devices (as of this writing) have some amount of internal Flash. Some have additional flash that's external to the chip but inside the module, and some ESP32 boards may have yet more flash on the SPI bus outside of the module. You can rely on there being flash present.

Reasons:
  • RegEx Blacklisted phrase (1): help us
  • Long answer (-1):
  • No code block (0.5):
  • Low reputation (0.5):
Posted by: Robert L