Feather ESP32-S3 littleFS on PlatformIO

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
Cyberfly100
 
Posts: 8
Joined: Thu Jul 27, 2023 4:51 am

Feather ESP32-S3 littleFS on PlatformIO

Post by Cyberfly100 »

Hi,

I posted here already, but got no reply. I think this sub-forum is more applicable. Maybe my old thread could be merged with this one? Meanwhile, I will duplicate the question in the hopes that someone can help me with my issue.

I was trying to use the littleFS filesystem on an Adafruit Feather ESP32-S3 (using PlatformIO). The filesystem uploads without complaints, but I cannot successfully access the files. I tried the same code (just exchanged the board in the PlatformIO ini) with the Unexpected Maker FeatherS3 board and it works like a charm.

The program I used is just a small test. There is a "test.tx" file inside a "data" folder. I am trying to read the content ("Hello") and print it to the serial port.

Test-program (main.cpp in VS Code):

Code: Select all

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

static volatile uint32_t last_print_ms{millis()};

void setup()
{
  Serial.begin(115200);

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

void loop()
{
  if (millis() - last_print_ms >= 2000)
  {
    last_print_ms = millis();
    File file = LittleFS.open("/test.txt", "r");
    if (!file)
    {
      Serial.println("Failed to open file for reading");
      return;
    }

    Serial.println("File Content:");
    while (file.available())
    {
      Serial.write(file.read());
    }
    file.close();
  }
}
Platformio.ini with both boards, so I can easily swap for testing:

Code: Select all

[env:adafruit_feather_esp32s3]
platform = espressif32
board = adafruit_feather_esp32s3
; board = um_feathers3
board_build.filesystem = littlefs
monitor_speed = 115200
framework = arduino
Output from building the file system for the Adafruit board:

Code: Select all

Processing adafruit_feather_esp32s3 (platform: espressif32; board: adafruit_feather_esp32s3; framework: arduino)
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/adafruit_feather_esp32s3.html
PLATFORM: Espressif 32 (6.1.0) > Adafruit Feather ESP32-S3 2MB PSRAM
HARDWARE: ESP32S3 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (cmsis-dap) External (cmsis-dap, esp-bridge, esp-builtin, esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES:
 - framework-arduinoespressif32 @ 3.20007.0 (2.0.7)
 - tool-esptoolpy @ 1.40500.0 (4.5.0)
 - tool-mklittlefs @ 1.203.210628 (2.3)
 - toolchain-riscv32-esp @ 8.4.0+2021r2-patch5
 - toolchain-xtensa-esp32s3 @ 8.4.0+2021r2-patch5
LDF: Library Dependency Finder -> https://BANNED/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 33 compatible libraries
Scanning dependencies...
Dependency Graph
|-- LittleFS @ 2.0.0
Building in release mode
Building FS image from 'data' directory to .pio\build\adafruit_feather_esp32s3\littlefs.bin
/test.txt
============================================================================================================== [SUCCESS] Took 1.11 seconds ==============================================================================================================
Output from uploading the file system to Adafruit board:

Code: Select all

Processing adafruit_feather_esp32s3 (platform: espressif32; board: adafruit_feather_esp32s3; framework: arduino)
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/adafruit_feather_esp32s3.html
PLATFORM: Espressif 32 (6.1.0) > Adafruit Feather ESP32-S3 2MB PSRAM
HARDWARE: ESP32S3 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (cmsis-dap) External (cmsis-dap, esp-bridge, esp-builtin, esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES:
 - framework-arduinoespressif32 @ 3.20007.0 (2.0.7)
 - tool-esptoolpy @ 1.40500.0 (4.5.0) 
 - tool-mkfatfs @ 2.0.1
 - tool-mklittlefs @ 1.203.210628 (2.3)
 - tool-mkspiffs @ 2.230.0 (2.30)
 - toolchain-riscv32-esp @ 8.4.0+2021r2-patch5
 - toolchain-xtensa-esp32s3 @ 8.4.0+2021r2-patch5
LDF: Library Dependency Finder -> https://BANNED/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 33 compatible libraries
Scanning dependencies...
Dependency Graph
|-- LittleFS @ 2.0.0
Building in release mode
Building FS image from 'data' directory to .pio\build\adafruit_feather_esp32s3\littlefs.bin
/test.txt
Looking for upload port...
Auto-detected: COM9
Forcing reset using 1200bps open/close on port COM9
Waiting for the new upload port...
Uploading .pio\build\adafruit_feather_esp32s3\littlefs.bin
esptool.py v4.5
Serial port COM9
Connecting...
Chip is ESP32-S3 (revision v0.1)
Features: WiFi, BLE
Crystal is 40MHz
MAC: 70:04:1d:cd:d3:74
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 460800
Changed.
Configuring flash size...
Flash will be erased from 0x00310000 to 0x003fffff...
Compressed 983040 bytes to 1221...
Writing at 0x00310000... (100 %)
Wrote 983040 bytes (1221 compressed) at 0x00310000 in 6.1 seconds (effective 1286.4 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting via RTS pin...
================================================================================================ [SUCCESS] Took 16.12 seconds ================================================================================================
I get "Failed to open file for reading" printed on the serial port.

User avatar
Cyberfly100
 
Posts: 8
Joined: Thu Jul 27, 2023 4:51 am

Re: Feather ESP32-S3 littleFS on PlatformIO

Post by Cyberfly100 »

I found that the filesystem already does not mount properly on the Adafruit Feather ESP32-S3. I did not see the serial output because the serial port was not ready, yet.

I also tested with SPIFFS and it does not mount either.

User avatar
Cyberfly100
 
Posts: 8
Joined: Thu Jul 27, 2023 4:51 am

Re: Feather ESP32-S3 littleFS on PlatformIO

Post by Cyberfly100 »

Fatfs seems to work though.

I slighly modified the code:

Code: Select all

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

static volatile uint32_t last_print_ms{millis()};

void setup()
{
  Serial.begin(115200);
  delay(1000);

  if (!FFat.begin())
  {
    Serial.println("An Error has occurred while mounting FFat");
    return;
  }
  else
  {
    Serial.println("File system mounted successfully.");
  }
}

void loop()
{
  if (millis() - last_print_ms >= 2000)
  {
    last_print_ms = millis();
    File file = FFat.open("/test.txt");
    if (!file)
    {
      Serial.println("Failed to open file for reading");
    }
    else
    {
      Serial.println("File Content:");
      while (file.available())
      {
        Serial.write(file.read());
      }
    }
    file.close();
  }
}
And the platformio.ini file:

Code: Select all

[env:adafruit_feather_esp32s3]
platform = espressif32
board = adafruit_feather_esp32s3
board_build.filesystem = fatfs
monitor_speed = 115200
framework = arduino
I am leaving this here in case someone else needs a file system to work on the Adafruit Feather ESP32-S3. I would still be interested to know why LittleFS is not working.

User avatar
rctoledano
 
Posts: 1
Joined: Tue Aug 01, 2023 1:12 am

Re: Feather ESP32-S3 littleFS on PlatformIO

Post by rctoledano »

Hi I have discovered that if you put this
if (!LittleFS.begin(true, "/littlefs", 10, "ffat"))
all works.

It seems like ESP32 S3 for example come with an FFat partition. When the littlefs.bin is uploaded all is good except the label of the partition that is not replaced. So if you put the rigth label partition all going well.

I hope that this help somebody.
Attachments
partition table of an ESP32 S3 board
partition table of an ESP32 S3 board
Screenshot from 2023-09-15 15-03-51.png (19.33 KiB) Viewed 2280 times

User avatar
pagemt
 
Posts: 5
Joined: Sat Jun 17, 2023 10:13 pm

Re: Feather ESP32-S3 littleFS on PlatformIO

Post by pagemt »

Thank you very much for this data, it worked!! I used Partition Scheme "Default 4M with ffat". That allow my program to read the JSON file I had copy to it with LittleFS format. The earlier worked on a ESP32 V2 feather. Where did you find this? I want to understand the different parameters.
Thanks again!

User avatar
Cyberfly100
 
Posts: 8
Joined: Thu Jul 27, 2023 4:51 am

Re: Feather ESP32-S3 littleFS on PlatformIO

Post by Cyberfly100 »

Thank you @rctoledano.
For completeness, I had a look at the source inside the arduino-esp32 core and the default arguments for LittleFS.begin() are as follows:

Code: Select all

bool begin(bool formatOnFail=false, const char * basePath="/littlefs", uint8_t maxOpenFiles=10, const char * partitionLabel="spiffs");
You can choose the first three parameters as you whish. It should work as long as the last one (partitionLabel) is "ffat". Which is probably what @rctoledano meant, just a little clearer.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”