接前一篇文章:ESP32-C3模组上跑通NVS(6)
上一回讲到乐鑫技术支持发来了操作自定义NVS分区的代码。本回就对于代码进行详细解析,并通过此过程看一下具体应如何进行正确的操作。下边就开始代码分析:
主函数
主函数即app_main()代码如下:
void app_main(void)
{
esp_err_t err = nvs_flash_init_partition(STORAGE_PARTITION);
if (err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND) {
// NVS partition was truncated and needs to be erased
// Retry nvs_flash_init
ESP_ERROR_CHECK(nvs_flash_erase());
err = nvs_flash_init_partition(STORAGE_PARTITION);
}
ESP_ERROR_CHECK( err );
uint32_t count