使用NVS Partition Generator Utility nvs读取不到key值

ChiShaoJun
Posts: 32
Joined: Mon Sep 17, 2018 3:24 am

使用NVS Partition Generator Utility nvs读取不到key值

Postby ChiShaoJun » Fri Apr 19, 2019 7:32 am

https://docs.espressif.com/projects/esp ... n_gen.html
我这边是按照上面的流程进行操作
要生成的test.csv
  1. key,type,encoding,value
  2. namespace_name,namespace,,
  3. key1,data,u8,1
转.bin指令
  1. python ~/esp/esp-idf/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py --input test.csv --output test.bin --size 0x6000
分区表也进行了修改
  1. # Espressif ESP32 Partition Table
  2. #
  3. # Note: if you change the phy_init or app partition offset
  4. #       make sure to change the offset in Kconfig.projbuild
  5. #
  6. # Name,   Type, SubType, Offset,  Size, Flags
  7. nvs,      data, nvs,     0x9000,  0x6000,
  8. phy_init, data, phy,     0xf000,  0x1000,
  9. factory,  app,  factory, 0x10000, 1200000,
读取的函数
  1. #define TEST_STORAGE_NAMESPACE "namespace_name"    //nvs测试名字空间
  2. uint8_t test_data = 0;
  3. /******************************
  4. * 函数名称:get_nvs_csv_data
  5. * 作    者:Kyle
  6. * 日    期:20190419
  7. * 描    述:测试nvs
  8. * 输入参数:无
  9. * 返 回 值:无
  10. ******************************/
  11. esp_err_t get_nvs_csv_data(void)
  12. {
  13.     esp_err_t ret = ESP_FAIL;
  14.     esp_err_t err = ESP_FAIL;
  15.     nvs_handle read_nvs_handle;
  16.     size_t required_size = 1;
  17.     ESP_LOGI(SPP_TAG, "required_size:%d\n",required_size);
  18.  
  19.     // Open
  20.     ESP_ERROR_CHECK(nvs_open(TEST_STORAGE_NAMESPACE, NVS_READWRITE, &read_nvs_handle));
  21.  
  22.     // Read
  23.     err = nvs_get_blob(read_nvs_handle, "key1", &test_data, &required_size);
  24.     ESP_LOGI(SPP_TAG, "[ test data ]:%d\n",test_data);
  25.     if(err == ESP_OK)
  26.     {
  27.         ESP_LOGI(SPP_TAG, "[ test data ]:%d\n",test_data);
  28.         ret = ESP_OK;
  29.     }
  30.     else if(err == ESP_ERR_NVS_NOT_FOUND)
  31.     {
  32.         ESP_LOGI(SPP_TAG,"ESP_ERR_NVS_NOT_FOUND\n");
  33.     }
  34.  
  35.     // Commit
  36.     ESP_ERROR_CHECK(nvs_commit(read_nvs_handle));
  37.  
  38.     // Close
  39.     nvs_close(read_nvs_handle);
  40.  
  41.     return ret;
  42. }
但是得到的日志出来是
  1. I (264) SPP_ACCEPTOR_DEMO: required_size:1
  2.  
  3. I (274) SPP_ACCEPTOR_DEMO: [ test data ]:0
  4.  
  5. I (274) SPP_ACCEPTOR_DEMO: ESP_ERR_NVS_NOT_FOUND
if the requested key doesn't exist,key值不存在,请问下我是哪一步出现问题呢?
Attachments
烧写.png
烧写.png (45.03 KiB) Viewed 4741 times

ChiShaoJun
Posts: 32
Joined: Mon Sep 17, 2018 3:24 am

Re: 使用NVS Partition Generator Utility nvs读取不到key值

Postby ChiShaoJun » Sun May 05, 2019 7:51 am

问题找到了,把read的函数换成nvs_get_u8就好了

Code: Select all

I (262) SPP_ACCEPTOR_DEMO: required_size:1

I (272) SPP_ACCEPTOR_DEMO: [ test data ]:1

I (272) SPP_ACCEPTOR_DEMO: [ test data ]:1
日志打印

Who is online

Users browsing this forum: No registered users and 206 guests