espressif / esp-idf-template

Template application for https://github.com/espressif/esp-idf
Other
335 stars 201 forks source link

Add nvs_flash_init Retry #11

Open jorgeespinoza0x20 opened 5 years ago

jorgeespinoza0x20 commented 5 years ago

In example esp-idf/examples/wifi/wps/main/wps.c, there is a retry if nvs_flash_init returns specific failure codes.

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.

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.