Skip to content

ESP-C3-12F crashes when serving static files with AsyncWebServer and LittleFS #5912

Closed
@AcuarioCat

Description

@AcuarioCat

Hardware:

Board: ESP-32-C3
Core Installation version: 2.0.0
IDE name: Visual Studio/Visual Micro
Flash Frequency: 80Mhz
PSRAM enabled: no
Upload Speed: 921600
Computer OS: Windows 10

Description:

I don't know if this is the ESP code or AsyncWebServer code that is causing the problem but...

When using the ESP-C3 with the AsyncWebServer and trying to serve a static file with server.serveStatic("/", LittleFS, "/"); the device crashes and resets.

Compiling and running the same code on an ESP32 works correctly with no crash.

Serving a file using server.on... works ok, no crash.
i.e. opening http://192.168.0.116/deb works ok
opening http://192.168.0.116/debug1.html crashes (debug1.html does not depend on any other LittleFS download, js, png etc..)

Sketch:

You need to create and upload some web pages using makelittlefs.exe to test this out. The code is from the simple_server.ino sample modified to serve files from LittleFS.

I'm running mklittlefs version: 0.2.3-27-gc41e51a

#include <Arduino.h>
#ifdef ESP32
#include <WiFi.h>
#include <AsyncTCP.h>
#elif defined(ESP8266)
#include <ESP8266WiFi.h>
#include <ESPAsyncTCP.h>
#endif
#include <ESPAsyncWebServer.h>
#include "LITTLEFS.h"

AsyncWebServer server(80);

const char* ssid = "YOUR_SSID";
const char* password = "YOUR_PASSWORD";

const char* PARAM_MESSAGE = "message";

void listDir(fs::FS& fs, const char* dirname, uint8_t levels) {
    Serial.printf("Listing directory: %s\r\n", dirname);

    File root = fs.open(dirname);
    if (!root) {
        Serial.println("- failed to open directory");
        return;
    }
    if (!root.isDirectory()) {
        Serial.println(" - not a directory");
        return;
    }

    File file = root.openNextFile();
    while (file) {
        if (file.isDirectory()) {
            Serial.print("  DIR : ");
            Serial.println(file.name());
            if (levels) {
                listDir(fs, file.path(), levels - 1);
            }
        }
        else {
            Serial.print("  FILE: ");
            Serial.print(file.name());
            Serial.print("\tSIZE: ");
            Serial.println(file.size());
        }
        file = root.openNextFile();
    }
}

void notFound(AsyncWebServerRequest* request) {
    request->send(404, "text/plain", "Not found");
}

void setup() {

    Serial.begin(115200);
    WiFi.mode(WIFI_STA);
    WiFi.begin(ssid, password);
    if (WiFi.waitForConnectResult() != WL_CONNECTED) {
        Serial.printf("WiFi Failed!\n");
        return;
    }

    Serial.print("IP Address: ");
    Serial.println(WiFi.localIP());


    // Format FileFS if not yet
    if (!LittleFS.begin())
    {
        Serial.println("LITTLEFS failed! AutoFormatting.");
        LittleFS.format();
    }

    Serial.println("Level 1:");
    listDir(LittleFS, "/", 1);

    server.on("/deb", HTTP_GET, [](AsyncWebServerRequest* request) {
        request->send(LittleFS, "/debug1.html");
        });

    server.on("/", HTTP_GET, [](AsyncWebServerRequest* request) {
        request->send(200, "text/plain", "Hello, world");
        });

    // Send a GET request to <IP>/get?message=<message>
    server.on("/get", HTTP_GET, [](AsyncWebServerRequest* request) {
        String message;
        if (request->hasParam(PARAM_MESSAGE)) {
            message = request->getParam(PARAM_MESSAGE)->value();
        }
        else {
            message = "No message sent";
        }
        request->send(200, "text/plain", "Hello, GET: " + message);
        });

    // Send a POST request to <IP>/post with a form field message set to <message>
    server.on("/post", HTTP_POST, [](AsyncWebServerRequest* request) {
        String message;
        if (request->hasParam(PARAM_MESSAGE, true)) {
            message = request->getParam(PARAM_MESSAGE, true)->value();
        }
        else {
            message = "No message sent";
        }
        request->send(200, "text/plain", "Hello, POST: " + message);
        });

    server.serveStatic("/", LittleFS, "/");
    server.onNotFound(notFound);

    server.begin();
}

void loop() {
}

Debug Messages:

Trying to open http://192.168.0.126/debug1.html throws error:
Guru Meditation Error: Core  0 panic'ed (Load access fault). Exception was unhandled.



Listing directory: /js
  FILE: jquery.min.js.gz	SIZE: 29240

Trying to open http://192.168.0.126/js/jquery.min.js throws the following error:
[ 41735][E][vfs_api.cpp:64] open(): /littlefs/js/jquery.min.js does not exist
Guru Meditation Error: Core  0 panic'ed (Load access fault). Exception was unhandled.

Core  0 register dump:
MEPC    : 0x4200862a  RA      : 0x4200868c  SP      : 0x3fcad5f0  GP      : 0x3fc8e800  
TP      : 0x3fc98bcc  T0      : 0x4005890e  T1      : 0x4038c298  T2      : 0x00300010  
S0/FP   : 0x3fca7764  S1      : 0x3fc961a4  A0      : 0x00000001  A1      : 0x98940ca0  
A2      : 0x3fca7764  A3      : 0x00000001  A4      : 0x3fc96000  A5      : 0x3fc961a4  
A6      : 0x3fe00000  A7      : 0x00000008  S2      : 0x3fca81dc  S3      : 0x3fca81ec  
S4      : 0x3fc961a4  S5      : 0x00000000  S6      : 0x00000000  S7      : 0x00000000  
S8      : 0x00000000  S9      : 0x00000000  S10     : 0x00000000  S11     : 0x00000000  
T3      : 0x0070015a  T4      : 0x7759990c  T5      : 0x00601700  T6      : 0x00723800  
MSTATUS : 0x00001881  MTVEC   : 0x40380001  MCAUSE  : 0x00000005  MTVAL   : 0x98940caf  
MHARTID : 0x00000000  

Stack memory:
3fcad5f0: 0x0a002c00 0x06ff0000 0x3fc961a4 0x00000000 0x00000000 0x00000000 0x00000000 0x0300b29e

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions