Struct stm32wlxx_hal::flash::Flash
source · pub struct Flash<'a> { /* private fields */ }
Expand description
Flash driver.
Implementations§
source§impl<'a> Flash<'a>
impl<'a> Flash<'a>
sourcepub fn unlock(flash: &'a mut FLASH) -> Self
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);
sourcepub unsafe fn standard_program(
&mut self,
from: *const u64,
to: *mut u64
) -> Result<(), Error>
pub unsafe fn standard_program( &mut self, from: *const u64, to: *mut u64 ) -> Result<(), Error>
Program 8 bytes.
Safety
- Do not write to flash memory that is being used for your code.
- The destination address must be within the flash memory region.
- The
from
andto
pointers must be aligned to the pointee type.
sourcepub unsafe fn program_bytes(
&mut self,
from: &[u8],
to: AlignedAddr
) -> Result<(), Error>
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
- 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())?;
}
sourcepub unsafe fn standard_program_generic<T>(
&mut self,
from: *const T,
to: *mut T
) -> Result<(), Error>
pub unsafe fn standard_program_generic<T>( &mut self, from: *const T, to: *mut T ) -> Result<(), Error>
Program a user-defined type.
Safety
- Do not write to flash memory that is being used for your code.
- The destination address must be within the flash memory region.
- The
from
andto
pointers must be aligned tou64
. Use#[repr(align(8))]
to align your structure.
sourcepub unsafe fn fast_program(
&mut self,
from: *const u64,
to: *mut u64
) -> Result<(), Error>
pub unsafe fn fast_program( &mut self, from: *const u64, to: *mut u64 ) -> Result<(), Error>
Program 256 bytes.
Safety
- Do not write to flash memory that is being used for your code.
- The destination address must be within the flash memory region.
- The flash clock frequency (HCLK3) must be at least 8 MHz.
- The
from
andto
pointers must be aligned to the pointee type. - The
from
pointer must point to 256 bytes of valid data. - The CPU must execute this from SRAM.
The compiler may inline this function, because
#[inline(never)]
is merely a suggestion.
sourcepub unsafe fn page_erase(&mut self, page: Page) -> Result<(), Error>
pub unsafe fn page_erase(&mut self, page: Page) -> Result<(), Error>
Erases a 2048 byte page, setting all the bits to 1
.
Safety
- 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)? };
Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more