NVS customized partition - ESP_ERR_NVS_NO_FREE_PAGES

jomi26@gmail.com
Posts: 8
Joined: Wed Nov 18, 2020 12:59 pm

NVS customized partition - ESP_ERR_NVS_NO_FREE_PAGES

Postby jomi26@gmail.com » Wed Feb 10, 2021 3:15 pm

Dear ESP experts,

I have found that if creating a separate NVS partition (See table below) I get an ESP_ERR_NVS_NO_FREE_PAGES error when calling nvs_flash_init_partition(..) in case the size is 0x1000. When changing the size to 0x2000 it works without an error.

I (64) boot: ## Label Usage Type ST Offset Length
I (71) boot: 0 nvs WiFi data 01 02 00009000 00006000
I (79) boot: 1 nvdb WiFi data 01 02 0000f000 00001000 --> when changed to 0x2000 it works
I (86) boot: 2 otadata OTA data 01 00 00010000 00002000
I (93) boot: 3 phy_ini RF data 01 01 00012000 00001000
I (101) boot: 4 factory factory app 00 00 00020000 00100000
I (108) boot: 5 ota_0 OTA app 00 10 00120000 00100000
I (116) boot: 6 ota_1 OTA app 00 11 00220000 00100000

I couldn't find documentation that there is a minimum size for a NVS partition (I probably overlooked it).
Could someone give a quick explanation why this is happening or where I can find the documentation?

Thanks in advance :)

ESP_Minatel
Posts: 364
Joined: Mon Jan 04, 2021 2:06 pm

Re: NVS customized partition - ESP_ERR_NVS_NO_FREE_PAGES

Postby ESP_Minatel » Wed Feb 10, 2021 4:08 pm

Hi,

For data type partitions, the minimum size is 0x1000 (4kB), but we recommend to size the NVS partition with at least 0x3000 (12kB).

This is due the Structure of a page.

jomi26@gmail.com
Posts: 8
Joined: Wed Nov 18, 2020 12:59 pm

Re: NVS customized partition - ESP_ERR_NVS_NO_FREE_PAGES

Postby jomi26@gmail.com » Thu Feb 11, 2021 3:23 pm

Hi ESP_Minatel,

thanks for the quick reply.

I have studied the NVS documentation again and checked my code. What I have found is that I always need to have at least one full page (0x1000bytes) free in my partition otherwise I get ESP_ERR_NVS_NO_FREE_PAGES error when calling nvs_flash_init_partition(..) or ESP_ERR_NVS_NOT_ENOUGH_SPACE when calling nvs_set_xx functions.

What I did is
1. I extended my partition size for partition "nvdb" from 0x1000 to 0x2000. No issues
2. I started to fill the first page (first 0x1000 bytes) until all 125 entries were written and then I wrote 1 more entry --> This failed with ESP_ERR_NVS_NOT_ENOUGH_SPACE
3. I extended my partition size for partition "nvdb" again. This time from 0x2000 to 0x3000. No issues to write the 126th entry to the 2nd page

Looking into the documentation it seems that there needs to be an empty page (page4) or I misinterpret it

Code: Select all

+--------+     +--------+     +--------+     +--------+
| Page 1 |     | Page 2 |     | Page 3 |     | Page 4 |
| Full   +---> | Full   +---> | Active |     | Empty  |   <- states
| #11    |     | #12    |     | #14    |     |        |   <- sequence numbers
+---+----+     +----+---+     +----+---+     +---+----+
    |               |              |             |
    |               |              |             |
    |               |              |             |
+---v------+  +-----v----+  +------v---+  +------v---+
| Sector 3 |  | Sector 0 |  | Sector 2 |  | Sector 1 |    <- physical sectors
+----------+  +----------+  +----------+  +----------+

Can you confirm that this behavior is intended? I find it hard to believe that on full page would never be used.

Thanks for your help

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: NVS customized partition - ESP_ERR_NVS_NO_FREE_PAGES

Postby WiFive » Thu Feb 11, 2021 3:58 pm

The only way to safely erase a page is to first copy all the data to a new page and then erase the old page. Otherwise you would have to cache the data in ram but it is not safe because if there was a power loss the data would be lost. So there must always be enough space for the copy operation available or no more nvs operations would be possible.

jomi26@gmail.com
Posts: 8
Joined: Wed Nov 18, 2020 12:59 pm

Re: NVS customized partition - ESP_ERR_NVS_NO_FREE_PAGES

Postby jomi26@gmail.com » Thu Feb 11, 2021 4:28 pm

Hi,

thanks for the explanation. Makes sense.

Thanks for your help.

djoshi
Posts: 53
Joined: Wed Jan 12, 2022 9:59 pm

Re: NVS customized partition - ESP_ERR_NVS_NO_FREE_PAGES

Postby djoshi » Mon Mar 07, 2022 11:54 pm

I am having a similar issue when I changed the partition setting for the purpose of OTA.

Where do I change the page size in the config menu setting?

ESP_Sprite
Posts: 9730
Joined: Thu Nov 26, 2015 4:08 am

Re: NVS customized partition - ESP_ERR_NVS_NO_FREE_PAGES

Postby ESP_Sprite » Tue Mar 08, 2022 1:36 am

djoshi wrote:
Mon Mar 07, 2022 11:54 pm
I am having a similar issue when I changed the partition setting for the purpose of OTA.

Where do I change the page size in the config menu setting?
You can't. It's a function of the flash erase size, and that depends on the flash chip itself. It's always 4K in any flash compatible with the ESP32.

djoshi
Posts: 53
Joined: Wed Jan 12, 2022 9:59 pm

Re: NVS customized partition - ESP_ERR_NVS_NO_FREE_PAGES

Postby djoshi » Wed Mar 09, 2022 4:38 pm

So what must i do?

ESP_Sprite
Posts: 9730
Joined: Thu Nov 26, 2015 4:08 am

Re: NVS customized partition - ESP_ERR_NVS_NO_FREE_PAGES

Postby ESP_Sprite » Thu Mar 10, 2022 2:55 am

...increase the partition size so NVS fits again?

Who is online

Users browsing this forum: No registered users and 77 guests