wokwi / wokwi-features

Wokwi Feature requests & Bug Reports
https://wokwi.com
74 stars 17 forks source link

ESP32 SPIFFS.begin error #587

Closed V1pr closed 1 year ago

V1pr commented 1 year ago

Describe the bug A clear and concise description of what the bug is.

Flash size: 4194304 bytes
E (2092) SPIFFS: spiffs partition could not be found
[  2103][E][SPIFFS.cpp:89] begin(): Mounting SPIFFS failed! Error: 261
FAILED.

Same result in VSCode simulator & firmware upload to simulator. Partitions are listed ok.

To Reproduce

Relevant code snipplet:

#if defined(ESP8266) || defined(ESP32)

        /* create custom characters */
        lcd.createChar(ICON_WIFI_CONNECTED, _iconimage_wifi_connected);
        lcd.createChar(ICON_WIFI_DISCONNECTED, _iconimage_wifi_disconnected);

        lcd.setCursor(0,0);
        lcd.print(F("Init file system"));
        DEBUG_PRINT("Init file system... ");
        lcd.setCursor(0,1);
        #if defined(ESP8266)
        if(!LittleFS.begin()) {
        #elif defined(ESP32)
            // Get the size of the flash memory
            uint32_t flash_size = ESP.getFlashChipSize();

            DEBUG_PRINTLN();
            DEBUG_PRINT(F("Flash size: "));
            DEBUG_PRINT(flash_size);
            DEBUG_PRINTLN(F(" bytes"));

            #if defined(ESP32_LIST_PARTITIONS)
            DEBUG_PRINTLN(F("ESP32 Partition table:"));

            DEBUG_PRINTLN(F("| Type | Sub |  Offset  |   Size   |       Label      |"));
            DEBUG_PRINTLN(F("| ---- | --- | -------- | -------- | ---------------- |"));

            esp_partition_iterator_t pi = esp_partition_find(ESP_PARTITION_TYPE_ANY, ESP_PARTITION_SUBTYPE_ANY, NULL);
            if (pi != NULL) {
                do {
                const esp_partition_t* p = esp_partition_get(pi);
                printf("|  %02x  | %02x  | 0x%06X | 0x%06X | %-16s |\r\n", 
                    p->type, p->subtype, p->address, p->size, p->label);
                } while (pi = (esp_partition_next(pi)));
            }
            #endif
        if(!SPIFFS.begin(ESP32_FORMAT_SPIFFS_IF_FAILED)) {
        #endif
            // !!! flash init failed, stall as we cannot proceed
            lcd.setCursor(0, 0);
            lcd_print_pgm(PSTR("Error Code: 0x2D"));
            DEBUG_PRINTLN(F("FAILED."));
            delay(10000);
            reboot_dev(REBOOT_CAUSE_PROGRAM);
        }
        DEBUG_PRINTLN(F("Done."));

        state = OS_STATE_INITIAL;

    #else

Expected behavior Code should continue to run, as on live hw.

Environment (please complete the following information):

Additional context platformio.ini settings:

platform = espressif32
board = esp32dev
framework = arduino
lib_ldf_mode = deep
lib_deps = 
    sui77/rc-switch @ ^2.6.3
    https://github.com/ThingPulse/esp8266-oled-ssd1306/archive/4.2.0.zip
    knolleary/PubSubClient @ ^2.8
    https://github.com/OpenThingsIO/OpenThings-Framework-Firmware-Library/archive/refs/heads/master.zip
    https://github.com/Links2004/arduinoWebSockets/archive/refs/tags/2.3.5.zip
    tobozo/ESP32-ENC28J60@^1.0.1
build_src_filter = +<*> -<html/*>
upload_speed = 460800
monitor_speed = 115200
urish commented 1 year ago

Can you please create a github repo with the complete setup?

V1pr commented 1 year ago

@urish sure, it's already there: https://github.com/V1pr/OpenSprinkler-Firmware-ESP32

Please keep in mind, that you'll have to modify the OpenThingsLibrary files a bit (as in readme):

OpenThings lib is not 100%, the following 2 functions must be added to Esp32LocalServer.cpp (don't forget to modify the .h as well):

void Esp32LocalClient::flush() {
    client.flush();
}

void Esp32LocalClient::stop() {
    client.stop();
}
urish commented 1 year ago

Thanks, seems like there are some other issues with the OpenThingsLibrary:

opensprinkler_server.cpp:253:89: error: no matching function for call to 'OTF::Response::writeHeader(const char [14], const char [47])'
  res.writeHeader(F("Cache-Control"), F("max-age=0, no-cache, no-store, must-revalidate"));
                                                                                         ^
In file included from .pio/libdeps/esp32_sprinkler/OpenThings-Framework-Firmware-Library/OpenThingsFramework.h:5,
                 from OpenSprinkler.h:50,
                 from opensprinkler_server.cpp:24:
.pio/libdeps/esp32_sprinkler/OpenThings-Framework-Firmware-Library/Response.h:48:10: note: candidate: 'void OTF::Response::writeHeader(const __FlashStringHelper*, const __FlashStringHelper*)'
     void writeHeader(const __FlashStringHelper *const name, const __FlashStringHelper *const value);
          ^~~~~~~~~~~
.pio/libdeps/esp32_sprinkler/OpenThings-Framework-Firmware-Library/Response.h:48:10: note:   no known conversion for argument 1 from 'const char [14]' to 'const __FlashStringHelper*'
.pio/libdeps/esp32_sprinkler/OpenThings-Framework-Firmware-Library/Response.h:50:10: note: candidate: 'void OTF::Response::writeHeader(const __FlashStringHelper*, int)'
     void writeHeader(const __FlashStringHelper *const name, int value);
          ^~~~~~~~~~~
.pio/libdeps/esp32_sprinkler/OpenThings-Framework-Firmware-Library/Response.h:50:10: note:   no known conversion for argument 1 from 'const char [14]' to 'const __FlashStringHelper*'
opensprinkler_server.cpp:254:45: error: no matching function for call to 'OTF::Response::writeHeader(const char [11], const char [6])'
  res.writeHeader(F("Connection"), F("close"));
                                             ^
In file included from .pio/libdeps/esp32_sprinkler/OpenThings-Framework-Firmware-Library/OpenThingsFramework.h:5,
                 from OpenSprinkler.h:50,
                 from opensprinkler_server.cpp:24:
.pio/libdeps/esp32_sprinkler/OpenThings-Framework-Firmware-Library/Response.h:48:10: note: candidate: 'void OTF::Response::writeHeader(const __FlashStringHelper*, const __FlashStringHelper*)'
     void writeHeader(const __FlashStringHelper *const name, const __FlashStringHelper *const value);
          ^~~~~~~~~~~
.pio/libdeps/esp32_sprinkler/OpenThings-Framework-Firmware-Library/Response.h:48:10: note:   no known conversion for argument 1 from 'const char [11]' to 'const __FlashStringHelper*'
.pio/libdeps/esp32_sprinkler/OpenThings-Framework-Firmware-Library/Response.h:50:10: note: candidate: 'void OTF::Response::writeHeader(const __FlashStringHelper*, int)'
     void writeHeader(const __FlashStringHelper *const name, int value);
          ^~~~~~~~~~~
.pio/libdeps/esp32_sprinkler/OpenThings-Framework-Firmware-Library/Response.h:50:10: note:   no known conversion for argument 1 from 'const char [11]' to 'const __FlashStringHelper*'
V1pr commented 1 year ago

@urish unfortunatelly no, that's a result of a f*cked up commit in ESP32 arduino framework (already fixed, but pio still uses it). Fastest is a manual fix in \Users\<CURR_USER.platformio\packages\framework-arduinoespressif32\core\esp32\WString.h:

// A pure abstract class forward used as a means to proide a unique pointer type
// but really is never defined.
class __FlashStringHelper;
//#define FPSTR(pstr_pointer) (pstr_pointer)
#define FPSTR(pstr_pointer) (reinterpret_cast<const __FlashStringHelper *>(pstr_pointer))
#define F(string_literal) (FPSTR(PSTR(string_literal)))  

( simply replace the F() and FPSTR() macro )

urish commented 1 year ago

Yeah, now it compiles and I can see the error:

image

urish commented 1 year ago

The reason you're getting it is because you are loading "firmware.bin", which does not contain the partition table, only the actual firmware.

You can fix it by switching to firmware_merged.bin instead. Change line 3 of wokwi.toml to

firmware = '.pio\build\esp32_sprinkler\firmware_merged.bin'

and line 6 of diagram.json to

    { "type": "wokwi-esp32-devkit-v1", "id": "esp", "top": 0, "left": 0, "attrs": { "firmwareOffset": "0" } },

then it seems to work (or, at least, find the SPIFFS partition):

image

V1pr commented 1 year ago

Thanks for checking! (meanwhile I've figured out, that the error above is due to the facts, that the SPIFFS is not formatted - the code seemingly stops, 'cos it's formatting the flash)

@urish I've tried the firmware_merged.bin before, but the simulator stalled at 'loading project' in VSCode. It was my bad, since I've also changed the path ot the ELF to firmware_merges.elf, which did not exists. IMHO it would be a good idea to check the existance of it upon startup ad throw an error.

(the code now failes, where it's failing on a live board)