Struct stm32wlxx_hal::flash::Flash

source ·
pub struct Flash<'a> { /* private fields */ }
Expand description

Flash driver.

Implementations§

source§

impl<'a> Flash<'a>

source

pub fn unlock(flash: &'a mut FLASH) -> Self

Unlock the flash memory for program or erase operations.

The flash memory will be locked when this struct is dropped.

Example
use stm32wlxx_hal::{flash::Flash, pac};

let mut dp: pac::Peripherals = pac::Peripherals::take().unwrap();

let mut flash: Flash = Flash::unlock(&mut dp.FLASH);
source

pub unsafe fn standard_program( &mut self, from: *const u64, to: *mut u64 ) -> Result<(), Error>

Program 8 bytes.

Safety
  1. Do not write to flash memory that is being used for your code.
  2. The destination address must be within the flash memory region.
  3. The from and to pointers must be aligned to the pointee type.
source

pub unsafe fn program_bytes( &mut self, from: &[u8], to: AlignedAddr ) -> Result<(), Error>

Program any number of bytes.

This is the safest possible method for programming.

Safety
  1. Do not write to flash memory that is being used for your code.
Example
use stm32wlxx_hal::{
    flash::{Flash, Page},
    pac,
};

let mut dp: pac::Peripherals = pac::Peripherals::take().unwrap();

let my_data: [u8; 3] = [0x14, 0x15, 0x16];

let last_page: Page = Page::from_index(127).unwrap();

let mut flash: Flash = Flash::unlock(&mut dp.FLASH);
unsafe {
    flash.page_erase(last_page)?;
    flash.program_bytes(&my_data, last_page.into())?;
}
source

pub unsafe fn standard_program_generic<T>( &mut self, from: *const T, to: *mut T ) -> Result<(), Error>

Program a user-defined type.

Safety
  1. Do not write to flash memory that is being used for your code.
  2. The destination address must be within the flash memory region.
  3. The from and to pointers must be aligned to u64. Use #[repr(align(8))] to align your structure.
source

pub unsafe fn fast_program( &mut self, from: *const u64, to: *mut u64 ) -> Result<(), Error>

Program 256 bytes.

Safety
  1. Do not write to flash memory that is being used for your code.
  2. The destination address must be within the flash memory region.
  3. The flash clock frequency (HCLK3) must be at least 8 MHz.
  4. The from and to pointers must be aligned to the pointee type.
  5. The from pointer must point to 256 bytes of valid data.
  6. The CPU must execute this from SRAM. The compiler may inline this function, because #[inline(never)] is merely a suggestion.
source

pub unsafe fn page_erase(&mut self, page: Page) -> Result<(), Error>

Erases a 2048 byte page, setting all the bits to 1.

Safety
  1. Do not erase flash memory that is being used for your code.
Example

Erase the last page.

use stm32wlxx_hal::{
    flash::{Flash, Page},
    pac,
};

let mut dp: pac::Peripherals = pac::Peripherals::take().unwrap();

let last_page: Page = Page::from_index(127).unwrap();

let mut flash: Flash = Flash::unlock(&mut dp.FLASH);
unsafe { flash.page_erase(last_page)? };
source

pub unsafe fn mass_erase(&mut self) -> Result<(), Error>

Erases the entire flash memory, setting all the bits to 1.

Safety
  1. The CPU must execute this from SRAM. The compiler may inline this function, because #[inline(never)] is merely a suggestion.

Trait Implementations§

source§

impl<'a> Debug for Flash<'a>

source§

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

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

impl Drop for Flash<'_>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'a> RefUnwindSafe for Flash<'a>

§

impl<'a> Send for Flash<'a>

§

impl<'a> !Sync for Flash<'a>

§

impl<'a> Unpin for Flash<'a>

§

impl<'a> !UnwindSafe for Flash<'a>

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.