My hardware is LilyGO TTGO T-Display esp32 board. It's an ESP32-based board with 4MB of flash memory.
-
Add to platfromio.ini
board_build.filesystem = fatfs
-
Select the right partition layout option
board_build.partitions = noota_3gffat.csv
with some partition layout .csv. You may chose some predefined partition layout from ESP-IDF example. I usednoota_3gffat.csv
. -
Create a data folder and put in the files that you want to upload to the board flash memory.
-
PlatformIO -> Board Configuration -> Build Filesystem Image (see image below)
-
PlatformIO -> Board Configuration -> Upload filesystem Image (see image below)
-
Add the includes:
#include "FS.h"
#include "FFat.h"
- In setup method before using any FFat methods initialise and mount the FFat partition:
if(!FFat.begin(false)){ // Change to true if you want to format the partition on mount error
Serial.println("An Error has occurred while mounting FFat");
return;
}
- Read/Write/Append files. Open a file using the appropriate mode or combination:
// open file
File file = FFat.open("/test.json", "r");
if(!file){ // Don't forget to check if the file was opened successfully
Serial.println("Failed to open test.json file for reading");
return;
}
- File operation:
while(file.available()){
Serial.write(file.read());
}
- Don't forget to close the file:
fileTmp.close();
How to use custom partition tables on ESP32
FATFS on ESP32 - partly out of date, but the Arduino sketch will work if you need it.
Parttool allows you to read and write partitions.
With installed to the default location Espressif ESP-IDF you will find partttol at(macos):
$HOME/esp/esp-idf/components/partition_table
I set up IDF_PATH environment variable first:
export $IDF_PATH=$HOME/esp/esp-idf
then I run parttool to read the FAT partitions into the ffat.bin file:
./parttool.py --port "/dev/tty.SLAB_USBtoUART" read_partition --partition-type=data --partition-subtype=fat --output "ffat.bin"
, where /dev/tty.SLAB_USBtoUART
is the USB serial port of the board.