esp-idf/examples/storage/wear_levelling
Marek Fiala ff18a96f7d tools: replace _ with - in idf.py
Closes https://github.com/espressif/esp-idf/issues/5126
2021-10-13 17:30:38 +08:00
..
main Whitespace: Automated whitespace fixes (large commit) 2020-11-11 07:36:35 +00:00
CMakeLists.txt cmake: make main a component again 2018-09-11 09:44:12 +08:00
Makefile Whitespace: Automated whitespace fixes (large commit) 2020-11-11 07:36:35 +00:00
README.md tools: replace _ with - in idf.py 2021-10-13 17:30:38 +08:00
partitions_example.csv Whitespace: Automated whitespace fixes (large commit) 2020-11-11 07:36:35 +00: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
wear_levelling_example_test.py ci: run Example_GENERIC for C3 2021-03-15 10:27:07 +08:00

README.md

Wear levelling example

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

This example demonstrates how to use wear levelling library and FATFS library to store files in a partition inside SPI flash. Example does the following steps:

  1. Use an "all-in-one" esp_vfs_fat_spiflash_mount function to:
    • find a partition in SPI flash,
    • initialize wear levelling library using this partition
    • mount FAT filesystem using FATFS library (and format the filesystem, if the filesystem can not be mounted),
    • register FAT filesystem in VFS, enabling C standard library and POSIX functions to be used.
  2. Create a file using fopen and write to it using fprintf.
  3. Open file for reading, read back the line, and print it to the terminal.

Wear levelling partition size is set in partitions_example.csv file. See Partition Tables documentation for more information.

How to use example

Hardware required

This example does not require any special hardware, and can be run on any common development board.

Build and flash

Build the project and flash it to the board, then run monitor tool to view serial output:

idf.py -p PORT flash monitor

(Replace PORT with serial port name.)

(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 a typical example console output.

I (280) example: Mounting FAT filesystem
W (440) vfs_fat_spiflash: f_mount failed (13)
I (440) vfs_fat_spiflash: Formatting FATFS partition, allocation unit size=4096
I (660) vfs_fat_spiflash: Mounting again
I (660) example: Opening file
I (910) example: File written
I (910) example: Reading file
I (920) example: Read from file: 'written using ESP-IDF v3.1-dev-171-gf9ad17eee-dirty'
I (920) example: Unmounting FAT filesystem
I (1000) example: Done

To erase the contents of wear levelling partition, run idf.py erase-flash command. Then upload the example again as described above.