ESP_ERR_NVS_NO_FREE_PAGES and ESP_ERR_NVS_NEW_VERSION_FOUND

nvs_flash_init() could not use the NVS partition as it is. Every ESP-IDF example handles these two codes the same way, and the fix erases what was stored there.

ESP_ERROR_CHECK failed: esp_err_t 0x110d (ESP_ERR_NVS_NO_FREE_PAGES) at 0x400d2a4f
file: "./main/main.c" line 42
func: app_main
expression: …

ESP_ERR_NVS_NO_FREE_PAGES (0x110d), ESP_ERR_NVS_NEW_VERSION_FOUND (0x1110). ESP-IDF's description: NVS partition doesn't contain any empty pages. This may happen if NVS partition was truncated. Erase the whole partition and call nvs_flash_init again. NVS partition contains data in new format and cannot be recognized by this version of code.

The fix ESP-IDF's examples use

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);

Erasing removes everything stored in NVS: WiFi credentials, calibration data, your own settings. On a development board that does not matter. On a device in the field it may, so understand why it happened before you ship the erase.

Why it happens

To see what is in an NVS partition, the free NVS editor reads a dump in the browser; the partition table editor shows where NVS sits and how big it is.

Related errors: ESP_ERR_NO_MEM · ESP_ERR_INVALID_STATE · ESP_ERR_OTA_VALIDATE_FAILED · esp_err_t codes. All ESP32 errors: the list. Codes and descriptions from ESP-IDF's headers; behaviour from the API documentation of the functions named. ESP-IDF's Error Handling guide.

More