Omar Chebib bd96484f7b host tests: add missing header files for compiling host tests 4 лет назад
..
doc f05f3fbde8 Added test for version update from V1 to V2. Problems for tests on host are fixed. Random function changed to esp_random() 7 лет назад
include a67d5d89e0 Replace all DOS line endings with Unix 7 лет назад
private_include 66fb5a29bb Whitespace: Automated whitespace fixes (large commit) 5 лет назад
test 570ef56d86 wear_levelling: Re-enable for ESP32-C3 5 лет назад
test_wl_host bd96484f7b host tests: add missing header files for compiling host tests 4 лет назад
.gitignore 57e380fa99 nvs_flash, wear_levelling: ignore host test files 9 лет назад
CMakeLists.txt 570ef56d86 wear_levelling: Re-enable for ESP32-C3 5 лет назад
Kconfig 37126d3451 Correct Kconfigs according to the coding style 7 лет назад
Partition.cpp a67d5d89e0 Replace all DOS line endings with Unix 7 лет назад
README.rst 6334b5e56f docs: update api-reference chapters for C3 5 лет назад
README_CN.rst bea507378e Add Chinese translation for README files in components and tools folders, including: 6 лет назад
SPI_Flash.cpp a67d5d89e0 Replace all DOS line endings with Unix 7 лет назад
WL_Ext_Perf.cpp a67d5d89e0 Replace all DOS line endings with Unix 7 лет назад
WL_Ext_Safe.cpp a67d5d89e0 Replace all DOS line endings with Unix 7 лет назад
WL_Flash.cpp 66fb5a29bb Whitespace: Automated whitespace fixes (large commit) 5 лет назад
component.mk 52b51df859 add wear_levelling component and example 9 лет назад
crc32.cpp c159984264 separate rom from esp32 component to esp_rom 7 лет назад
crc32.h 66fb5a29bb Whitespace: Automated whitespace fixes (large commit) 5 лет назад
wear_levelling.cpp f05f3fbde8 Added test for version update from V1 to V2. Problems for tests on host are fixed. Random function changed to esp_random() 7 лет назад

README.rst

Wear Levelling API
==================

:link_to_translation:`zh_CN:[中文]`

Overview
--------
Most of flash memory and especially SPI flash that is used in {IDF_TARGET_NAME} has a sector-based organization and also has a limited number of erase/modification cycles per memory sector. The wear levelling component helps to distribute wear and tear among sectors more evenly without requiring any attention from the user.

The wear levelling component provides API functions related to reading, writing, erasing, and memory mapping of data in external SPI flash through the partition component. The component also has higher-level API functions which work with the FAT filesystem defined in :doc:`FAT filesystem `.

The wear levelling component, together with the FAT FS component, uses FAT FS sectors of 4096 bytes, which is a standard size for flash memory. With this size, the component shows the best performance but needs additional memory in RAM.

To save internal memory, the component has two additional modes which both use sectors of 512 bytes:

- **Performance mode.** Erase sector operation data is stored in RAM, the sector is erased, and then data is copied back to flash memory. However, if a device is powered off for any reason, all 4096 bytes of data is lost.
- **Safety mode.** The data is first saved to flash memory, and after the sector is erased, the data is saved back. If a device is powered off, the data can be recovered as soon as the device boots up.

The default settings are as follows:
- Sector size is 512 bytes
- Performance mode

You can change the settings through the configuration menu.


The wear levelling component does not cache data in RAM. The write and erase functions modify flash directly, and flash contents are consistent when the function returns.


Wear Levelling access API functions
-----------------------------------

This is the set of API functions for working with data in flash:

- ``wl_mount`` - initializes the wear levelling module and mounts the specified partition
- ``wl_unmount`` - unmounts the partition and deinitializes the wear levelling module
- ``wl_erase_range`` - erases a range of addresses in flash
- ``wl_write`` - writes data to a partition
- ``wl_read`` - reads data from a partition
- ``wl_size`` - returns the size of available memory in bytes
- ``wl_sector_size`` - returns the size of one sector

As a rule, try to avoid using raw wear levelling functions and use filesystem-specific functions instead.


Memory Size
-----------

The memory size is calculated in the wear levelling module based on partition parameters. The module uses some sectors of flash for internal data.