VSCode ESP-IDF framework esp32 SPIFFS error

I’ve beet trying for days and days now to make SPIFFS work on my esp32 board using PlatformIO in VSCode following the following example: esp-idf/examples/storage/spiffs at master · espressif/esp-idf · GitHub but I can’t just make it work.
If I use the Arduino framework it will mount the partition without any problems but when I try to do it with ESP-IDF framework it just wont create the partition nor reformat flash memory if doesn’t find the partition I’m looking for.

the logs are as follows:

I (28) boot: ESP-IDF 3.30300.190916 2nd stage bootloader
I (29) boot: compile time 23:32:31
I (37) boot: Enabling RNG early entropy source…
I (37) boot: SPI Speed : 40MHz
I (38) boot: SPI Mode : DIO
I (42) boot: SPI Flash Size : 4MB
I (46) boot: Partition Table:
I (50) boot: ## Label Usage Type ST Offset Length
I (57) boot: 0 nvs WiFi data 01 02 00009000 00006000
I (64) boot: 1 phy_init RF data 01 01 0000f000 00001000
I (72) boot: 2 factory factory app 00 00 00010000 00100000
I (79) boot: End of partition table
I (83) esp_image: segment 0: paddr=0x00010020 vaddr=0x3f400020 size=0x08e64 ( 36452) map
I (105) esp_image: segment 1: paddr=0x00018e8c vaddr=0x3ffbdb60 size=0x01ec4 ( 7876) load
I (108) esp_image: segment 2: paddr=0x0001ad58 vaddr=0x40080000 size=0x00400 ( 1024) load
I (113) esp_image: segment 3: paddr=0x0001b160 vaddr=0x40080400 size=0x04eb0 ( 20144) load
I (129) esp_image: segment 4: paddr=0x00020018 vaddr=0x400d0018 size=0x19444 (103492) map
I (165) esp_image: segment 5: paddr=0x00039464 vaddr=0x400852b0 size=0x033cc ( 13260) load
I (176) boot: Loaded app from partition at offset 0x10000
I (176) boot: Disabling RNG early entropy source…
I (177) cpu_start: Pro cpu up.
I (180) cpu_start: Application information:
I (185) cpu_start: Project name: vetable
I (190) cpu_start: App version: 1.0.0
I (195) cpu_start: Compile time: Nov 28 2019 23:32:36
I (201) cpu_start: ELF file SHA256: 0000000000000000…
I (207) cpu_start: ESP-IDF: 3.30300.190916
I (213) cpu_start: Starting app cpu, entry point is 0x40081e0c
I (0) cpu_start: App cpu up.
I (223) heap_init: Initializing. RAM available for dynamic allocation:
I (230) heap_init: At 3FFAE6E0 len 0000F480 (61 KiB): DRAM
I (236) heap_init: At 3FFC0A80 len 0001F580 (125 KiB): DRAM
I (242) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (249) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (255) heap_init: At 4008867C len 00017984 (94 KiB): IRAM
I (261) cpu_start: Pro cpu start user code
I (280) cpu_start: Chip Revision: 1
W (280) cpu_start: Chip revision is higher than the one configured in menuconfig. Suggest to upgrade it.
I (283) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
I (294) SPIFFS:

Initializing SPIFFS
E (304) SPIFFS: spiffs partition could not be found
E (304) SPIFFS: Failed to find SPIFFS partition

and my code is the following:

//standar freeRTOS
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_spi_flash.h"
#include "driver/gpio.h"
#include "sdkconfig.h"
#include "freertos/queue.h"

//spiffs
#include <string.h>
#include <sys/unistd.h>
#include <sys/stat.h>
#include "esp_err.h"
#include "esp_log.h"
#include "esp_spiffs.h"
#include "spiffs_config.h"



//----------SPIFFS SETUP-----------//
void vfsSetup(){
    ESP_LOGI(TAG, "\n\nInitializing SPIFFS");
    
    esp_vfs_spiffs_conf_t conf = {
    .base_path = "/vetable",
    .partition_label = NULL,
    .max_files = 5,
    .format_if_mount_failed = true
    };
    
    // Use settings defined above to initialize and mount SPIFFS filesystem.
    // Note: esp_vfs_spiffs_register is an all-in-one convenience function.
    esp_err_t ret = esp_vfs_spiffs_register(&conf);

    if (ret != ESP_OK) {
        if (ret == ESP_FAIL) {
            ESP_LOGE(TAG, "Failed to mount or format filesystem");
        } else if (ret == ESP_ERR_NOT_FOUND) {
            ESP_LOGE(TAG, "Failed to find SPIFFS partition");
        } else {
            ESP_LOGE(TAG, "Failed to initialize SPIFFS (%s)", esp_err_to_name(ret));
        }
        return;
    }
    

    vTaskDelay(100/portTICK_PERIOD_MS);

    size_t total = 0, used = 0;
    ret = esp_spiffs_info(NULL, &total, &used);
    if (ret != ESP_OK) {
        ESP_LOGE(TAG, "Failed to get SPIFFS partition information (%s)", esp_err_to_name(ret));
    } else {
        ESP_LOGI(TAG, "Partition size: total: %d, used: %d", total, used);
    }
    
};



//----------MAIN----------//
void app_main(void){
   vfsSetup();
   return;
}

This shows that you haven’t instructed PIO to use the partition table CSV file that is present in the SPIFFS example project, otherwise there would be a storage partition of type SPIFFS here.

Without an existing partition which has some space allocated to it, it also can’t create a SPIFFS for you.

Instructions on how to include that file are in the documentation: Espressif 32 — PlatformIO latest documentation

Thank you, the partition table was my main suspect, I thought it would get generated automatically as with the Arduino framework. I guess now my question would be how to create it in VSCode and in which directory of my pio project would I have to store it?

As linked in the documentation, just download the file, put it in the root of your project (same level as your platformio.ini) as partitions_example.csv and add the line

board_build.partitions = partitions_example.csv

to the platformio.ini.

1 Like