Skip to content

hal::flash

A word-addressed NOR-flash region, for the key/value store to sit on.

The kernel’s nvs module is the joint between kvstore (the format) and a SoC’s flash driver (the registers). It drives the flash through this trait so the joint’s read/write/erase logic names no chip: a SoC’s driver implements [NorFlash], and the board selects one concrete type with the build. The word-oriented API (&[u32], not &[u8]) is deliberate — the ESP32’s SPI1 controller takes word pointers and counts, and pretending otherwise at this layer only hides the alignment the caller must respect.

trait NorFlash {
fn len(&self) -> u32
fn is_empty(&self) -> bool
unsafe fn read(&self, offset: u32, out: &mut [u32]) -> Result<(), Self::Error>
unsafe fn write(&self, offset: u32, data: &[u32]) -> Result<(), Self::Error>
unsafe fn erase_all(&self) -> Result<(), Self::Error>
}

A bounded region of NOR flash, addressed in whole 32-bit words within it.

Every method is unsafe: on some SoCs (the ESP32) these run with the instruction cache off, which stops any core still fetching from flash — see the driver for the second-core contract.