Page 1 of 1

custom memory partition on ESP32-c6

Posted: Fri Nov 03, 2023 4:31 pm
by MohamedTrabelsi
Hello guys,
I'm working on a project that needs to store configuration data on the flash memory so I generated this csv file
then I tried to initialize the desired partition using a this function
  1. #include <stdio.h>
  2. #include "freertos/FreeRTOS.h"
  3. #include "freertos/task.h"
  4. #include "nvs_flash.h"
  5.  
  6.  
  7. void init_nvs(const char *partition_name) {
  8.     esp_err_t ret = nvs_flash_init_partition(partition_name);
  9.     if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
  10.         ESP_ERROR_CHECK(nvs_flash_erase_partition(partition_name));
  11.         ret = nvs_flash_init_partition(partition_name);
  12.         printf("done");
  13.     }
  14.     ESP_ERROR_CHECK(ret);
  15.     printf("error");
  16. }
  17.  
  18. void app_main() {
  19.    
  20.     init_nvs("wifi");
  21. }
but I got error and that how it looks like

Re: custom memory partition on ESP32-c6

Posted: Mon Nov 06, 2023 2:41 am
by ESP_adokitkat
Hello.

The minimal size for a NVS partition is 0x3000 bytes and recommended size is 0x6000 bytes. It seems like you put sizes too small (0x24 and 0x4 bytes) into the partition table .csv file (which you don't need to do - when left blank it the partition will start from the offset to the next one). However, the difference in your offsets is too little as well to fit 0x3000 or 0x6000 bytes there (0xa000-0x9000=0x1000).

Also I don't think need to create so many NVS partitions - create just one and use namespaces to avoid key name conflicts (1 nvs partition with 6 namespaces: ap1, ap2, ap3, wifi, ble, cfg).

Code: Select all

# Partition table .csv file
# Name,   Type, SubType, Offset,  Size, Flags
nvs,      data, nvs,     0x9000,  0x6000,
...

Re: custom memory partition on ESP32-c6

Posted: Mon Nov 06, 2023 10:06 am
by MohamedTrabelsi
Thank you for pointing out the partition size discrepancy.
Regarding the suggestion to create just one NVS partition with multiple namespaces, that makes a lot of sense.
Thanks again for your assistance.