0
\$\begingroup\$

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: https://github.com/espressif/esp-idf/tree/master/examples/storage/spiffs 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;
}

The following is my platformio.ini file:

;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
\$\endgroup\$
  • 1
    \$\begingroup\$ To use SPIFFS, you must partition the flash memory such that space is allocated for SPIFFS? What partitioning are you using? Please show the platformio.ini file. Also see: docs.platformio.org/en/latest/platforms/… \$\endgroup\$ – Codo Nov 29 '19 at 14:07
  • \$\begingroup\$ @Codo I believe you're completely right, that was my main suspect. My question now would be, in VSCode, where in my project would I have to put my partition table? \$\endgroup\$ – Marco Castro Nov 29 '19 at 17:38
  • 1
    \$\begingroup\$ I guess you got your answer by now: community.platformio.org/t/… \$\endgroup\$ – Codo Nov 29 '19 at 18:02
0
\$\begingroup\$

I've found an answer for this issue as stated in the following thread: https://community.platformio.org/t/vscode-esp-idf-framework-esp32-spiffs-error/10817.

The problem was basically I was trying to access a partition that never existed in my partition table. I downloaded the csv file from the example and placed it in the root directory (where platformio.ini is located) then I was able to access the "spiffs" partition to store data

| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

Define partition table in platform.ini like this:

board_build.partitions = custom_16MB.csv

Inside file is something like :

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,

This is my partition table for 16Mb ESP32.

How to define custom partition tables:

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

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.