Flash

Trait Flash 

Source
pub trait Flash {
    type Error: Debug;

    // Required methods
    fn read(&mut self, addr: u32, buf: &mut [u8]) -> Result<(), Self::Error>;
    fn write(&mut self, addr: u32, data: &mut [u8]) -> Result<(), Self::Error>;
    fn erase(&mut self, addr: u32) -> Result<(), Self::Error>;

    // Provided method
    fn erase_all(&mut self, count: usize) -> Result<(), Self::Error> { ... }
}
Expand description

Trait for flash memory operations

Implement this trait for your flash hardware to use with Storage. The trait is generic over the error type to support different hardware backends.

Required Associated Types§

Source

type Error: Debug

The error type for flash operations

Required Methods§

Source

fn read(&mut self, addr: u32, buf: &mut [u8]) -> Result<(), Self::Error>

Read data from flash memory at the specified byte address

§Arguments
  • addr - The byte address to read from
  • buf - The buffer to read data into
Source

fn write(&mut self, addr: u32, data: &mut [u8]) -> Result<(), Self::Error>

Write data to flash memory at the specified address

Note: The data parameter is mutable because some flash drivers (e.g., w25q) require mutable access during write operations.

Source

fn erase(&mut self, addr: u32) -> Result<(), Self::Error>

Erase a flash sector or replace first byte to invalidate a slot

For EEPROM, this typically sets the first byte to 0xFF. For NOR flash, this erases an entire sector.

Provided Methods§

Source

fn erase_all(&mut self, count: usize) -> Result<(), Self::Error>

Bulk erase multiple slots/sectors

Some flash chips have optimized bulk erase operations. The default implementation erases sectors one by one.

§Arguments
  • count - The number of slots to erase

Implementors§

Source§

impl<T: Eeprom24xTrait> Flash for T
where T::Error: Debug,

Flash trait implementation for AT24Cxx EEPROM chips

Source§

impl<const SECTOR_SIZE: usize, const SECTOR_COUNT: usize> Flash for SectorMockFlash<SECTOR_SIZE, SECTOR_COUNT>

Source§

impl<const SIZE: usize> Flash for MeasuredMockFlash<SIZE>

Source§

impl<const SIZE: usize> Flash for MockFlash<SIZE>