We use custom partition table to have a small NVS partition and a large App partition (15Mb) and no OTA partition.
Project works when App size is less than 8MB and PSRAM is enabled. No error in accessing the NVS partition.
As soon as App size become greater than 8MB and PSRAM is kept enabled. Error generated on accessing the NVS data – (NVS partition not available)
Also even when App size is greater than 8MB but PSRAM is disabled. No error in accessing the NVS partition.
Error message:
E (2081) partition: load_partitions returned 0x101
ESP_ERROR_CHECK failed: esp_err_t 0x105 (ESP_ERR_NOT_FOUND) at 0x420084f8
0x420084f8: app_main at /main.c:18 (discriminator 1)
NVS access error in this code
- #include <stdio.h>
- #include "freertos/FreeRTOS.h"
- #include "freertos/task.h"
- #include "nvs_flash.h"
- #include "nvs.h"
- #include "esp_log.h"
- extern uint8_t MyFile_bin_start[] asm("_binary_MyFile_bin_start");
- int cnt=0;
- void app_main(void)
- {
- // Initialize NVS
- esp_err_t err = nvs_flash_init();
- if (err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND)
- {
- ESP_ERROR_CHECK(nvs_flash_erase());
- err = nvs_flash_init();
- }
- ESP_ERROR_CHECK(err);
- vTaskDelay(20 / portTICK_PERIOD_MS);
- nvs_handle_t nvs_handle;
- // Open NVS handle
- err = nvs_open("nvs", NVS_READWRITE, &nvs_handle);
- if (err != ESP_OK)
- {
- ESP_LOGI("MyLog", "Error (%s) opening write NVS handle!\n", esp_err_to_name(err));
- return;
- }
- // Read array from NVS under the provided key
- size_t required_size = 1 * sizeof(int);
- err = nvs_get_blob(nvs_handle, "cntData", &cnt, &required_size);
- if (err == ESP_OK)
- {
- ESP_LOGI("MyLog", "Array for key cntData retrieved successfully!\n");
- // for (int i = 0; i < size; i++) {
- // ESP_LOGI("MyLog","Array[%d] = %d\n", i, arr[i]);
- // }
- }
- else
- {
- ESP_LOGI("MyLog", "Error (%s) reading key %s!\n", esp_err_to_name(err), "cntData");
- }
- cnt++;
- // Write array to NVS under the provided key
- err = nvs_set_blob(nvs_handle, "cntData", &cnt, required_size);
- if (err != ESP_OK)
- {
- ESP_LOGI("MyLog", "Error (%s) writing to key %s!\n", esp_err_to_name(err), "cntData");
- }
- // Commit write
- err = nvs_commit(nvs_handle);
- if (err != ESP_OK)
- {
- ESP_LOGI("MyLog", "Error (%s) committing!\n", esp_err_to_name(err));
- }
- // Close NVS handle
- nvs_close(nvs_handle);
- ESP_LOGI("MyLog", "Cnt value: %d", cnt);
- cnt = MyFile_bin_start[0]; //array from external linked bin file
- }
A small project is attached to demonstrate this effect.
In this project an external bin file (MyFile.bin) containing a large size array is accessed from the App. By varying the data size of the bin file, overall app size can be made greater or less than 8MB.
The PSRAM usage is enabled / disabled using the menu-config option. (menuconfig -- ESP PSRAM -- Support for external, SPI-connected RAM)
In the project, at the beginning, a variable is accessed from the NVS storage area, incremented and stored back to NVS.
Any guidance/hint at solving the NVS partition access when App size is greater than 8MB and PSRAM enabled is appreciated.
Custom partition table:
# Name, Type, SubType, Offset, Size, Flags
nvs, data, nvs, 0xA000, 0x6000,
phy_init, data, phy, , 0x1000,
factory, app, factory, 0x100000, 15M,