This is an ESP-IDF compatible, bare metal, non-volatile storage (NVS) library.
The motivation to write this library was
- to have a backwards compatible NVS driver in case someone is upgrading existing systems from ESP-IDF.
- to take advantage of the many people working at espressif, who probably spent a minute or two when designing the underlying, flash-friendly data structure.
Therefore, the code is based on the NVS documentation from espressif and inspired by the actual C++ implementation.
Since the data structure on the flash is based on C structs, some unsafe blocks are used to transmute the read memory
to #[repr(C,packed)] structs and unions. Nevertheless, all data structures include CRC32 checksums which are checked and handled.
The use of unions requires unsafe as well.
This library is used in production, but nevertheless, there might be some kinks here and there.
esp-nvs requires an implementation of the Platform trait to provide access to the flash as well as to the CRC32 present
in the ESP32 ROM.
Example implementation of the Platform driver for an ESP32. This requires new low-level feature of the esp-storage crate:
[dependencies]
esp-storage = { version = "0.8.1", features = ["esp32c6"] }// TODO: Update the offsets according to your partition table definition.
let partition_offset = 0x390000;
let partition_size = 0x32000;
let storage = esp_storage::FlashStorage::new(peripherals.FLASH);
let nvs =
esp_nvs::Nvs::new(partition_offset, partition_size, storage).expect("failed to create nvs");