开发板:ESP32-WROOM,16MB Flash 大小
如标题:读取写入 ESP32 板 NVS 分区的值失败,错误代码 4354 (0x1102) 对应于 ESP_ERR_NVS_NOT_FOUND。
官方 ESP API 页面上的错误: ESP_ERR_NVS_NOT_FOUND = Id namespace doesn't exist yet and mode is NVS_READONLY
我不明白为什么,因为我使用正确的命名空间和NVS_READWRITE标志进行了初始化。
编码:
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);
注意:我也毫不拖延地尝试过:同样的结果。
输出:
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
分区:
# 乐鑫 ESP32 分区表 # 名称、类型、子类型、偏移量、大小、标志 nvs,数据,nvs,0x9000,16K, otadata,数据,ota,0xd000,8K, phy_init,数据,phy,0xf000,4K, 工厂,应用程序,工厂,0x10000,8M, ota_0,app,ota_0,0x810000,1M, ota_1,app,ota_1,0x910000,1M,
难道我做错了什么?我错过了什么吗?
谢谢!
更新:似乎测试板闪存已损坏。我尝试了另一个,代码运行良好。