• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..--

main/11-Mar-2024-14689

spiffs_image/11-Mar-2024-3,7392,792

CMakeLists.txtD11-Mar-2024233 75

MakefileD11-Mar-2024543 174

README.mdD11-Mar-20242.5 KiB6043

example_test.pyD11-Mar-2024940 2916

partitions_example.csvD11-Mar-2024311 76

sdkconfig.ciD11-Mar-2024153 43

sdkconfig.defaultsD11-Mar-2024153 43

README.md

1# SPIFFS Image Generation on Build Example
2
3(See the README.md file in the upper level 'examples' directory for more information about examples.)
4
5This example demonstrates how to use the SPIFFS image generation tool [spiffsgen.py](../../../components/spiffs/spiffsgen.py) to automatically create a SPIFFS
6filesystem image from the contents of a host folder during build, with an option of
7automatically flashing the created image on invocation of `idf.py -p PORT flash`.
8For more information, see description of `spiffsgen.py` on the ESP-IDF Programming Guide under API Reference > Storage > SPIFFS Filesystem.
9
10The following gives an overview of the example:
11
121. There is a directory `spiffs_image` from which the SPIFFS filesystem image will be created.
13
142. The function `spiffs_create_partition_image` is used to specify that a SPIFFS image
15should be created during build for the `storage` partition. For CMake, it is called from [the main component's CMakeLists.txt](./main/CMakeLists.txt);
16for Make, from the [project Makefile](./Makefile). `FLASH_IN_PROJECT` specifies that the created image
17should be flashed on invocation of `idf.py -p PORT flash` together with app, bootloader, partition table, etc.
18For both build systems, the image is created on the example's build directory with the output filename `storage.bin`.
19
203. Upon invocation of `idf.py -p PORT flash monitor`, application loads and
21finds there is already a valid SPIFFS filesystem in the `storage` partition with files same as those in `spiffs_image` directory. The application is then
22able to read those files.
23
24## How to use example
25
26### Build and flash
27
28To run the example, type the following command:
29
30```Makefile
31# Make
32make flash monitor
33```
34or
35```CMake
36# CMake
37idf.py -p PORT flash monitor
38```
39
40(To exit the serial monitor, type ``Ctrl-]``.)
41
42See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects.
43
44## Example output
45
46Here is the example's console output:
47
48```
49...
50I (10) example: Initializing SPIFFS
51I (110) example: Partition size: total: 896321, used: 171935
52I (110) example: Reading hello.txt
53I (110) example: Read from hello.txt: Hello World!
54I (110) example: Computing alice.txt MD5 hash
55I (330) example: Computed MD5 hash of alice.txt: deeb71f585cbb3ae5f7976d5127faf2a
56I (330) example: SPIFFS unmounted
57```
58
59The logic of the example is contained in a [single source file](./main/spiffsgen_example_main.c), and it should be relatively simple to match points in its execution with the log outputs above.
60