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>
impl<SPI, FlashParams, Delay> Flash<SPI, FlashParams, Delay>
Sourcepub async fn init(
spi: SPI,
delay: Delay,
poll_delay_us: u32,
_params: FlashParams,
) -> Result<Self, Error<SPI>>
pub async fn init( spi: SPI, delay: Delay, poll_delay_us: u32, _params: FlashParams, ) -> Result<Self, Error<SPI>>
Sourcepub const fn page_write_size(&self) -> usize
pub const fn page_write_size(&self) -> usize
Get the size of a page which can be written.
Sourcepub const fn sector_erase_size(&self) -> usize
pub const fn sector_erase_size(&self) -> usize
Get the size of a sector which can be erased.
Sourcepub const fn block_erase_size(&self) -> usize
pub const fn block_erase_size(&self) -> usize
Get the size of a block which can be erased.
Sourcepub async fn read_jedec_id(&mut self) -> Result<Identification, Error<SPI>>
pub async fn read_jedec_id(&mut self) -> Result<Identification, Error<SPI>>
Reads the JEDEC manufacturer/device identification.
Sourcepub async fn read_status(&mut self) -> Result<Status, Error<SPI>>
pub async fn read_status(&mut self) -> Result<Status, Error<SPI>>
Reads the status register.
pub async fn wait_done(&mut self) -> Result<(), Error<SPI>>
Sourcepub async fn read(
&mut self,
addr: u32,
buf: &mut [u8],
) -> Result<(), Error<SPI>>
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.
Sourcepub async fn erase_sector(&mut self, addr: u32) -> Result<(), Error<SPI>>
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.
Sourcepub async fn erase_block(&mut self, addr: u32) -> Result<(), Error<SPI>>
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.
Sourcepub async fn write_bytes(
&mut self,
addr: u32,
data: &[u8],
) -> Result<(), Error<SPI>>
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 toaddr
, note that it will only take the lowestPAGE_SIZE
bytes from the slice.
Sourcepub async fn erase_all(&mut self) -> Result<(), Error<SPI>>
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.
Sourcepub async fn erase_range(
&mut self,
start_address: u32,
end_address: u32,
) -> Result<(), Error<SPI>>
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.