Struct Flash

Source
pub struct Flash<SPI, CS: OutputPin> { /* private fields */ }
Expand description

Driver for 25-series SPI Flash chips.

§Type Parameters

  • SPI: The SPI master to which the flash chip is attached.
  • CS: The Chip-Select line attached to the \CS/\CE pin of the flash chip.

Implementations§

Source§

impl<SPI: Transfer<u8>, CS: OutputPin> Flash<SPI, CS>

Source

pub fn init(spi: SPI, cs: CS) -> Result<Self, Error<SPI, CS>>

Creates a new 25-series flash driver.

§Parameters
  • spi: An SPI master. Must be configured to operate in the correct mode for the device.
  • cs: The Chip-Select Pin connected to the \CS/\CE pin of the flash chip. Will be driven low when accessing the device.
Source

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

Reads the JEDEC manufacturer/device identification.

Source

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

Reads the status register.

Source

pub fn get_device_info(&mut self) -> Result<FlashInfo, Error<SPI, CS>>

Source

pub fn write_enable(&mut self) -> Result<(), Error<SPI, CS>>

Source

pub fn power_down(&mut self) -> Result<(), Error<SPI, CS>>

Enters power down mode. Datasheet, 8.2.35: Power-down: Although the standby current during normal operation is relatively low, standby current can be further reduced with the Power-down instruction. The lower power consumption makes the Power-down instruction especially useful for battery powered applications (See ICC1 and ICC2 in AC Characteristics). The instruction is initiated by driving the /CS pin low and shifting the instruction code “B9h” as shown in Figure 44.

The /CS pin must be driven high after the eighth bit has been latched. If this is not done the Power-down instruction will not be executed. After /CS is driven high, the power-down state will entered within the time duration of tDP (See AC Characteristics). While in the power-down state only the Release Power-down / Device ID (ABh) instruction, which restores the device to normal operation, will be recognized. All other instructions are ignored. This includes the Read Status Register instruction, which is always available during normal operation. Ignoring all but one instruction makes the Power Down state a useful condition for securing maximum write protection. The device always powers-up in the normal operation with the standby current of ICC1.

Source

pub fn release_power_down<D: DelayUs<u8>>( &mut self, delay: &mut D, ) -> Result<(), Error<SPI, CS>>

Exits Power Down Mode Datasheet, 8.2.36: Release Power-down: The Release from Power-down / Device ID instruction is a multi-purpose instruction. It can be used to release the device from the power-down state, or obtain the devices electronic identification (ID) number.
To release the device from the power-down state, the instruction is issued by driving the /CS pin low, shifting the instruction code “ABh” and driving /CS high as shown in Figure 45. Release from power-down will take the time duration of tRES1 (See AC Characteristics) before the device will resume normal operation and other instructions are accepted. The /CS pin must remain high during the tRES1 time duration.

Note: must manually delay after running this, IOC

Source

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

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 fn erase_sectors( &mut self, addr: u32, amount: usize, ) -> Result<(), Error<SPI, CS>>

Source

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

Source

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

Source

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

Trait Implementations§

Source§

impl<SPI: Debug, CS: Debug + OutputPin> Debug for Flash<SPI, CS>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<SPI, CS> Freeze for Flash<SPI, CS>
where SPI: Freeze, CS: Freeze,

§

impl<SPI, CS> RefUnwindSafe for Flash<SPI, CS>
where SPI: RefUnwindSafe, CS: RefUnwindSafe,

§

impl<SPI, CS> Send for Flash<SPI, CS>
where SPI: Send, CS: Send,

§

impl<SPI, CS> Sync for Flash<SPI, CS>
where SPI: Sync, CS: Sync,

§

impl<SPI, CS> Unpin for Flash<SPI, CS>
where SPI: Unpin, CS: Unpin,

§

impl<SPI, CS> UnwindSafe for Flash<SPI, CS>
where SPI: UnwindSafe, CS: 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.