[已解决] 求助,spiffs初始化失败,报错ESP_ERR_INVALID_ARG

wenbozzz
Posts: 5
Joined: Tue Jun 15, 2021 9:53 am

[已解决] 求助,spiffs初始化失败,报错ESP_ERR_INVALID_ARG

Postby wenbozzz » Wed Jun 23, 2021 10:37 am

芯片:ESP32-WROVER-B
IDF版本:release/v4.3
开发环境:Windows10


各位好,我遇到spiffs初始化失败的问题,但我感觉我给的config应该没啥问题?
esp_vfs_spiffs_conf_t conf = {
.base_path = "/abcdefghi_files", .partition_label = NULL, .max_files = 4, .format_if_mount_failed = false};
整段代码如下:

Code: Select all

void storageInit() {
    static const char* tag = "storageInit";
    ESP_LOGD(tag, "storageInit() called");
    esp_vfs_spiffs_conf_t conf = {
        .base_path = "/abcdefghi_files", .partition_label = NULL, .max_files = 4, .format_if_mount_failed = false};

    // 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");
            throw std::runtime_error("fail to mount");
        } else if (ret == ESP_ERR_NOT_FOUND) {
            ESP_LOGE(tag, "Failed to find SPIFFS partition");
            throw std::runtime_error("no partition");
        } else {
            ESP_LOGE(tag, "Failed to initialize SPIFFS (%s)", esp_err_to_name(ret));
            throw std::runtime_error("fail to init");
        }
        return;
    }

    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_LOGD(tag, "Partition size: total: %d, used: %d", total, used);
    }
}
然后串口打印如下
D (1823) storageInit: storageInit() called
D (1833) partition: Loading the partition table
D (1843) SPIFFS: SPIFFS_mount sz:0 logpgsz:0 logblksz:0 perasz:0 addr:00000000 fdsz:192 cachesz:1124

D (1923) SPIFFS: page index byte len: 256

D (1923) SPIFFS: object lookup pages: 1

D (1923) SPIFFS: page pages per block: 16

D (1923) SPIFFS: page header length: 5

D (1933) SPIFFS: object header index entries: 87

D (1933) SPIFFS: object index entries: 124

D (1943) SPIFFS: available file descriptors: 4

D (1943) SPIFFS: free blocks: 255

D (1953) SPIFFS: SPIFFS_unmount

E (1953) storageInit: Failed to initialize SPIFFS (ESP_ERR_INVALID_ARG)
请问这个ESP_ERR_INVALID_ARG是怎么导致的?

我的sdkconfig里spiffs相关的内容如下
#
# SPIFFS Configuration
#
CONFIG_SPIFFS_MAX_PARTITIONS=3

#
# SPIFFS Cache Configuration
#
CONFIG_SPIFFS_CACHE=y
CONFIG_SPIFFS_CACHE_WR=y
# CONFIG_SPIFFS_CACHE_STATS is not set
# end of SPIFFS Cache Configuration

CONFIG_SPIFFS_PAGE_CHECK=y
CONFIG_SPIFFS_GC_MAX_RUNS=10
# CONFIG_SPIFFS_GC_STATS is not set
CONFIG_SPIFFS_PAGE_SIZE=256
CONFIG_SPIFFS_OBJ_NAME_LEN=128
# CONFIG_SPIFFS_FOLLOW_SYMLINKS is not set
CONFIG_SPIFFS_USE_MAGIC=y
CONFIG_SPIFFS_USE_MAGIC_LENGTH=y
CONFIG_SPIFFS_META_LENGTH=4
CONFIG_SPIFFS_USE_MTIME=y

#
# Debug Configuration
#
CONFIG_SPIFFS_DBG=y
CONFIG_SPIFFS_API_DBG=y
CONFIG_SPIFFS_GC_DBG=y
# CONFIG_SPIFFS_CACHE_DBG is not set
CONFIG_SPIFFS_CHECK_DBG=y
CONFIG_SPIFFS_TEST_VISUALISATION=y
# end of Debug Configuration
# end of SPIFFS Configuration
partition如下:
# Name, Type, SubType, Offset, Size, Flags
# Note: if you have increased the bootloader size, make sure to update the offsets to avoid overlap
nvs, data, nvs, 0x9000, 0x6000,
phy_init, data, phy, 0xf000, 0x1000,
factory, app, factory, 0x10000, 1M,
storage, data, spiffs, , 1M,
storage里面只有一个文件,文件名长度24字节,文件大小46字节
Last edited by wenbozzz on Thu Jun 24, 2021 2:22 am, edited 1 time in total.

wenbozzz
Posts: 5
Joined: Tue Jun 15, 2021 9:53 am

Re: 求助,spiffs初始化失败,报错ESP_ERR_INVALID_ARG

Postby wenbozzz » Thu Jun 24, 2021 1:14 am

把base path缩短成 abc 就能初始化成功
esp_vfs_spiffs_conf_t conf = {
.base_path = "/abc", .partition_label = NULL, .max_files = 4, .format_if_mount_failed = false};
请问是有什么config设置需要改的吗? CONFIG_SPIFFS_OBJ_NAME_LEN=128 感觉已经够大了?

ESP_Gargamel
Posts: 786
Joined: Wed Nov 14, 2018 8:45 am

Re: 求助,spiffs初始化失败,报错ESP_ERR_INVALID_ARG

Postby ESP_Gargamel » Thu Jun 24, 2021 1:40 am

vfs 的 base_path 最长当前定义为 15,这个是 vfs 这层限制的长度。对应代码为:https://github.com/espressif/esp-idf/bl ... _vfs.h#L52

SPIFFS_OBJ_NAME_LEN 是 spiffs 限制的文件名的长度。

wenbozzz
Posts: 5
Joined: Tue Jun 15, 2021 9:53 am

Re: 求助,spiffs初始化失败,报错ESP_ERR_INVALID_ARG

Postby wenbozzz » Thu Jun 24, 2021 2:14 am

看到了, 感谢!
还想再请教下,
假如这个ESP_VFS_PATH_MAX我改大了(例如改成31),会导致什么其他的问题吗? 还是说仅仅内存开销大了而已?

ESP_Gargamel
Posts: 786
Joined: Wed Nov 14, 2018 8:45 am

Re: 求助,spiffs初始化失败,报错ESP_ERR_INVALID_ARG

Postby ESP_Gargamel » Thu Jun 24, 2021 2:19 am

应该问题不大,只要全局都正常用了这个宏。但该改动我们未做过测试,需要你试一下。

wenbozzz
Posts: 5
Joined: Tue Jun 15, 2021 9:53 am

Re: 求助,spiffs初始化失败,报错ESP_ERR_INVALID_ARG

Postby wenbozzz » Thu Jun 24, 2021 2:21 am

好的,谢谢!

Who is online

Users browsing this forum: No registered users and 87 guests