esp_err_t ret = nvs_flash_init();
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
ESP_ERROR_CHECK(nvs_flash_erase());
ret = nvs_flash_init();
}
ESP_ERROR_CHECK(ret);
I was really lucky to read a specific example that had the retry. Many of the other examples do not have the retry.
The source code for this template does not have the retry. If the template is a common starting point for writing production code then it would help if the retry was present in the template.
In example esp-idf/examples/wifi/wps/main/wps.c, there is a retry if
nvs_flash_init
returns specific failure codes.I was really lucky to read a specific example that had the retry. Many of the other examples do not have the retry.
I asked about this retry as a best practice on the ESP32 forum. @igrr responded that the retry as above is the correct thing to do for a production code.
The source code for this template does not have the retry. If the template is a common starting point for writing production code then it would help if the retry was present in the template.