VSCode ESP-IDF framework esp32 SPIFFS error

He estado intentando durante días y días hacer que SPIFFS funcione en mi placa esp32 usando PlatformIO en VSCode siguiendo el siguiente ejemplo: https://github.com/espressif/esp-idf/tree/master/examples/storage/spiffs pero no puedo hacer que funcione. Si uso el marco Arduino, montará la partición sin ningún problema, pero cuando intento hacerlo con el marco ESP-IDF, simplemente no crea la partición ni formatea la memoria flash si no encuentra la partición que estoy buscando.

los registros son los siguientes:

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

y mi codigo es el siguiente:

//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;
}

El siguiente es mi archivo platformio.ini:

;PlatformIO Project Configuration File
;
;   Build options: build flags, source filter
;   Upload options: custom upload port, speed and extra flags
;   Library options: dependencies, extra library storages
;   Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[env:esp32dev]
platform = espressif32
board = esp32dev
framework = espidf
monitor_speed = 115200
Para usar SPIFFS, debe particionar la memoria flash de modo que se asigne espacio para SPIFFS. ¿Qué partición estás usando? Por favor, muestre el platformio.iniarchivo. Ver también: docs.platformio.org/en/latest/platforms/…
@Codo Creo que tienes toda la razón, ese era mi principal sospechoso. Mi pregunta ahora sería, en VSCode, ¿en qué parte de mi proyecto tendría que colocar mi tabla de particiones?
Supongo que ya tienes tu respuesta: community.platformio.org/t/…

Respuestas (2)

Encontré una respuesta para este problema como se indica en el siguiente hilo: https://community.platformio.org/t/vscode-esp-idf-framework-esp32-spiffs-error/10817 .

Básicamente, el problema era que estaba tratando de acceder a una partición que nunca existió en mi tabla de particiones. Descargué el archivo csv del ejemplo y lo coloqué en el directorio raíz (donde se encuentra platformio.ini), luego pude acceder a la partición "spiffs" para almacenar datos

Defina la tabla de particiones en platform.ini así:

board_build.partitions = custom_16MB.csv

El archivo interno es algo así como:

Name, Type, SubType, Offset, Size, Flags

nvs, data, nvs, 0x9000, 0x5000,

otadata, data, ota, 0xe000, 0x2000,

app0, app, ota_0, , 0x640000,

app1, app, ota_1, , 0x640000,

spiffs, data, spiffs, , 0x370000,

Esta es mi tabla de particiones para 16Mb ESP32.

Cómo definir tablas de partición personalizadas:

https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/partition-tables.html