# Need some guidance on using SPIFFS

**URL:** <https://forum.arduino.cc/t/need-some-guidance-on-using-spiffs/1260101>\
**Category:** Storage\
**Created:** [May 15, 2024, 2:29am UTC](https://forum.arduino.cc/t/need-some-guidance-on-using-spiffs/1260101 "2024-05-15T02:29:11Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![replaysmike](https://avatars.discourse-cdn.com/v4/letter/r/db5fbb/32.png) [@replaysmike](https://forum.arduino.cc/u/replaysmike)\
**Post date:** [May 15, 2024, 2:29am UTC](https://forum.arduino.cc/t/need-some-guidance-on-using-spiffs/1260101/1 "2024-05-15T02:29:11Z")

</div>

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.

```arduino
#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:

```arduino
mkspiffs.exe -c .\Data -b 4096 -p 256 -s 0x100000 spiffs.bin

```

output:

```arduino
/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:

```arduino
esptool.exe --chip esp32 --port COM10 --baud 921600 write_flash -z 0x120000 spiffs.bin

```

output:

```arduino
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.

```arduino
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?

---

<div class="post-metadata">

**Author:** ![johnerrington](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/johnerrington/32/340106_2.png) [@johnerrington](https://forum.arduino.cc/u/johnerrington)\
**Post date:** [May 15, 2024, 6:08am UTC](https://forum.arduino.cc/t/need-some-guidance-on-using-spiffs/1260101/2 "2024-05-15T06:08:27Z")

</div>

Have you tried this example?

> **[ESP32 Web Server using SPIFFS (SPI Flash File System) | Random Nerd Tutorials](https://randomnerdtutorials.com/esp32-web-server-spiffs-spi-flash-file-system/)**
>
> In this In this tutorial we'll show you how to build a web server that serves HTML and CSS files stored on the ESP32 SPIFFS (SPI Flash File System).

you may need to use the earlier (1.8) IDE

---

<div class="post-metadata">

**Author:** ![replaysmike](https://avatars.discourse-cdn.com/v4/letter/r/db5fbb/32.png) [@replaysmike](https://forum.arduino.cc/u/replaysmike)\
**Post date:** [May 15, 2024, 8:30pm UTC](https://forum.arduino.cc/t/need-some-guidance-on-using-spiffs/1260101/3 "2024-05-15T20:30:51Z")

</div>

I tried a similar one which covered the command line tools, but I'm going to look over that one now and see if I can get it working. I also used the example sketch which is basically that exact code in the article. Looks like I should switch to LittleFS instead and see if I have any luck there.

---

<div class="post-metadata">

**Author:** ![ptillisch](https://avatars.discourse-cdn.com/v4/letter/p/ad7895/32.png) [@ptillisch](https://forum.arduino.cc/u/ptillisch)\
**Post date:** [May 15, 2024, 8:39pm UTC](https://forum.arduino.cc/t/need-some-guidance-on-using-spiffs/1260101/4 "2024-05-15T20:39:46Z")

</div>

> [@johnerrington](#):
>
> you may need to use the earlier (1.8) IDE

You can use Arduino IDE 2.x, the procedure is a bit different than described in the tutorial you linked, but fortunately they have also produced a tutorial for Arduino IDE 2.x (which is linked to from the instructions in the tutorial you shared):

> **[Arduino IDE 2: Install ESP32 LittleFS Uploader | Random Nerd Tutorials](https://randomnerdtutorials.com/arduino-ide-2-install-esp32-littlefs/)**
>
> Upload files to the ESP32 LittleFS Filesystem using Arduino IDE 2 or a higher version. We'll install an uploader plugin that will add a new menu to the Arduino IDE.

---

<div class="post-metadata">

**Author:** ![replaysmike](https://avatars.discourse-cdn.com/v4/letter/r/db5fbb/32.png) [@replaysmike](https://forum.arduino.cc/u/replaysmike)\
**Post date:** [May 15, 2024, 8:55pm UTC](https://forum.arduino.cc/t/need-some-guidance-on-using-spiffs/1260101/5 "2024-05-15T20:55:09Z")

</div>

I was able to get it to work using LittleFS in the 1.8.\* IDE using the plugin described at [https://randomnerdtutorials.com/esp32-littlefs-arduino-ide/](https://randomnerdtutorials.com/esp32-littlefs-arduino-ide/)

I'm going to try the one you just recommended and hopefully get it working in the 2.3.\* IDE. Not sure why the command line tools weren't working, I must have had some parameter wrong.

---

<div class="post-metadata">

**Author:** ![replaysmike](https://avatars.discourse-cdn.com/v4/letter/r/db5fbb/32.png) [@replaysmike](https://forum.arduino.cc/u/replaysmike)\
**Post date:** [May 15, 2024, 9:27pm UTC](https://forum.arduino.cc/t/need-some-guidance-on-using-spiffs/1260101/6 "2024-05-15T21:27:22Z")

</div>

After a fair bit of fiddling around and thanks to the link you provided me I now have it working in Arduino IDE 2.3.\*.

I placed all my files in the `data\` folder of my sketch, then CTRL-SHIFT-P to open the plugin tool (since 2.3.\* doesn't add plugins to the UI) and executed `Upload LittleFS to Pico/ESP32...`.

I can't upload the data files in the IDE unfortunately, as esptool is being passed a board/chip identifier `esp32da` that esptool doesn't understand. Fortunately however it does output the command line that it runs, and I was able to override the chip setting to `esp32` instead of `esp32da`.

Executed by the IDE:

```arduino
C:\Users\mikeb\AppData\Local\Arduino15\packages\esp32\tools\esptool_py\4.5.1/esptool.exe --chip esp32da --port COM10 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 80m --flash_size detect 2686976 C:\Users\mikeb\AppData\Local\Temp\tmp-15912-DR3empe702jP-.littlefs.bin

```

modified the `--chip` parameter as follows:

```arduino
C:\Users\mikeb\AppData\Local\Arduino15\packages\esp32\tools\esptool_py\4.5.1/esptool.exe --chip esp32 --port COM10 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 80m --flash_size detect 2686976 C:\Users\mikeb\AppData\Local\Temp\tmp-15912-DR3empe702jP-.littlefs.bin

```

and all working. Thanks for your help!

---

<div class="post-metadata">

**Author:** ![replaysmike](https://avatars.discourse-cdn.com/v4/letter/r/db5fbb/32.png) [@replaysmike](https://forum.arduino.cc/u/replaysmike)\
**Post date:** [May 15, 2024, 9:33pm UTC](https://forum.arduino.cc/t/need-some-guidance-on-using-spiffs/1260101/7 "2024-05-15T21:33:37Z")

</div>

actually can mostly scrub my previous comment. Plugin version 1.1.5 VSIX works just fine, I had downgraded to 1.1.3 when trying to debug why it didn't show up (have to use command palette to run it) and forgot to put the latest version back in place. noice!

---

<div class="post-metadata">

**Author:** ![ptillisch](https://avatars.discourse-cdn.com/v4/letter/p/ad7895/32.png) [@ptillisch](https://forum.arduino.cc/u/ptillisch)\
**Post date:** [May 15, 2024, 9:34pm UTC](https://forum.arduino.cc/t/need-some-guidance-on-using-spiffs/1260101/8 "2024-05-15T21:34:34Z")

</div>

Nice work! I was just about to reply that I thought this bug had been fixed already:

> <https://github.com/earlephilhower/arduino-littlefs-upload/pull/26>
>
> Fix #25

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [November 11, 2024, 9:35pm UTC](https://forum.arduino.cc/t/need-some-guidance-on-using-spiffs/1260101/9 "2024-11-11T21:35:14Z")

</div>

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
