Reputation: 83
Board: ESP32-WROOM with 16MB Flash size
As the title: reading values written into ESP32 board NVS partition fail with error code 4354 (0x1102) which corresponds to ESP_ERR_NVS_NOT_FOUND.
The error on official ESP API page: ESP_ERR_NVS_NOT_FOUND = Id namespace doesn’t exist yet and mode is NVS_READONLY
I cannot understand why, since I init with proper namespace and with NVS_READWRITE flag.
The code:
esp_err_t ret = 0;
nvs_handle handler = 0;
ret = nvs_flash_init_partition("nvs");
log_e("nvs_flash_init_partition CODE: %d", ret);
delay(500);
ret = nvs_open_from_partition("nvs", "tele", NVS_READWRITE, &handler);
log_e("nvs_open CODE: %d", ret);
delay(500);
ret = nvs_set_u8(handler, "kk", 7);
log_e("nvs_set_u8 CODE: %d", ret);
delay(500);
ret = nvs_commit(handler);
log_e("nvs_commit CODE: %d", ret);
delay(500);
int8_t max_buffer_size = 256;
ret = nvs_get_i8(handler, "kk", &max_buffer_size);
log_e("nvs_get_u8 CODE: %d", ret);
log_e("nvs_get_u8 STORED: %d", max_buffer_size);
delay(500);
ret = nvs_flash_deinit_partition("nvs");
log_e("nvs_flash_deinit_partition CODE: %d", ret);
nvs_close(handler);
Note: I also tried without delays: same result.
the output:
begin(): nvs_flash_init_partition CODE: 0
begin(): nvs_open CODE: 0
begin(): nvs_set_u8 CODE: 0
begin(): nvs_commit CODE: 0
begin(): nvs_get_u8 CODE: 4354
begin(): nvs_get_u8 STORED: 0
begin(): nvs_flash_deinit_partition CODE: 0
Partitions:
# Espressif ESP32 Partition Table # Name, Type, SubType, Offset, Size, Flags nvs,data,nvs,0x9000,16K, otadata,data,ota,0xd000,8K, phy_init,data,phy,0xf000,4K, factory,app,factory,0x10000,8M, ota_0,app,ota_0,0x810000,1M, ota_1,app,ota_1,0x910000,1M,
Am I doing something wrong? Am I missing something?
Thanks!
UPDATE: Seemed that the test board flash was corrupted. I tried with another one and the code worked fine.
Upvotes: 2
Views: 3051
Reputation: 4770
Take a look at this note in the documentation for nvs_set_u8():
Note that actual storage will not be updated until nvs_commit function is called.
So add a call to nvs_commit()
immediately after nvs_set_u8()
:
ret = nvs_commit(handler);
log_e("nvs_commit CODE: %d", ret);
Upvotes: 4