Launch ESP32 spiffs file system in three minutes

What is spiffs file system

The spiffs file system is a file system that can be used in embedded devices.

For the details of the spiffs file system of esp32, please see the introduction of esp32 official website: espidf programming guide-spiffs

The document introduces the burning methods of a variety of file systems. This article uses spiffsgen.pyburning as an example to use the spiffs file system in the simplest and quickest way.

Create a directory for the file system

First download spiffsgen.py, click me to download , spiffsgen.pycreate a new folder in the same level directory as the root directory of spiffs, for example root, then you can put files or create new folders under root.
Such as the following directory structure:

root

gree

ac_gree_1.bin

haier

ac_haier_1.bin

spiffsgen.py

Generate binary file system

Take generating a 100k file system as an example, execute the following command line to generate spiffs.bin file, this is the spiffs file system. Its size 0x19000 is 100k.

python spiffsgen.py 0x19000 root spiffs.bin

Burn spiffs

Here I am using esp32 burning tool.

Insert picture description here
This thing should be available for download on the official website, or you can burn it with esp_tools.py according to the document. Here I burn the file to the Double click to enlarge
corresponding 0x330000 in the flash, and add the following under the partitions.csv file under the project:

# Name,   Type, SubType, Offset,  Size
storage,  data, spiffs,  0x330000, 0x19000, 

Burning is complete!

Simple use of spiffs

Reference esp-idf/examples/storage/spiffsproject

    esp_vfs_spiffs_conf_t conf = {
    
    
      .base_path = "/spiffs",	//根目录,对应root文件夹
      .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;
    }

Guess you like

Origin blog.csdn.net/weixin_44821644/article/details/109480902