I've been trying to setup a SPIFFS file system on my ESP32-WROOM to serve some files for a web server. My process was to create a SPIFFS bin image on my PC, then flash it to the ESP32 and list the files but it's not working as it can't find the filesystem (SPIFFS Mount Failed). I'm using a really simple sketch just to make sure I can list the files that I'm flashing. I've set the Partition Scheme to the Default 4MB with spiffs partition.
#include "FS.h"
#include "SPIFFS.h"
void listDir(fs::FS &fs, const char * dirname, uint8_t levels){
Serial.printf("Listing directory: %s\r\n", dirname);
File root = fs.open(dirname);
if(!root){
Serial.println("- failed to open directory");
return;
}
if(!root.isDirectory()){
Serial.println(" - not a directory");
return;
}
File file = root.openNextFile();
while(file){
if(file.isDirectory()){
Serial.print(" DIR : ");
Serial.println(file.name());
if(levels){
listDir(fs, file.path(), levels -1);
}
} else {
Serial.print(" FILE: ");
Serial.print(file.name());
Serial.print("\tSIZE: ");
Serial.println(file.size());
}
file = root.openNextFile();
}
}
void setup() {
Serial.begin(115200);
if(!SPIFFS.begin(false)){
Serial.println("SPIFFS Mount Failed");
return;
}
Serial.println("SPIFFS Info:");
Serial.printf("Total Bytes: %u\n", SPIFFS.totalBytes());
Serial.printf("Used Bytes: %u\n", SPIFFS.usedBytes());
Serial.printf("Free Bytes: %u\n",SPIFFS.totalBytes() - SPIFFS.usedBytes());
listDir(SPIFFS, "/", 0);
}
loop() {
}
First I'm creating the 1MB binary image with the contents from the Data folder:
mkspiffs.exe -c .\Data -b 4096 -p 256 -s 0x100000 spiffs.bin
output:
/assets/icons-Dbz5-pCR.svg
/assets/index-CXsarTAc.js
/assets/index-mliwPROd.css
/favicon.ico
/index.html
Then I'm uploading it to the ESP32:
esptool.exe --chip esp32 --port COM10 --baud 921600 write_flash -z 0x120000 spiffs.bin
output:
esptool.py v4.7.0
Serial port COM10
Connecting.......
Chip is ESP32-D0WD-V3 (revision v3.1)
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
Crystal is 40MHz
MAC: fc:b4:67:f3:47:b8
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 921600
Changed.
Configuring flash size...
Flash will be erased from 0x00120000 to 0x0026ffff...
Compressed 1376256 bytes to 269653...
Wrote 1376256 bytes (269653 compressed) at 0x00120000 in 7.6 seconds (effective 1456.5 kbit/s)...
Hash of data verified.
Leaving...
Hard resetting via RTS pin...
That seems to run without issues. But if I reset the ESP32 (or upload my sketch in the IDE) I get an error as if it's not aware of the SPIFFS file system image I uploaded. I have "Erase all flash before sketch upload" = Disabled.
rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:1344
load:0x40078000,len:13964
load:0x40080400,len:3600
entry 0x400805f0
E (9) SPIFFS: mount failed, -10025
SPIFFS Mount Failed
I'm assuming I'm missing something, such as maybe needing to upload my sketch via the command line instead of the IDE. Is my sketch overwriting part of the file system image or the partition isn't set correctly?