LittleFS/SPIFFS issues with Adafruit Feather ESP32-S3 TFT

Hi!

I’m having issues using LittleFS and SPIFFS with my Adafruit Feather ESP32-S3 TFT. I have code that is working fine on the Arduino IDE, but LittleFS and SPIFFS cannot be successfully be started with pio running on VS Code, whether it’s ran on Ubuntu 24.04 or windows 11.

This is my main.cpp code:

#include "LittleFS.h"

String fileContent = ""; // Global string to store file content

int led = LED_BUILTIN;

void setup()
{
  pinMode(led, OUTPUT);

  Serial.begin(115200);
  delay(10000); // wait for 10 seconds

  //This always returns false
  if (!LittleFS.begin())
  {
    Serial.println("An Error has occurred while mounting LittleFS");
    return;
  }

  File file = LittleFS.open("/text.txt", "r");
  if (!file)
  {
    Serial.println("Failed to open file for reading");
    return;
  }

  Serial.println("Reading file content...");
  while (file.available())
    fileContent += (char)file.read();

  file.close();
}

void loop()
{
  if (!fileContent.isEmpty())
    Serial.println("file contains: " + fileContent);
  else
    Serial.println("could not read file");

  //blink the led
  digitalWrite(led, HIGH);
  delay(500);
  digitalWrite(led, LOW);
  delay(500);
}

This is my platformio.ini file:

[env:adafruit_feather_esp32s3_tft]
platform = espressif32
board = adafruit_feather_esp32s3_tft
framework = arduino
board_build.partitions = partitions.csv

At the root of my project I have this partitions.csv file (a copy of the default 4MB with spiffs partition scheme from the Arduino IDE):

# Name,   Type, SubType, Offset,  Size, Flags
nvs,      data, nvs,     0x9000,  0x5000,
otadata,  data, ota,     0xe000,  0x2000,
app0,     app,  ota_0,   0x10000, 0x140000,
app1,     app,  ota_1,   0x150000,0x140000,
spiffs,   data, spiffs,  0x290000,0x160000,
coredump, data, coredump,0x3F0000,0x10000,

And my text file in data/test.txt.

I can successfully build and upload my Filesystem Image using the platformio menu, then upload the firmware just fine, but calls to LittleFS.begin() (or SPIFFS.begin(), if I use that instead) always fail. Here’s what the serial monitor looks like:

---- Opened the serial port COM5 ----
An Error has occurred while mounting LittleFS
could not read file

But that won’t be used at all if you don’t reference in the platformio.ini.

https://docs.platformio.org/en/latest/platforms/espressif32.html#partition-tables

board_build.partitions = partitions.csv
1 Like

thanks! I updated my platformio.ini file (edited the post above as well), but still the same result, LittleFS.begin() returns false…

You have to reupload the filesystem after making that platformio.ini file change, because the start address of the LittleFS might have changed now. (project tasks → Upload Filesystem)

You can also say

LittleFS.begin(true)

to cause a LittleFS format if no premade filesystem could be found, just to test if it can create the filesystem in flash at all. (It won’t find the file on an empty filesystem then, of course).

Yep, I had rebuilt and re-uploaded the filesystem first.

I didn’t actually get to test the formatting because I found the issue :tada:!

I needed to add the board_build.filesystem = littlefs line in my platformio.ini file! Here’s my updated, working platformio.ini file now:

[env:adafruit_feather_esp32s3_tft]
platform = espressif32
board = adafruit_feather_esp32s3_tft
framework = arduino
board_build.filesystem = littlefs
board_build.partitions = partitions.csv
1 Like

Oh right, because SPIFFS is the default! Mentioned in

https://docs.platformio.org/en/latest/platforms/espressif32.html#uploading-files-to-file-system

Good that you found it.

1 Like