Skip to main content

Flash

Struct Flash 

Source
pub struct Flash<'d, Dm: DriverMode> { /* private fields */ }
Available on crate feature unstable only.
Expand description

Internal SPI flash driver.

Constructible only in Blocking mode.

§Stability

This API is marked as unstable and is only available when the unstable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

Implementations§

Source§

impl<'d> Flash<'d, Blocking>

Source

pub const PAGE_SIZE: u32 = 256

Program page size in bytes.

§Stability

This API is marked as unstable and is only available when the unstable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

Source

pub const SECTOR_SIZE: u32 = 4096

Erase sector size in bytes.

§Stability

This API is marked as unstable and is only available when the unstable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

Source

pub const BLOCK_SIZE: u32 = 65536

Erase block size in bytes.

§Stability

This API is marked as unstable and is only available when the unstable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

Source

pub fn new(flash: FLASH<'d>, config: Config) -> Result<Self, ConfigError>

Creates a new flash driver from the FLASH peripheral.

Capacity is determined from the JEDEC density in the ROM-cached device ID, not the image-header size or the ROM cached chip size used by read, write, and erase operations.

§Errors
  • ConfigError::UnknownFlashChip if the attached flash chip cannot be identified or its size is not recognized. On ESP32, this error also occurs when a second-stage bootloader has not identified the chip (including the ROM placeholder ID 0x001540EF).
§Stability

This API is marked as unstable and is only available when the unstable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

Source

pub fn apply_config(&mut self, config: &Config) -> Result<(), ConfigError>

Applies a new configuration.

Updates the multi-core strategy on dual-core chips. On single-core chips, this is a no-op. The return type is reserved for future configuration options.

§Stability

This API is marked as unstable and is only available when the unstable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

Source

pub fn capacity(&self) -> usize

Returns the JEDEC-decoded flash capacity in bytes.

Driver bounds checks use this value. ROM read, write, and erase operations also check the ROM-cached chip size, which a bootloader can set from the application image header.

§Stability

This API is marked as unstable and is only available when the unstable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

Source

pub fn chip_info(&self) -> ChipInfo

Returns chip identification and geometry.

chip_id contains the manufacturer ID in bits 23:16. capacity is the JEDEC density; see Self::capacity. Geometry is fixed, not probed from the chip.

§Stability

This API is marked as unstable and is only available when the unstable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

Source

#[unsafe(link_section = ".rwtext")]
pub fn read(&mut self, offset: u32, data: &mut [u32]) -> Result<(), Error>

Reads words into data starting at byte address offset.

offset is a flash byte address and must be a multiple of 4. data must reside in DRAM, not in flash, IRAM, RTC memory, or PSRAM. An empty data slice only checks that offset is within Self::capacity.

§Errors
§Stability

This API is marked as unstable and is only available when the unstable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

Source

#[unsafe(link_section = ".rwtext")]
pub unsafe fn write(&mut self, offset: u32, data: &[u32]) -> Result<(), Error>

Writes data starting at byte address offset.

The target flash range must already be erased. offset is a flash byte address and must be a multiple of 4. data must reside in DRAM, not in flash, IRAM, RTC memory, or PSRAM. An empty data slice only checks that offset is within Self::capacity.

§Errors
§Safety

The programmed range must not be mapped for instruction fetch or as immutable data. Writing a mapped .text or .rodata page overwrites the running image or mutates data the compiler treats as immutable.

§Stability

This API is marked as unstable and is only available when the unstable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

Source

#[unsafe(link_section = ".rwtext")]
pub unsafe fn erase(&mut self, from: u32, to: u32) -> Result<(), Error>

Erases flash sectors in the range [from, to).

from and to must be multiples of Self::SECTOR_SIZE (4096 bytes); there is no byte-granular erase. to == capacity is allowed. When from == to, this function only checks that from is within Self::capacity.

§Errors
§Safety

The erased range must not be mapped for instruction fetch or as immutable data. Erasing a mapped .text or .rodata page destroys the running image or mutates data the compiler treats as immutable.

§Stability

This API is marked as unstable and is only available when the unstable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

Source

pub fn read_encrypted( &mut self, offset: u32, data: &mut [u32], ) -> Result<(), Error>

Reads decrypted words into data starting at byte address offset.

Uses a temporary MMU mapping to read decrypted data through the cache. If flash encryption is not enabled, this returns plaintext.

offset is a flash byte address and must be a multiple of 4. data must reside in DRAM, not in flash, IRAM, RTC memory, or PSRAM. An empty data slice only checks that offset is within Self::capacity.

§Errors
§Stability

This API is marked as unstable and is only available when the unstable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

Source

#[unsafe(link_section = ".rwtext")]
pub unsafe fn write_encrypted( &mut self, offset: u32, data: &[u32], ) -> Result<(), Error>

Writes data with transparent flash encryption.

offset must be a multiple of 16, and data.len() must be a multiple of 4 words (16 bytes). The destination must already be erased, and bytes outside the requested range are not programmed. data must reside in DRAM, not in flash, IRAM, RTC memory, or PSRAM.

On ESP32, encrypted writes operate in 32-byte rows. If a boundary is not 32-byte aligned, the driver preserves the adjacent 16-byte block by re-encrypting its existing plaintext to the same ciphertext. The neighbor block therefore does not require prior erasing. An empty data slice only checks that offset is within Self::capacity.

§Errors
§Safety

The programmed range must not be mapped for instruction fetch or as immutable data. Writing a mapped .text or .rodata page overwrites the running image, or mutates static or .rodata data the compiler treats as immutable.

§Stability

This API is marked as unstable and is only available when the unstable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

Trait Implementations§

Source§

impl<'d, Dm: Debug + DriverMode> Debug for Flash<'d, Dm>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'d, Dm> !UnwindSafe for Flash<'d, Dm>

§

impl<'d, Dm> Freeze for Flash<'d, Dm>

§

impl<'d, Dm> RefUnwindSafe for Flash<'d, Dm>
where Dm: RefUnwindSafe,

§

impl<'d, Dm> Send for Flash<'d, Dm>
where Dm: Send,

§

impl<'d, Dm> Sync for Flash<'d, Dm>
where Dm: Sync,

§

impl<'d, Dm> Unpin for Flash<'d, Dm>
where Dm: Unpin,

§

impl<'d, Dm> UnsafeUnpin for Flash<'d, Dm>

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

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> Same for T

Source§

type Output = T

Should always be Self
§

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.