Using a 64 KiB NVS partition to store 250 B blobs, the NVS works for a while, but after some seemingly random number of reads/writes/reboots the nvs_get_blob() will return 4354 (ESP_ERR_NVS_NOT_FOUND, "Id namespace doesn't exist yet and mode is NVS_READONLY"). Once the NVS gets into this state, it seems to subsequently keep returning the same error even if the device is rebooted. Critical sections of the code:
Code: Select all
// Initialisation and read (called from the start of app_main()):
esp_err_t ret = nvs_flash_init_partition(NVS_PARTITION_NAME);
nvs_handle handle;
size_t sz = sizeof(dev_context.dev);
ESP_ERROR_CHECK(nvs_open_from_partition(NVS_PARTITION_NAME, "device_info", NVS_READWRITE, &handle));
esp_err_t err = nvs_get_blob(handle, "info", &dev_context.dev, &sz); // Failure here sometimes
// Write (in a helper function):
ESP_ERROR_CHECK(nvs_open_from_partition(NVS_PARTITION_NAME, "device_info", NVS_READWRITE, &handle));
ESP_ERROR_CHECK(nvs_set_blob(handle, "info", &dev_context.dev, sz));
ESP_ERROR_CHECK(nvs_commit(handle));
nvs_close(handle);
// Deinitialisation (only at the end of app_main()):
nvs_flash_deinit_partition(NVS_PARTITION_NAME);