esp-idf/examples/storage/spiffsgen
2021-11-11 15:32:36 +01:00
..
main Build & config: Remove leftover files from the unsupported "make" build system 2021-11-11 15:32:36 +01:00
spiffs_image Whitespace: Automated whitespace fixes (large commit) 2020-11-11 07:36:35 +00:00
CMakeLists.txt spiffs: move spiffsgen example with other storage related examples 2019-04-26 22:37:41 +08:00
example_test.py ci: run Example_GENERIC for C3 2021-03-15 10:27:07 +08:00
partitions_example.csv Whitespace: Automated whitespace fixes (large commit) 2020-11-11 07:36:35 +00:00
README.md Storage: Remove makefile reference from spiffsgen README 2021-11-11 15:32:36 +01:00
sdkconfig.ci example_tests: Deletes usage esp32c3 ECO0 in CI (by default ECO3) 2021-09-24 13:55:07 +08:00
sdkconfig.defaults examples: remove non-existent options from sdkconfig.defaults 2019-07-29 04:57:38 +02:00

SPIFFS Image Generation on Build Example

(See the README.md file in the upper level 'examples' directory for more information about examples.)

This example demonstrates how to use the SPIFFS image generation tool spiffsgen.py to automatically create a SPIFFS filesystem image from the contents of a host folder during build, with an option of automatically flashing the created image on invocation of idf.py -p PORT flash. For more information, see description of spiffsgen.py on the ESP-IDF Programming Guide under API Reference > Storage > SPIFFS Filesystem.

The following gives an overview of the example:

  1. There is a directory spiffs_image from which the SPIFFS filesystem image will be created.

  2. The function spiffs_create_partition_image is used to specify that a SPIFFS image should be created during build for the storage partition. It is called from the main component's CMakeLists.txt. FLASH_IN_PROJECT specifies that the created image should be flashed on invocation of idf.py -p PORT flash together with app, bootloader, partition table, etc. For both build systems, the image is created on the example's build directory with the output filename storage.bin.

  3. Upon invocation of idf.py -p PORT flash monitor, application loads and finds there is already a valid SPIFFS filesystem in the storage partition with files same as those in spiffs_image directory. The application is then able to read those files.

How to use example

Build and flash

To run the example, type the following command:

idf.py -p PORT flash monitor

(To exit the serial monitor, type Ctrl-].)

See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects.

Example output

Here is the example's console output:

...
I (10) example: Initializing SPIFFS
I (110) example: Partition size: total: 896321, used: 171935
I (110) example: Reading hello.txt
I (110) example: Read from hello.txt: Hello World!
I (110) example: Computing alice.txt MD5 hash
I (330) example: Computed MD5 hash of alice.txt: deeb71f585cbb3ae5f7976d5127faf2a
I (330) example: SPIFFS unmounted

The logic of the example is contained in a single source file, and it should be relatively simple to match points in its execution with the log outputs above.