platform-espressif32
platform-espressif32 copied to clipboard
How to use LittleFS with ESP-IDF?
The LittleFS library seams not to be compiled in when using platform=arduino,espidf.
This result in link error.
d:/.../packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: .pio/build/esp32/src/main.o:(.literal._Z5setupv+0x14): undefined reference to `LittleFS'
d:/.../packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: .pio/build/esp32/src/main.o:(.literal._Z5setupv+0xa0): undefined reference to `fs::LittleFSFS::begin(bool, char const*, unsigned char, char const*)'
d:/.../packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: .pio/build/esp32/src/main.o: in function `setup()':
D:\.../src/main.cpp:39: undefined reference to `fs::LittleFSFS::begin(bool, char const*, unsigned char, char const*)'
#include "LittleFS.h"
void setup() {
LittleFS.begin();
}
void loop(){
}
I have started the project from the espidf-arduino-blink example.
regards,
You have to add as component, it is not included in IDF. This one is used https://github.com/joltwallet/esp_littlefs.git
How to add it with platformio ?
Git clone in components folder. I have done this way https://github.com/tasmota/esp-idf/tree/Tasmota/v4.4
I try to find a solution to do it with platformio and not forking the ESPIDF and make modification. For now, we will using the SPIFFS since we don't need to write the FS often (once in the life of the product).
Thanx @Jason2866 for your input !
I have this problem too. My way of reproducing this problem:
- Start with: https://github.com/espressif/arduino-esp32/tree/master/libraries/LittleFS/examples/LITTLEFS_PlatformIO
- This project will build OK
- Change platformio.ini file line
framework = arduino
toframework = arduino, espidf
- Fix some minor problem with this platform (
CONFIG_FREERTOS_HZ 1000
) - Now build the project and the error
undefined reference to `LittleFS'
will appear, amongst similar messages.
The littlefs component needs to be added as component in the Platformio setup. Component LittleFS is not included in IDF!
Thank you Jason. I'm not sure how to this though. LittleFS may not be included in IDF, but it is included in Arduino framework, which confuses me.
Yes, but when you compile Arduino as component in IDF no precompiled lib from Arduino is used (where the LittleFS part is included). This is the reason why doing this compile variant. The support of LittleFS in Arduino is there because it is added as component in IDF in the Arduino Lib Builder. Seen here https://github.com/espressif/esp32-arduino-lib-builder/blob/master/tools/update-components.sh where all extra IDF components are added which are later in Arduino
Just to be practical: what should one do to use LittleFS in an arduino, espidf
project in PlatformIO?
Make components
folder in root of your project and place LittleFS there.
In the LittleFS folder, edit CMakeLists.txt to be included in the project.
Will do an example setup (the next days) and will provide a link too.
HI, I think this is the new feature that is supported. check here https://docs.platformio.org/en/latest/frameworks/espidf.html#esp-idf-components
@dumarjo not new ;-)
Again starting with: https://github.com/espressif/arduino-esp32/tree/master/libraries/LittleFS/examples/LITTLEFS_PlatformIO
Change platformio.ini file line framework = arduino
to framework = arduino, espidf
Now add components/littlefs folder and add source files from https://github.com/littlefs-project/littlefs
Add CMakeList.txt file to this folder, with following content:
idf_component_register(SRCS "lfs.c" "lfs.h" "lfs_util.c" "lfs_util.h")
The CMakeList.txt in the root of the project:
cmake_minimum_required(VERSION 3.16.0)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
list(APPEND EXTRA_COMPONENT_DIRS littlefs)
project(LITTLEFS_PlatformIO)
The result:
Executing task: C:\Users\wijns\.platformio\penv\Scripts\platformio.exe run
Processing esp32 (platform: espressif32; board: esp32dev; framework: arduino, espidf)
----------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/esp32dev.html
PLATFORM: Espressif 32 (6.0.1) > Espressif ESP32 Dev Module
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (cmsis-dap) External (cmsis-dap, esp-bridge, 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.20006.221224 (2.0.6)
- framework-espidf @ 3.40403.0 (4.4.3)
- tool-cmake @ 3.16.4
- tool-esptoolpy @ 1.40400.0 (4.4.0)
- tool-idf @ 1.0.1
- tool-mconf @ 1.4060000.20190628 (406.0.0)
- tool-ninja @ 1.9.0
- toolchain-esp32ulp @ 1.23500.220830 (2.35.0)
- toolchain-xtensa-esp32 @ 8.4.0+2021r2-patch5
Warning! Arduino framework as an ESP-IDF component doesn't handle the `variant` field! The default `esp32` variant will be used.
Reading CMake configuration...
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 0 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
Compiling .pio\build\esp32\components\littlefs\lfs.o
Compiling .pio\build\esp32\components\littlefs\lfs_util.o
Archiving .pio\build\esp32\esp-idf\littlefs\liblittlefs.a
Generating project linker script .pio\build\esp32\sections.ld
Linking .pio\build\esp32\firmware.elf
c:/users/wijns/.platformio/packages/[email protected]+2021r2-patch5/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: .pio\build\esp32\src\main.o:(.literal._Z5setupv+0x14): undefined reference to `LittleFS'
c:/users/wijns/.platformio/packages/[email protected]+2021r2-patch5/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: .pio\build\esp32\src\main.o:(.literal._Z5setupv+0x4c): undefined reference to `fs::LittleFSFS::begin(bool, char const*, unsigned char, char const*)'
c:/users/wijns/.platformio/packages/[email protected]+2021r2-patch5/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: .pio\build\esp32\src\main.o: in function `setup()':
c:\users\wijns\.platformio\packages\[email protected]+2021r2-patch5\xtensa-esp32-elf\include\c++\8.4.0\ext/atomicity.h:49: undefined reference to `fs::LittleFSFS::begin(bool, char const*, unsigned char, char const*)'
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\esp32\firmware.elf] Error 1
=============================================== [FAILED] Took 23.85 seconds ===============================================
I have to admin that I have no idea what I'm doing since I know little about CMake.
What am I doing wrong here?
@wijnsema Working dummy LittleFS IDF/Arduion example https://github.com/Jason2866/Arduino_IDF_LittleFS
Thanks @Jason2866
This project is indeed working properly.
A couple of things to note when integrating this into your running project:
-
I had to 'upgrade' to the development version of the PlatformIO Espressif platform in my current project. So you need
platform = https://github.com/platformio/platform-espressif32.git
instead ofplatform = espressif32
-
If you just drop in the components/esp_littlefs folder you might need to force a recompile by deleting the build folder first
There are no changes needed. The platformio.ini from my example project just looks like this

Sure Jason, your project runs fine. It's just a reminder that people with existing projects that want to use LittleFS should realize that the development branch of 'platform' espressif32 is needed.
No, it does work fine with standard release. There is no issue.
Hi @Jason2866, I am trying to build your latest code and I keep on getting the following error:
Linking .pio\build\esp32dev\firmware.elf c:/users/nef/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: .pio\build\esp32dev\src\main.o:(.literal._Z5setupv+0x14): undefined reference to
LittleFS'
c:/users/nef/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: .pio\build\esp32dev\src\main.o:(.literal._Z5setupv+0x4c): undefined reference to fs::LittleFSFS::begin(bool, char const*, unsigned char, char const*)' c:/users/nef/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: .pio\build\esp32dev\src\main.o: in function
setup()':
c:\users\nef.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0\ext/atomicity.h:49: undefined reference to fs::LittleFSFS::begin(bool, char const*, unsigned char, char const*)' collect2.exe: error: ld returned 1 exit status *** [.pio\build\esp32dev\firmware.elf] Error 1
I can't seem to figure it out. Can you please take a look and let me know? I would like to have LittleFS working with: framework = arduino, espidf
Thanks.
@nelfata Here is an working example setup
Thanks for the prompt reply. I did try to clone your latest repository and built it as it is (pro run), but I mentioned that error I am having in my previous post. Am I missing something?
@nelfata For some strange reasons the idf component manager does not work with official platform-espressif32
It does work well with my fork?! Anyways this branch does work
OK great, that worked. Thanks again.
@nelfata Found the reason for not working components manager :-) Branch main is working now too
Yes that worked too, thanks for the follow up. I did run the tests that your provided on ESP32-S3 and here is the output (just FYI): ` Listing directory: / Creating Dir: /mydir Dir created Writing file: /mydir/hello2.txt
- file written [ 454][E][vfs_api.cpp:105] open(): /littlefs/mydir/newdir2/newdir3/hello3.txt does not exist, no permits for creation Create missing folders of: /mydir/newdir2/newdir3/hello3.txt Writing file to: /mydir/newdir2/newdir3/hello3.txt
- file written Listing directory: / DIR : mydir LAST WRITE: 1969-12-31 23:59:59 Listing directory: mydir [ 655][E][vfs_api.cpp:29] open(): mydir does not start with /
- failed to open directory Deleting file: /mydir/hello2.txt
- file deleted Deleting file and empty folders on path: /mydir/newdir2/newdir3/hello3.txt
- file deleted Removing all empty folders on path: /mydir/newdir2/newdir3/hello3.txt Removing Dir: /mydir [ 799][E][vfs_api.cpp:250] rmdir(): /mydir does not exists or is a file rmdir failed Listing directory: / Writing file: /hello.txt
- file written Appending to file: /hello.txt
- message appended Reading file: /hello.txt
- read from file: Hello World! Renaming file /hello.txt to /foo.txt
- file renamed Reading file: /foo.txt
- read from file: Hello World! Deleting file: /foo.txt
- file deleted Testing file I/O with /test.txt
- writing................................................................
- 1048576 bytes written in 14534 ms
- reading................................................................
- 1048576 bytes read in 515 ms Deleting file: /test.txt
- file deleted Test complete `
Just FYI. You may want to mention that in order to upload the files in the data directory it is required to add to platformio.ini the following: board_build.filesystem = littlefs And to perform the upload: pin -t uploadfs Otherwise the upload defaults to SPIFSS and no files will show up even though the upload was successful.
Hi @Jason2866 I am using ESP Mail Client (mobizt/ESP Mail Client@^3.4.14) and getting the same LittleFS linker error:
.pio\build\esp32dev\libf72\libESP Mail Client.a(ESP_Mail_Client.cpp.o):(.literal._ZN5MB_FS10createDirsE9MB_String22mb_fs_mem_storage_type[_ZN5MB_FS10createDirsE9MB_String22mb_fs_mem_storage_type]+0x8): undefined reference to LittleFS' .pio\build\esp32dev\libf72\libESP Mail Client.a(ESP_Mail_Client.cpp.o):(.literal._ZN5MB_FS13openFlashFileERK9MB_String15mb_fs_open_mode[_ZN5MB_FS13openFlashFileERK9MB_String15mb_fs_open_mode]+0x14): undefined reference to
fs::LittleFSFS::begin(bool, char const*, unsigned char, char const*)'
.pio\build\esp32dev\libf72\libESP Mail Client.a(ESP_Mail_Client.cpp.o): in function MB_FS::flashReady()': /.pio/libdeps/esp32dev/ESP Mail Client/src/./extras/MB_FS.h:331: undefined reference to
fs::LittleFSFS::begin(bool, char const*, unsigned char, char const*)'
.pio/libdeps/esp32dev/ESP Mail Client/src/./extras/MB_FS.h:331: undefined reference to fs::LittleFSFS::begin(bool, char const*, unsigned char, char const*)' .pio/libdeps/esp32dev/ESP Mail Client/src/./extras/MB_FS.h:331: undefined reference to
fs::LittleFSFS::begin(bool, char const*, unsigned char, char const*)'
.pio/libdeps/esp32dev/ESP Mail Client/src/./extras/MB_FS.h:1058: undefined reference to fs::LittleFSFS::begin(bool, char const*, unsigned char, char const*)' .pio\build\esp32dev\libf72\libESP Mail Client.a(ESP_Mail_Client.cpp.o):C:\Working\mcu\IrrigationController/.pio/libdeps/esp32dev/ESP Mail Client/src/./extras/MB_FS.h:331: more undefined references to
fs::LittleFSFS::begin(bool, char const*, unsigned char, char const*)' follow
I have followed suggestions from this posts but so far no luck. My platform.ini is like this:
[env] platform = https://github.com/tasmota/platform-espressif32/releases/download/2023.10.02/platform-espressif32.zip framework = arduino, espidf monitor_speed = 115200
[env:esp32dev] board = esp32dev extra_scripts = ./littlefsbuilder.py board_build.partitions = partitions_custom.csv debug_tool = esp-prog debug_init_break = tbreak setup upload_protocol = esp-prog lib_deps = psychogenic/Chronos@^1.2.0 mobizt/ESP Mail Client@^3.4.14 jchristensen/Timezone@^1.2.4 paulstoffregen/Time@^1.6.1
Any ideas?
Link to repo with the project?
https://github.com/borisqbf/mcu/tree/master/IrrigationController
managed_components folder (not under source control) includes keep.me file and littlefs folder, which is a clone of main branch of https://github.com/littlefs-project/littlefs