DIY Projects

ESP8266. Upload the data folder (SPIFFS or LittleFS) from PlatformIO

pio platformio upload littlefs spiffs data file folder esp8266

It is necessary to install complementary tools to the Arduino IDE before you can upload SPIFFS or LittleFS files (since version 2.6.0 of the ESP8266 SDK). There is nothing like it to do with PlatformIO. PIO integrates the Upload File System Image command accessible from the sidebar. To activate LittleFS, you simply need to add the option board_build.filesystem=littlefs to the configuration file!


It is not possible to directly use an Arduino project with PlatformIO, read this tutorial which explains how to migrate a project ESP32, ESP8266 (or any other platform) developed with the Arduino IDE

Update ESP8266 SDK to v2.6.0 or higher

LittleFS is supported from version 2.6.0 of the ESP8266 SDK.

If the files to be uploaded are in SPIFFS format, you must first update the Espressif ESP8266 SDK.

Move (create) the data folder in a PIO project

The data folder which will contain all the files to be uploaded to the ESP8266 flash memory must be at the same level as the src folder.

Here is an example of a tree structure

It is also possible to manually specify the location of the folder by adding the data_dir key in the platformio.ini file

How to change the size of the filesystem (board_build.ldscript)

With the Arduino IDE, it is very easy to choose the size of the file area from the Tools -> Flash Size menu

To specify the size of the File System (FS), just add the option board_build.ldscript and specify the value in the form eagle.flash. ***. Ld

All available configurations are here.

Here is an example for a LoLin d1 mini equipped with 4MB of Flash memory of which 3MB will be allocated to the LittleFS file system.

platform = espressif8266
board = d1_mini_lite
board_build.ldscript = eagle.flash.4m3m.ld

Enable LittleFS support in the file

By default the files are uploaded in SPIFFS format. To activate LittleFS support, you will need to add the option to the configuration file

board_build.filesystem = littlefs

This gives for example for the LoLin d1 mini

platform = espressif8266
board = d1_mini_lite
board_build.filesystem = littlefs
board_build.ldscript = eagle.flash.4m3m.ld
framework = arduino
monitor_speed = 115200

You can note in passing the option monitor_speed = 115200 which allows to specify the speed of the serial monitor. Obviously, the value must correspond to the speed specified in the Serial.begin () command in the Arduino code.

Upload LittleFS (or SPIFFS) files

As with the Arduino IDE, you must manually upload the SPIFFS and LittleFS files to the memory area.

It is the same command in both cases. PIO determines the file format using the board_build.filesystem option

We upload the files from the PIO menu using the Upload File System Image option or the command

platformio run --target uploadfs

A Terminal makes it possible to monitor the smooth running of the operation. If you only have one ESP8266 board connected, PIO will automatically detect it.

You can see here that PIO generated a binary named littlefs.bin, it contains all files in the data folder.

Processing d1_mini_lite (platform: espressif8266; board: d1_mini_lite; framework: arduino)
PackageManager: Installing tool-mklittlefs @ ~1.203.0
tool-mklittlefs @ 1.203.200522 has been successfully installed!
Verbose mode can be enabled via `-v, --verbose` option
PLATFORM: Espressif 8266 2.6.2 > WeMos D1 mini Lite
HARDWARE: ESP8266 80MHz, 80KB RAM, 1MB Flash
 - framework-arduinoespressif8266 3.20704.0 (2.7.4) 
 - tool-esptool 1.413.0 (4.13) 
 - tool-esptoolpy 1.20800.0 (2.8.0) 
 - tool-mklittlefs 1.203.200522 (2.3) 
 - tool-mkspiffs 1.200.0 (2.0) 
 - toolchain-xtensa 2.40802.200502 (4.8.2)
Converting test_with_text_file.ino
LDF: Library Dependency Finder ->
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 30 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <LittleFS(esp8266)> 0.1.0
Building in release mode
Building file system image from 'data' directory to .pio/build/d1_mini_lite/littlefs.bin
skipping .DS_Store
Looking for upload port...
Auto-detected: /dev/cu.usbserial-1410
Uploading .pio/build/d1_mini_lite/littlefs.bin v2.8
Serial port /dev/cu.usbserial-1410
Chip is ESP8266EX
Features: WiFi
Crystal is 26MHz
MAC: b4:e6:2d:13:f2:c9
Uploading stub...
Running stub...
Stub running...
Configuring flash size...
Auto-detected Flash size: 4MB
Compressed 65536 bytes to 301...

Writing at 0x000eb000... (100 %)
Wrote 65536 bytes (301 compressed) at 0x000eb000 in 0.0 seconds (effective 14974.5 kbit/s)...
Hash of data verified.

Hard resetting via RTS pin...

Error, LittlesFS files are not downloaded correctly

LittleFS is supported from version 2.6.0 of the ESP8266 SDK. If PIO uploads an image named spiffs.bin instead of littlefs.bin, you need to update the ESP8266 SDK.


16/09/2020 Publication of the article

Click to rate this post!
[Total: 2 Average: 5]
Exit mobile version