12.File system SPIFFS

ESP32 File System SPIFFS Configuration Guide

1. Why use a file system

On BiBoard (ESP32), in addition to the regular program area and boot area, we use the file system in the Flash partition.

The role of a file system with independent partitions is as follows:

Common file systems include Windows NTFS, exFAT, and Linux log file systems Ext and XFS. But in the embedded field, these large file systems are too large. We use the lightweight SPIFFS (SPI Flash File System), an embedded file system for SPI NOR flash devices, and support functions such as wear leveling and file system consistency checking.

Because of its light weight, the biggest feature of SPIFFS is that it does not support tree directories, that is, all files are stored in the same layer. SPIFFS provided by ESP32 has the following features:

  • Currently, SPIFFS does not support directories, it produces a flat structure. If SPIFFS is mounted under /spiffs, then creating a file with the path /spiffs/tmp/myfile.txt will create a file called /tmp/myfile.txt in SPIFFS, instead of myfile.txt in the directory /spiffs/tmp.

  • It is not a real-time stack. One write operation might take much longer than another.

  • For now, it does not detect or handle bad blocks.

2. Install the Arduino ESP32 file system uploader

You can create/save and delete files with your own Arduino code, but the operation is cumbersome. You need to put data or even binary files into Arduino Sketch and create files by running the program.

However, there is a very useful tool that can directly upload files from the computer to the file system. Although it is slightly more troublesome than the "drag-and-drop" copy of the "removable storage", whether it is MP3 audio or HTML web files, all can be easily uploaded to flash memory. Let's learn how to use this plugin.

3. Install ESP32 file upload plugin

3.1 Preparing the Environment

Please install Arduino IDE (Version: 1.8.* ) and the ESP32 support package of Arduino IDE (refer to Chapter 3.2.1 of the BiBoard Quick Start Guide.).

3.2 Download the ESP32FS plugin

Download the compressed package of the ESP32FS plug-in at:

Go to the "Arduino" directory and open the "tools" folder

C:\Users\{YourUserName}\Documents\Arduino\tools

Unzip the downloaded .zip folder to the Tools folder. You should have a similar folder structure:

C:\Users\{YourUserName}\Documents\Arduino\tools\ESP32FS\tool\esp32fs.jar

Finally, restart the Arduino IDE.

To check whether the plug-in has been successfully installed, open the Arduino IDE. Select your ESP32 development board (ESP32 Dev Module), go to "Tools", and then check if there is an "ESP32 Sketch Data Upload" option.

4. Upload files using the file system uploader

To upload files to the ESP32 file system, follow the steps below:

  • Create an Arduino project (e.g.: Test.ino) and save

  • To open the project directory, you can use the "Sketch - Show Sketch Folder" option

  • Inside this folder, create a new folder named "data"

  • In the "data" folder, you should put the file which you want to save into the SPIFFS file system. e.g., create a .txt file that contains some text named "test_example". as following:

  • Please click "Tools - ESP32 Sketch Data Upload" in the Arduino IDE

When you see the "SPIFFS Image Uploaded" prompt message, the file has been successfully uploaded to the SPIFFS partition.

5. Demo of how to use the file system

The demo of the file system SPIFFS_Test.ino(C:\Users\{YourUserName}\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.*\libraries\SPIFFS\examples\SPIFFS_Test)comes from the official ESP32 without modification. The code implements the basic operation of "addition, deletion, modification, and check", and provides an SPI flash IO test program.

If necessary, it is recommended to directly use the code of the demo to operate ESP32 SPIFFS.

Last updated

#524: Add a demo in Melody Creation

Change request updated