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 the latest Arduino IDE and the ESP32 support package of Arduino IDE (refer to the instructions).

3.2 Download the ESP32FS plugin

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

Download ESP32 SPIFFS file system upload plug-in for Arduino IDE

Go to the Arduino IDE directory and open the "Tools" folder.

Use Arduino IDE to install ESP32 SPIFFS file system upload plug-in

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

<home_dir> / Arduino- <version> / tools / ESP32FS / tool / esp32fs.jar

Use Arduino IDE to install ESP32 SPIFFS file system upload plug-in

Finally, restart the Arduino IDE.

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

ESP32 Sketch Data Upload in Arduino IDE

4. Upload files using the file system uploader

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

  • Create an Arduino project and save

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

Arduino IDE displays Sketch folder to create data folder
  • Inside this folder, create a new folder named "data"

"data" folder in the project directory
  • In the "data" folder, you should put the file which you want to save into the ESP32 file system. For example, create a .txt file that contains some text named "test_example".

Create test sample file with Notepad
  • Please go to Tools> ESP32 Sketch Data Upload in Arduino IDE

ESP32 Sketch Data Upload in Arduino IDE

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

The SPIFFS image has been uploaded to the ESP32 board

5. Demo of how to use the file system

The demo of the file system comes from the official ESP32 without modification. The code implements the basic operation of "addition, deletion, modification, and check", and provides a SPI flash IO test program.

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