nvs_flash_init_partition returns ESP_ERR_NVS_NOT_ENOUGH_SPACE

vincecube
Posts: 1
Joined: Fri Mar 22, 2024 9:08 am

nvs_flash_init_partition returns ESP_ERR_NVS_NOT_ENOUGH_SPACE

Postby vincecube » Fri Mar 22, 2024 1:30 pm

Chip : ESP32
NVS custom partition size : 16 kB

Hi,
When calling nvs_flash_init_partition on a NVS custom partition at startup, the function returns ESP_ERR_NVS_NOT_ENOUGH_SPACE error. This NVS custom partition is meant to hold only blob data, some of which are written only once and some are written regularly on a minute basis.
The item that is written every minute is a blob type of 8 bytes.

A memory dump of the NVS custom partition shows that 3 pages are marked as FULL and one page is marked as FREEING. Looking at entries bitmap of each page shows that there are plenty of erased entries, respectively 87, 123, 94 and 96.

Is there a way to fix this ?

ESP_rrtandler
Posts: 24
Joined: Wed May 31, 2023 6:54 pm

Re: nvs_flash_init_partition returns ESP_ERR_NVS_NOT_ENOUGH_SPACE

Postby ESP_rrtandler » Tue Mar 26, 2024 10:14 pm

Hi Vincecube,

The state of NVS flash you are describing - 3 pages are marked as FULL and one page is marked as FREEING is assumed to be inconsistent for nvs_init function. It expects at least one ACTIVE or UNINITIALIZED page when it sees FREEING page. I am not sure what caused the state you describes, perhaps some power off event in sensitive part of the code.

Regarding the storage of just 8 bytes, please consider using nvs_set_u64 / nvs_get_u64 instead of BLOBs. The total overhead connected with 8 bytes long BLOBs is 64 bytes. In case of u64, just 32 bytes are used. R/W is faster and thus less susceptible to power off event. Another advantage is in less fragmented NVS page space.

Who is online

Users browsing this forum: No registered users and 174 guests