NVS customized partition - ESP_ERR_NVS_NO_FREE_PAGES
-
- Posts: 8
- Joined: Wed Nov 18, 2020 12:59 pm
NVS customized partition - ESP_ERR_NVS_NO_FREE_PAGES
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
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
-
- Posts: 364
- Joined: Mon Jan 04, 2021 2:06 pm
Re: NVS customized partition - ESP_ERR_NVS_NO_FREE_PAGES
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.
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.
-
- Posts: 8
- Joined: Wed Nov 18, 2020 12:59 pm
Re: NVS customized partition - ESP_ERR_NVS_NO_FREE_PAGES
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
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
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
Re: NVS customized partition - ESP_ERR_NVS_NO_FREE_PAGES
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.
-
- Posts: 8
- Joined: Wed Nov 18, 2020 12:59 pm
Re: NVS customized partition - ESP_ERR_NVS_NO_FREE_PAGES
Hi,
thanks for the explanation. Makes sense.
Thanks for your help.
thanks for the explanation. Makes sense.
Thanks for your help.
Re: NVS customized partition - ESP_ERR_NVS_NO_FREE_PAGES
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?
Where do I change the page size in the config menu setting?
-
- Posts: 9730
- Joined: Thu Nov 26, 2015 4:08 am
Re: NVS customized partition - ESP_ERR_NVS_NO_FREE_PAGES
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.
Re: NVS customized partition - ESP_ERR_NVS_NO_FREE_PAGES
So what must i do?
-
- Posts: 9730
- Joined: Thu Nov 26, 2015 4:08 am
Re: NVS customized partition - ESP_ERR_NVS_NO_FREE_PAGES
...increase the partition size so NVS fits again?
Who is online
Users browsing this forum: Majestic-12 [Bot] and 105 guests