Error on nvs_flash_init(). Worked on Mac but failure no Windows

Hi, I’m trying to develop a single application to scan wifi access points.

I used the example program as start point. And it worked fine in my PlatformIO in Mac (High Sierra).

I’ve tried to use the same project in a Windows machine. It build fine, but when I try to run, I got this error:

ESP_ERROR_CHECK failed: esp_err_t 0x1110 (ESP_ERR_NVS_NEW_VERSION_FOUND) at 0x400d0a36
file: "src/main.c" line 16
func: wifiInit
expression: nvs_flash_init()

Backtrace: 0x4008d567:0x3ffcbc40 0x4008dad0:0x3ffcbc60 0x400d0a36:0x3ffcbc80 0x400d0ad2:0x3ffcbd40 0x400d0c78:0x3ffcc400

I had already deleted the folder: %HOMEPATH%\.platformio\packages\framework-espidf before build to download a new set of files.

But without success.

See below my entire code and the platformio.ini file:

#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_event_loop.h"
#include "esp_wifi.h"
#include "esp_log.h"
#include "nvs_flash.h"

#define MAX_APs 20

static esp_err_t event_handler(void * ctx, system_event_t *event) {
  return ESP_OK;
}

void wifiInit() {
  ESP_ERROR_CHECK(nvs_flash_init());
  tcpip_adapter_init();
  ESP_ERROR_CHECK(esp_event_loop_init(event_handler, NULL));

  wifi_init_config_t wifi_config = WIFI_INIT_CONFIG_DEFAULT();
  ESP_ERROR_CHECK(esp_wifi_init(&wifi_config));
  ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
  ESP_ERROR_CHECK(esp_wifi_start());

}

static char *getAuthModeName(wifi_auth_mode_t auth_mode)
{
  char *names[] = {"OPEN", "WEP", "WPA PSK", "WPA2 PSK", "WPA WPA2 PSK", "MAX"};
  return names[auth_mode];
}

void app_main()
{
  wifiInit();

  wifi_scan_config_t scan_config = {
    .ssid = 0,
    .bssid = 0,
    .channel = 0,
    .show_hidden = true
  };

  ESP_ERROR_CHECK(esp_wifi_scan_start(&scan_config, true));

  wifi_ap_record_t wifi_records[MAX_APs];

  uint16_t maxRecods = MAX_APs;
  ESP_ERROR_CHECK(esp_wifi_scan_get_ap_records(&maxRecods, wifi_records));

 printf("Found %d access points:\n", maxRecods);
  printf("\n");
  printf("               SSID              | Channel | RSSI |   Auth Mode |    MAC ADDRESS    |\n");
  printf("----------------------------------------------------------------|-------------------|\n");
  for (int i = 0; i < maxRecods; i++)
    printf("%32s | %7d | %4d | %12s| %02x:%02x:%02x:%02x:%02x:%02x\n", (char *)wifi_records[i].ssid, wifi_records[i].primary, wifi_records[i].rssi, getAuthModeName(wifi_records[i].authmode), 
      wifi_records[i].bssid[0], wifi_records[i].bssid[1], wifi_records[i].bssid[2], wifi_records[i].bssid[3], wifi_records[i].bssid[4], wifi_records[i].bssid[5]);
  printf("-------------------------------------------------------------------------------------\n");
}

platformio.ini

[env:wemosbat]
platform = espressif32
board = wemosbat
framework = espidf
monitor_speed = 115200

This would be very weird. Both the Windows and Mac machine should work from the same codenbase.

Can you post the output that appears at the start of compilation for both machines? It contains info about the used platform and packages version, as in e.g.

Processing esp32dev (platform: espressif32; board: esp32dev; framework: arduino)
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/esp32dev.html
PLATFORM: Espressif 32 (3.1.0) > Espressif ESP32 Dev Module
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (esp-prog) External (esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES:
 - framework-arduinoespressif32 3.10005.210308 (1.0.5)
 - tool-esptoolpy 1.30000.201119 (3.0.0)
 - toolchain-xtensa32 2.50200.97 (5.2.0)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
1 Like

Hi @maxgerhardt

This is the output of Mac OSX:

Processing wemosbat (platform: espressif32; board: wemosbat; framework: espidf)
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/wemosbat.html
PLATFORM: Espressif 32 (3.2.0) > WeMos WiFi and Bluetooth Battery
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (esp-prog) External (esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES: 
 - framework-espidf 3.40200.210118 (4.2.0) 
 - tool-cmake 3.16.4 
 - tool-esptoolpy 1.30000.201119 (3.0.0) 
 - tool-ninja 1.9.0 
 - toolchain-esp32ulp 1.22851.191205 (2.28.51) 
 - toolchain-xtensa32 2.80400.210211 (8.4.0)
Warning! Starting with ESP-IDF v4.0, new project structure is required: 
https://docs.platformio.org/en/latest/frameworks/espidf.html#project-structure
Reading CMake configuration...
Generating assembly for certificate bundle...
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft

And this, the output of Windows 10

Processing wemosbat (platform: espressif32; board: wemosbat; framework: espidf)
--------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via -v, --verbose option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/wemosbat.html
PLATFORM: Espressif 32 (1.6.0) > WeMos WiFi and Bluetooth Battery
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (esp-prog) External (esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES:
 - framework-espidf 3.30102.190109 (3.1.2)
 - tool-espotapy 1.1.3
 - tool-esptoolpy 1.20600.0 (2.6.0)
 - tool-mkspiffs 2.230.0 (2.30)
 - toolchain-xtensa32 2.50200.80 (5.2.0)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft

Max likely had a suspicion and it is confirmed: You are using a considerably older framework version on Windows than on macOS:

Windows:

  • framework-espidf 3.30102.190109 (3.1.2)

macOS:

  • framework-espidf 3.40200.210118 (4.2.0)

So the NVS area on the ESP32 has been written with a current version of the framework and now you have uploaded code based on an old version. That version is unable to work with the NVS data in the new format. The error code ESP_ERR_NVS_NEW_VERSION_FOUND indicates this as well.

Run Update All from QUICK ACCESS menu to bring your Windows installation up to date and try again.

2 Likes

@manuelbl and @maxgerhardt thanks so much for your help.

I’d like to mark both replies as solutions, but I can’t :slight_smile:

1 Like