Struct Flash

Source
pub struct Flash<SPI, FlashParams, Delay> { /* private fields */ }
Expand description

Driver for 25-series SPI Flash chips.

§Type Parameters

  • SPI: The SPI master to which the flash chip is attached.
  • FlashParams: Memory size.
  • Delay: Delay provider.

Implementations§

Source§

impl<SPI, FlashParams, Delay> Flash<SPI, FlashParams, Delay>
where SPI: SpiDevice<u8>, Delay: DelayNs, FlashParams: FlashParameters,

Source

pub async fn init( spi: SPI, delay: Delay, poll_delay_us: u32, _params: FlashParams, ) -> Result<Self, Error<SPI>>

Creates a new 26-series flash driver.

§Parameters
  • spi: An SPI master. Must be configured to operate in the correct mode for the device.
  • delay: A DelayNs implementation.
  • poll_delay_us: The delay between polling the chip when waiting for an operation to complete.
Source

pub const fn page_write_size(&self) -> usize

Get the size of a page which can be written.

Source

pub const fn sector_erase_size(&self) -> usize

Get the size of a sector which can be erased.

Source

pub const fn block_erase_size(&self) -> usize

Get the size of a block which can be erased.

Source

pub const fn chip_size(&self) -> usize

Get the size of the flash chip.

Source

pub async fn read_jedec_id(&mut self) -> Result<Identification, Error<SPI>>

Reads the JEDEC manufacturer/device identification.

Source

pub async fn read_status(&mut self) -> Result<Status, Error<SPI>>

Reads the status register.

Source

pub async fn wait_done(&mut self) -> Result<(), Error<SPI>>

Source

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

Reads flash contents into buf, starting at addr.

Note that addr is not fully decoded: Flash chips will typically only look at the lowest N bits needed to encode their size, which means that the contents are “mirrored” to addresses that are a multiple of the flash size. Only 24 bits of addr are transferred to the device in any case, limiting the maximum size of 25-series SPI flash chips to 16 MiB.

§Parameters
  • addr: 24-bit address to start reading at.
  • buf: Destination buffer to fill.
Source

pub async fn erase_sector(&mut self, addr: u32) -> Result<(), Error<SPI>>

Erases a sector from the memory chip.

§Parameters
  • addr: The address to start erasing at. If the address is not on a sector boundary, the lower bits can be ignored in order to make it fit.
Source

pub async fn erase_block(&mut self, addr: u32) -> Result<(), Error<SPI>>

Erases a block from the memory chip.

§Parameters
  • addr: The address to start erasing at. If the address is not on a block boundary, the lower bits can be ignored in order to make it fit.
Source

pub async fn write_bytes( &mut self, addr: u32, data: &[u8], ) -> Result<(), Error<SPI>>

Writes bytes onto the memory chip. This method is supposed to assume that the sectors it is writing to have already been erased and should not do any erasing themselves.

§Parameters
  • addr: The address to write to.
  • data: The bytes to write to addr, note that it will only take the lowest PAGE_SIZE bytes from the slice.
Source

pub async fn erase_all(&mut self) -> Result<(), Error<SPI>>

Erases the memory chip fully.

Warning: Full erase operations can take a significant amount of time. Check your device’s datasheet for precise numbers.

Source

pub async fn erase_range( &mut self, start_address: u32, end_address: u32, ) -> Result<(), Error<SPI>>

Erases a range of sectors. The range is expressed in bytes. These bytes need to be a multiple of SECTOR_SIZE. If the range starts at SECTOR_SIZE * 3 then the erase starts at the fourth sector. All sectors are erased in the range [start_sector..end_sector]. The start address may not be a higher value than the end address.

§Arguments
  • start_address - Address of the first byte of the start of the range of sectors that need to be erased.
  • end_address - Address of the first byte of the end of the range of sectors that need to be erased.

Trait Implementations§

Source§

impl<SPI: Debug, FlashParams: Debug, Delay: Debug> Debug for Flash<SPI, FlashParams, Delay>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<SPI, FlashParams, Delay> ErrorType for Flash<SPI, FlashParams, Delay>
where SPI: SpiDevice<u8>,

Source§

type Error = Error<SPI>

Errors returned by this NOR flash.
Source§

impl<SPI, FlashParams, Delay> FlashParameters for Flash<SPI, FlashParams, Delay>
where FlashParams: FlashParameters,

Source§

const PAGE_SIZE: usize = FlashParams::PAGE_SIZE

The page write size in bytes.
Source§

const SECTOR_SIZE: usize = FlashParams::SECTOR_SIZE

The sector erase size in bytes.
Source§

const BLOCK_SIZE: usize = FlashParams::BLOCK_SIZE

The block erase size in bytes.
Source§

const CHIP_SIZE: usize = FlashParams::CHIP_SIZE

The total chip size in bytes.
Source§

impl<SPI, FlashParams, Delay> Format for Flash<SPI, FlashParams, Delay>
where SPI: Format, Delay: Format, PhantomData<FlashParams>: Format,

Source§

fn format(&self, f: Formatter<'_>)

Writes the defmt representation of self to fmt.
Source§

impl<SPI, FlashParams, Delay> NorFlash for Flash<SPI, FlashParams, Delay>
where SPI: SpiDevice<u8>, Delay: DelayNs, FlashParams: FlashParameters,

Source§

const WRITE_SIZE: usize = 1usize

The minumum number of bytes the storage peripheral can write
Source§

const ERASE_SIZE: usize = FlashParams::SECTOR_SIZE

The minumum number of bytes the storage peripheral can erase
Source§

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

Erase the given storage range, clearing all data within [from..to]. The given range will contain all 1s afterwards. Read more
Source§

async fn write(&mut self, offset: u32, bytes: &[u8]) -> Result<(), Self::Error>

If power is lost during write, the contents of the written words are undefined, but the rest of the page is guaranteed to be unchanged. It is not allowed to write to the same word twice. Read more
Source§

impl<SPI, FlashParams, Delay> ReadNorFlash for Flash<SPI, FlashParams, Delay>
where SPI: SpiDevice<u8>, Delay: DelayNs, FlashParams: FlashParameters,

Source§

const READ_SIZE: usize = 1usize

The minumum number of bytes the storage peripheral can read
Source§

async fn read( &mut self, offset: u32, bytes: &mut [u8], ) -> Result<(), Self::Error>

Read a slice of data from the storage peripheral, starting the read operation at the given address offset, and reading bytes.len() bytes. Read more
Source§

fn capacity(&self) -> usize

The capacity of the peripheral in bytes.

Auto Trait Implementations§

§

impl<SPI, FlashParams, Delay> Freeze for Flash<SPI, FlashParams, Delay>
where SPI: Freeze, Delay: Freeze,

§

impl<SPI, FlashParams, Delay> RefUnwindSafe for Flash<SPI, FlashParams, Delay>
where SPI: RefUnwindSafe, Delay: RefUnwindSafe, FlashParams: RefUnwindSafe,

§

impl<SPI, FlashParams, Delay> Send for Flash<SPI, FlashParams, Delay>
where SPI: Send, Delay: Send, FlashParams: Send,

§

impl<SPI, FlashParams, Delay> Sync for Flash<SPI, FlashParams, Delay>
where SPI: Sync, Delay: Sync, FlashParams: Sync,

§

impl<SPI, FlashParams, Delay> Unpin for Flash<SPI, FlashParams, Delay>
where SPI: Unpin, Delay: Unpin, FlashParams: Unpin,

§

impl<SPI, FlashParams, Delay> UnwindSafe for Flash<SPI, FlashParams, Delay>
where SPI: UnwindSafe, Delay: UnwindSafe, FlashParams: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.