Skip to main content

Module storage

Module storage 

Source
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 f against the global handle if storage is up and the flash is idle.

Type Aliasesยง

Storage ๐Ÿ”’
Concrete storage type: NVS on the internal flash.