LittleFS fails to initialize on the Arduino Nano ESP32

I everyone! Just got my brand new nano esp32 and wanted to give a try to the LittleFS library on it, but it just doesn't work. This is what I've done so far (using Platformio):

FILE SYSTEM UPLOAD

I created the data folder, containing a .txt file, on the same level of the src folder, and then uploaded it using the Build file system and Upload file system functions. The csv partition table i've used is the following:

# Name,   Type, SubType, Offset,  Size, Flags
nvs,      data, nvs,     0x9000,  0x5000,
otadata,  data, ota,     0xe000,  0x2000,
app0,     app,  ota_0,   0x10000, 0x2F0000,
app1,     app,  ota_1,   0x300000, 0x2F0000,
spiffs,   data, spiffs,  0x5F0000, 0xA10000,

Everything went smooth and the file system was uploaded starting from address 0x5F0000 (the same one that is specified in the csv for the spiffs partition)

PLATFORMIO.INI CONFIGURATION

[env:arduino_nano_esp32]
platform = espressif32
board = arduino_nano_esp32
;upload_protocol = esptool ; protocol used for the filesystem upload
board_build.filesystem = littlefs
board_build.partitions = partitions.csv

ARDUINO CODE

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

#define FORMAT_LITTLEFS_IF_FAILED true

void setup() {
    Serial.begin(9600);
    while (!Serial);

    if (!LittleFS.begin(FORMAT_LITTLEFS_IF_FAILED)) {
        Serial.println("Mounting Failed");
        while (true);
    }
    Serial.println(":)");
}

void loop() {

}

There is no problem during the uploading of the arduino code, but LittleFS always fails to initialize.
After some time I've been able to print to the serial monitor the error code returned from the begin method (ESP_ERR_NOT_FOUND) and found out that that specific error is returned when Littlefs can't find its partition.

What am i doing wrong? The filesystem was uploaded correctly in the address specified on the partition table and there is no error during compilation, so i don't have any clue of what the problem is.
If anyone has any clue on how to fix this or knows what i am doing wrong, please lmk! Thanks!

Hello @endermaker878!
Can you please attempt the process following the initial steps from our guide over at https://docs.arduino.cc/tutorials/nano-esp32/spiff to test if this is able to mount?

Thank you so much! It set up the partition correctly and finally worked even with Platformio projects.

1 Like

Could we perhaps have some explanation of how setting up a SPIFFS filesystem (the link in the solution) solved a LittleFS problem? I don't doubt that it helped the original poster, but I'm confused.

The original issue was that the data partition was FAT formatted by the first sketches that ran on the board. Most sketches will then refuse to format/initialize a non-empty partition, to avoid destroying useful data.

The trick is the "Burn bootloader" step.

It's all slightly weird in ESP32 land, but what this action really does is, it erases the whole Flash of the device, forcing it to run the ROM bootloader as a fallback (hence the name!). This has the other side effect of clearing the data partition, which then makes formatting code happy, regardless of the file system you end up using :slight_smile:

2 Likes

Transferring LittleFS data to the Arduino Nano ESP32 involves a process in which I combined the BasicOTA and LittleFS examples using Arduino IDE 1.8.12. Upon uploading the sketch through the standard procedure using the COM port, switch to the Network Port in the Tools Menu and select the ‘ESP Sketch data upload’ option to load files from the data directory using DFU mode.
To erase all data, upload an empty data directory. For insights into the process, connect a terminal program to the COM port to monitor the ongoing activities.