Expand description
NVS persistent storage for device configuration and crash reports.
Wraps esp-nvs behind a process-wide singleton so the panic handler can
persist a crash snapshot even though the FLASH peripheral is consumed at
init time. Every operation runs synchronously (no await inside) and is
serialized through NVS_BUSY, which lets the panic handler decide in
one load whether the flash is safe to touch right now.
Constantsยง
- KEY_CFG ๐
- NVS key for the config blob.
- KEY_
PANIC ๐ - NVS key for the persisted last-panic snapshot.
- NS_
CONFIG ๐ - NVS namespace for config storage.
- NS_DIAG ๐
- NVS namespace for diagnostics.
- NVS_
OFFSET ๐ - NVS partition offset (default for ESP32-S2).
- NVS_
SIZE ๐ - NVS partition size (default for ESP32-S2: 24 KiB).
Staticsยง
- NVS ๐
- The global handle, set once by
init. - NVS_
BUSY ๐ - Set while any NVS operation is in flight.
Functionsยง
- busy_
clear ๐ - Clear the busy flag.
- busy_
swap ๐ - Atomically set the busy flag and return its previous value.
- clear
- Clear all config data from NVS (reverts to defaults on next load).
- init
- Initialize the global NVS handle. Takes ownership of the FLASH peripheral.
- load
- Load the persisted device configuration.
- load_
panic ๐ - Load the persisted last-panic snapshot, if any.
- persist_
panic ๐ - Persist the last-panic snapshot (overwrites the previous one).
- save
- Save the device configuration to NVS (serialized via
postcard). - with_
nvs ๐ - Run
fagainst the global handle if storage is up and the flash is idle.
Type Aliasesยง
- Storage ๐
- Concrete storage type: NVS on the internal flash.