Labels

Monday, 23 November 2026

Add a filesystem to ESP32

File Systems

On most computers a file system is a very basic requirement.  ESP32 and similar devices often utilise required information within the sketch.  So far, whilst building our ESP32 system, we have managed without a file system.  The only "file" we have required is foxy.local/webserial/index.html.  This has been stored within program memory so that a user sees a web page when connecting to ESP32.

Most requirements will be more extensive, necessitating multiple files.  If ESP32 has an integrated SD card or an attached SD peripheral, the SD card can provide a large amount of file storage.

For smaller data volumes Flash memory can be used as a file system.  As most ESP32 devices don't have integrated SD cards, flash file systems are very convenient and can provide 1MB-12MB space.

Many file system types are available.  ESP32 initially used SPIFFS which has now been replaced by LittleFS.  In contrast, for SD cards a FAT16 file system would be more appropriate so that cards to be used to transfer data with PCs etc. 

LittleFS

As usual I found that RNT provides a helpful tutorial on LittleFS, although another by SunFounder is at least as good.

The first step is to create a file system and store some files on ESP32.  To do this you should install a plugin to the Arduino IDE plugins folder.  You then put some files in a "/data" subfolder within the sketch.  There is then a secret key combination Ctrl-Shift P which brings up a command palette window, just like IDF!  You choose an "upload LittleFS" option and your files are copied copied to ESP32, initialising the filesystem first if necessary.


I know, when using IDF, Flash memory is reserved for a file system by providing a partitions.csv file.  In Arduino IDE tools menu, there are a number of pre-defined options.  A default, used for most systems is to define 4MB flash with 1.5MB available for SPIFFS/LittleFS files.  As the ESP32-N16R8 has 16MB flash, I could increase available space if appropriate.



It is very simple to use LittleFS.  the first test program which displays contents of a test file is shown .  Another example provided by RNT shows all file operations.




When a user enters a URL, ESP32AsyncWebServer routes the request to LittleFS which can respond with the contents of a web page.


FTP Server

Arduino IDE has provided a plugin utility to load files into ESP32 Flash but it isn't very convenient to use.  Typically FTP is used for file transfer and it is easy to incorporate an FTP server into our sketch.

I installed SimpleFTPserver which was written by Renzo Mischanti for ESP devices.  They provide a sample sketch to test it works.  Once the server is running it sits and waits for FTP clients to connect.

I could use the command line FTP client in Windows but it is much more sensible to install FileZilla, a well-known FTP client.  I can then drag and drop files between Windows and ESP32.

It is very straightforward to copy FTP server code into my operational sketch so that I can modify ESP32 files without changing the sketch I use or restarting.

Outro

File Systems and file transfer are very easy to use on ESP32 and my framework continues to make an ESP32-S3 behave like a real computer😀

No comments:

Post a Comment