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
- No free pages: the NVS partition has no empty page left. ESP-IDF's description says it may happen if the partition was truncated, for example after a partition table change made it smaller or moved it, so the old contents do not fit the new layout.
- New version found: the partition holds data in a format newer than this firmware's NVS understands, typically after flashing firmware built with an older ESP-IDF over one built with a newer one.
- Writing too often or too much: NVS is for small values that change now and then, not for logs or counters written every second.
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
- Remote access to an ESP32 without TLS: what it measured and what it costs
- Reaching an ESP32 web server from outside its network
- Updating ESP32 firmware over the internet, with rollback
- Guru Meditation Error: decoding the backtrace, and crashes from the field
- Remote logging: ESP_LOG without a serial cable
- Heap and stack monitoring in the field
- An ESP32 behind CGNAT, 4G or Starlink
- TLS memory usage on the ESP32, and how to reduce it
- Sharing an ESP32 sensor page with anyone, without port forwarding
- ArduinoOTA over the internet, with a rollback
- ESP32 remote access compared: port forwarding, ngrok, Cloudflare Tunnel, Tailscale
- esp_http_server slow? The 250 ms delay and the fix
- Before the first ESP32 ships: a field support checklist
- ESP32 exception decoder: a Guru Meditation backtrace to lines, in the browser