W25

Struct W25 

Source
pub struct W25<Series, SPI, HOLD, WP> { /* private fields */ }
Expand description

Low level driver for the w25 flash memory chip.

Implementations§

Source§

impl<Series: NorSeries, SPI, S, P, HOLD, WP> W25<Series, SPI, HOLD, WP>
where SPI: SpiDevice<Error = S>, HOLD: OutputPin<Error = P>, WP: OutputPin<Error = P>, S: Debug, P: Debug,

Source

pub async fn device_id(&mut self) -> Result<[u8; 8], Error<S, P>>

Request the 64 bit id that is unique to this chip.

Source

pub async fn reset(&mut self) -> Result<(), Error<S, P>>
where Series: Reset,

Reset the chip

Source

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

Reads a chunk of bytes from the flash chip. The number of bytes read is equal to the length of the buf slice. The first byte is read from the provided address. This address is then incremented for each following byte.

§Arguments
  • address - Address where the first byte of the buf will be read.
  • buf - Slice that is going to be filled with the read bytes.
Source

pub async fn write( &mut self, address: u32, buf: &[u8], ) -> Result<(), Error<S, P>>

Writes a chunk of bytes to the flash chip. The first byte is written to the provided address. This address is then incremented for each following byte.

§Arguments
  • address - Address where the first byte of the buf will be written.
  • buf - Slice of bytes that will be written.
Source

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

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.
Source

pub async fn erase_sector(&mut self, index: u32) -> Result<(), Error<S, P>>

Erases a single sector of flash memory with the size of SECTOR_SIZE.

§Arguments
  • index - the index of the sector that needs to be erased. The address of the first byte of the sector is the provided index * SECTOR_SIZE.
Source

pub async fn erase_block_32k(&mut self, index: u32) -> Result<(), Error<S, P>>

Erases a single block of flash memory with the size of BLOCK_32K_SIZE.

§Arguments
  • index - the index of the block that needs to be erased. The address of the first byte of the block is the provided index * BLOCK_32K_SIZE.
Source

pub async fn erase_block_64k(&mut self, index: u32) -> Result<(), Error<S, P>>

Erases a single block of flash memory with the size of BLOCK_64K_SIZE.

§Arguments
  • index - the index of the block that needs to be erased. The address of the first byte of the block is the provided index * BLOCK_64K_SIZE.
Source

pub async fn erase_chip(&mut self) -> Result<(), Error<S, P>>

Erases all sectors on the flash chip. This is a very expensive operation.

Source

pub async fn enable_power_down_mode(&mut self) -> Result<(), Error<S, P>>

Puts the chip into power down mode. While in the power-down state, only the Release Power-down/Device ID (0xAB) instruction will be recognized. This instruction restores the device to normal operation. All other instructions are ignored.

Source

pub async fn disable_power_down_mode(&mut self) -> Result<(), Error<S, P>>

Releases the chip from power down mode. Restores operation from power down mode by reading the deviceID from the device.

Source§

impl<Series: NorSeries, SPI, HOLD, WP> W25<Series, SPI, HOLD, WP>

Source

pub fn capacity(&self) -> u32

Get the total capacity of the flash in bytes

Source§

impl<Series: NorSeries, SPI, S: Debug, P: Debug, HOLD, WP> W25<Series, SPI, HOLD, WP>
where SPI: ErrorType<Error = S>, HOLD: OutputPin<Error = P>, WP: OutputPin<Error = P>,

Source

pub fn new( spi: SPI, hold: HOLD, wp: WP, capacity: u32, ) -> Result<Self, Error<S, P>>

Create a new instance of the flash.

The capacity must be the total chip capacity. Weird things can happen if you provide the wrong value. No checks are done, you’re believed at your word.

Source

pub fn set_hold(&mut self, value: PinState) -> Result<(), Error<S, P>>

Set the hold pin state.

The driver doesn’t do anything with this pin. When using the chip, make sure the hold pin is not asserted. By default this means the pin needs to be high (true).

This function sets the pin directly and can cause the chip to not work.

Source

pub fn set_wp(&mut self, value: PinState) -> Result<(), Error<S, P>>

Set the write protect pin state.

The driver doesn’t do anything with this pin. When using the chip, make sure the hold pin is not asserted. By default this means the pin needs to be high (true).

This function sets the pin directly and can cause the chip to not work.

Trait Implementations§

Source§

impl<Series: NorSeries, SPI, S: Debug, P: Debug, HOLD, WP> ErrorType for W25<Series, SPI, HOLD, WP>
where SPI: ErrorType<Error = S>, HOLD: OutputPin<Error = P>, WP: OutputPin<Error = P>,

Source§

type Error = Error<S, P>

Errors returned by this NOR flash.
Source§

impl<Series: NorSeries, SPI, S, P, HOLD, WP> NorFlash for W25<Series, SPI, HOLD, WP>
where SPI: SpiDevice<Error = S>, HOLD: OutputPin<Error = P>, WP: OutputPin<Error = P>, S: Debug, P: Debug,

Source§

const WRITE_SIZE: usize = 1usize

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

const ERASE_SIZE: usize

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<Series: NorSeries, SPI, S, P, HOLD, WP> ReadNorFlash for W25<Series, SPI, HOLD, WP>
where SPI: SpiDevice<Error = S>, HOLD: OutputPin<Error = P>, WP: OutputPin<Error = P>, S: Debug, P: Debug,

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.
Source§

impl<Series: NorSeries, SPI, S, P, HOLD, WP> MultiwriteNorFlash for W25<Series, SPI, HOLD, WP>
where SPI: SpiDevice<Error = S>, HOLD: OutputPin<Error = P>, WP: OutputPin<Error = P>, S: Debug, P: Debug,

Auto Trait Implementations§

§

impl<Series, SPI, HOLD, WP> Freeze for W25<Series, SPI, HOLD, WP>
where SPI: Freeze, HOLD: Freeze, WP: Freeze,

§

impl<Series, SPI, HOLD, WP> RefUnwindSafe for W25<Series, SPI, HOLD, WP>
where SPI: RefUnwindSafe, HOLD: RefUnwindSafe, WP: RefUnwindSafe, Series: RefUnwindSafe,

§

impl<Series, SPI, HOLD, WP> Send for W25<Series, SPI, HOLD, WP>
where SPI: Send, HOLD: Send, WP: Send, Series: Send,

§

impl<Series, SPI, HOLD, WP> Sync for W25<Series, SPI, HOLD, WP>
where SPI: Sync, HOLD: Sync, WP: Sync, Series: Sync,

§

impl<Series, SPI, HOLD, WP> Unpin for W25<Series, SPI, HOLD, WP>
where SPI: Unpin, HOLD: Unpin, WP: Unpin, Series: Unpin,

§

impl<Series, SPI, HOLD, WP> UnwindSafe for W25<Series, SPI, HOLD, WP>
where SPI: UnwindSafe, HOLD: UnwindSafe, WP: UnwindSafe, Series: 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.