ESP32 wear-leveling and memory size

Hi all,

Kind of wordy questions below, sorry.

I'm using an ESP32 -WROVER-B and need to periodically store a few values (elapsed minutes and hours) to non-volatile memory. Thanks to helpful people here I've learned I need to use Preferences rather than the now unsupported EEPROM function. Still trying to grasp how Preferences works exactly, but at least I think I understand how to use the commands. (Monkey doesn't understand fire, but can bang the rocks together to make fire).

I've read online that automatic memory wear-leveling is built into this process. Is that correct? Do I need a command to set aside a given amount of flash memory for this leveling? Or is the amount of "fake EEPROM" flash space pre-set by the architecture? Or does Preferences just use all free flash space not taken up with the program itself?

I'd like to store updated elapsed time values every 5 minutes (maybe even every 2 minutes). When I initially looked at this a few months ago I somehow calculated that provided wear-leveling is automatic and there's a maximum 10,000 cell write limit the memory should be guaranteed for at least 20 years of writes. Does that seem plausible?

Yes.

Preferences.h has these two #includes
#include "nvs.h"
#include "nvs_flash.h"

The documention of the nvs storage and the scheme which moves entries around is here
https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/storage/nvs_flash.html

See the section marked "Internals" where it says:

NVS stores key-value pairs sequentially, with new key-value pairs being added at the end. When a value of any given key has to be updated, a new key-value pair is added at the end of the log and the old key-value pair is marked as erased.

Or does Preferences just use all free flash space not taken up with the program itself?

I believe that Preferences.h uses all the available flash space available for nvs in the Partition Table set by tools in the Arduino IDE.

You can find the arrangements here.

AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.6\tools\partitions

With the default scheme listed as 4MB with spiffs, there is 0x5000 bytes shown (approximately 20K) for nvs. I think this nvs allocation holds for most of the partition schemes.

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