8000 LittleFS Mount Failure on ESP32-C3 · Issue #6579 · espressif/arduino-esp32 · GitHub
[go: up one dir, main page]

Skip to content
LittleFS Mount Failure on ESP32-C3 #6579
Closed
@brentru

Description

@brentru

Board

ESP32-C3

Device Description

Adafruit QT Py ESP32-C3

Hardware Configuration

Nothing attached.

Version

latest master

IDE Name

Arduino IDE

Operating System

macOS

Flash frequency

80Mhz

PSRAM enabled

no

Upload speed

115200

Description

Attempts to mount a LittleFS filesystem fails on ESP32-C3...

I am using the FS read PR (#6569) as well.

LittleFS configuration settings:

[LittleFS] data   : /Users/brent/Downloads/esp32_esp8266_test_littlefs/data
[LittleFS] offset : 0
[LittleFS] start  : 2686976
[LittleFS] size   : 1472
[LittleFS] page   : 256
[LittleFS] block  : 4096
->/secrets.json
[LittleFS] upload : /var/folders/k6/g066g1tn567fn8mj2p42x4240000gn/T/arduino_build_941002/esp32_esp8266_test_littlefs.littlefs.bin
[LittleFS] address: 2686976
[LittleFS] port   : /dev/cu.usbmodem1433301
[LittleFS] speed  : 115200
[LittleFS] mode   : dout
[LittleFS] freq   : 80m

Sketch

/* Checks and writes out the files on a LittleFS filesystem on ESP8266 and ESP32 platforms
   This sketch only performs READ operations on the LittleFS filesystem and should not modify the filesystem's contents.

   NOTE: The LittleFS image must have already been uploaded prior to using this sketch.
*/

#include <Arduino.h>
#include <FS.h>
#include <LittleFS.h>
#include <ArduinoJson.h>

StaticJsonDocument<512> jsonDoc; ///< JSON document

// Via https://github.com/espressif/arduino-esp32/blob/master/libraries/LittleFS/examples/LITTLEFS_test/LITTLEFS_test.ino
void listDir(fs::FS &fs, const char * dirname, uint8_t levels){
    Serial.printf("Listing directory: %s\r\n", dirname);

    #ifdef ARDUINO_ARCH_ESP8266
    File root = fs.open(dirname, "r");
    #else
    File root = fs.open(dirname);
    #endif

    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){
                #ifdef ARDUINO_ARCH_ESP8266
                listDir(fs, file.fullName(), levels -1);
                #else
                listDir(fs, file.path(), levels -1);
                #endif
            }
        } else {
            Serial.print("  FILE: ");
            Serial.print(file.name());
            Serial.print("\tSIZE: ");
            Serial.println(file.size());
        }
        file = root.openNextFile();
    }
}

// via https://github.com/espressif/arduino-esp32/blob/master/libraries/LittleFS/examples/LITTLEFS_test/LITTLEFS_test.ino
void readFile(fs::FS &fs, const char * path){
    Serial.printf("Reading file: %s\r\n", path);

    #ifdef ARDUINO_ARCH_ESP8266
    File file = fs.open(path, "r");
    #else
    File file = fs.open(path);
    #endif

    if(!file || file.isDirectory()){
        Serial.println("- failed to open file for reading");
        return;
    }

    Serial.println("- read from file:");
    while(file.available()){
        Serial.write(file.read());
    }
    Serial.println("");
    file.close();
}

void setup() {
  Serial.begin(115200);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB
  }



  // attempt to mount LittleFS filesystem
  Serial.print("Mounting LittleFS filesystem...");
  if(!LittleFS.begin()){
    Serial.println("ERROR: LittleFS Mount Failed!");
    return;
  }
  Serial.println("Mounted!");

  // list everything on the filesystem '/' directory where secrets is expected
  listDir(LittleFS, "/", 3);

  // check if WipperSnapper's `secrets.json` file exists on filesystem
  if (!LittleFS.exists("/secrets.json")) {
    Serial.println("ERROR: Unable to find secrets.json file on LittleFS filesystem!");
    while (1); // wait forever
  }

  // read out the secrets.json file in plain-text
  readFile(LittleFS, "/secrets.json");

  // Test we can open the secrets file using ArduinoJSON
  File secretsFile = LittleFS.open("/secrets.json", "r");
  if (!secretsFile) {
    Serial.println("ERROR: Unable to open secrets.json file from the LittleFS filesystem!");
    while (1); // wait forever
  }

  // Test we can deserialize the secrets file using ArduinoJSON
  DeserializationError err = deserializeJson(jsonDoc, secretsFile);
  if (err) {
    Serial.print("ERROR: Failed to deserialize secrets.json file with code: ");
    Serial.println(err.c_str());
    while (1); // wait forever
  }

  // Test parsing username from secrets.json file
  const char *io_username = jsonDoc["io_username"];
  // error check against default values [ArduinoJSON, 3.3.3]
  if (io_username == nullptr) {
    Serial.println("ERROR: Failed to parse io_username!");
    while(1); // wait forever
  }

  // Get IO key from JSON
  const char *io_key = jsonDoc["io_key"];
  // error check against default values [ArduinoJSON, 3.3.3]
  if (io_key == nullptr) {
    Serial.println("ERROR: Failed to parse io_key!");
    while(1); // wait forever
  }

  // Parse SSID
  const char *network_type_wifi_native_network_ssid = jsonDoc["network_type_wifi_native"]["network_ssid"];
  if (network_type_wifi_native_network_ssid == nullptr) {
    Serial.println("ERROR: Failed to parse network_type_wifi_native_network_ssid!");
    while(1); // wait forever
  }

  // Parse SSID password
  const char *network_type_wifi_native_network_password = jsonDoc["network_type_wifi_native"]["network_password"];
  // error check against default values [ArduinoJSON, 3.3.3]
  if (network_type_wifi_native_network_password == nullptr) {
    Serial.println("ERROR: Failed to parse network_type_wifi_native_network_password!");
    while(1); // wait forever
  }

  Serial.println("Parsed `secrets.json` values...");
  Serial.print("\tio_username: "); Serial.println(io_username);
  Serial.print("\tio_key: "); Serial.println(io_key);
  Serial.print("\tWiFi SSID: "); Serial.println(network_type_wifi_native_network_ssid);
  Serial.print("\tWiFi Password: "); Serial.println(network_type_wifi_native_network_password);

  // close the file
  secretsFile.close();

  // clear the JSON document and release all memory from the memory pool
  jsonDoc.clear();

  // close fs
  LittleFS.end();

  Serial.println("DONE!");
}

void loop() {
  // no-op
}

Debug Message

14:33:38.869 -> Mounting LittleFS filesystem..../components/esp_littlefs/src/littlefs/lfs.c:1071:error: Corrupted dir pair at {0x0, 0x1}
14:33:38.869 -> E (5935) esp_littlefs: mount failed,  (-84)
14:33:38.869 -> E (5936) esp_littlefs: Failed to initialize LittleFS
14:33:38.869 -> [  3023][E][LittleFS.cpp:94] begin(): Mounting LittleFS failed! Error: -1
14:33:38.869 -> ERROR: LittleFS Mount Failed!

Other Steps to Reproduce

No response

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.

Metadata

Metadata

Assignees

Type

No type

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0