pub unsafe fn program_bytes(&mut self, from: &[u8], to: AlignedAddr) -> Result<(), Error> {
        if from.is_empty() {
            return Ok(());
        }

        if !flash_range().contains(&usize::from(to).saturating_add(from.len())) {
            return Err(Error::Overflow);
        }

        let chunks_exact: ChunksExact<u8> = from.chunks_exact(8);
        let remainder: &[u8] = chunks_exact.remainder();
        let remainder_len: usize = remainder.len();

        let last_u64: u64 = chunks_exact
            .remainder()
            .iter()
            .enumerate()
            .fold(0, |acc, (n, byte)| acc | u64::from(*byte) << (8 * n));

        for (n, chunk) in chunks_exact.enumerate() {
            let chunk_u64: u64 = u64::from_le_bytes(chunk.try_into().unwrap());
            let addr: usize = n * size_of::<u64>() + usize::from(to);

            self.standard_program(&chunk_u64, addr as *mut u64)?;
        }

        if remainder_len != 0 {
            let last_addr: usize = (usize::from(to) + from.len()).prev_multiple_of(&8);
            self.standard_program(&last_u64, last_addr as *mut u64)?;
        }

        Ok(())
    }
/// 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
///
/// ```no_run
/// 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())?;
/// }
/// # Ok::<(), stm32wlxx_hal::flash::Error>(())
/// ```
Program any number of bytes.
This is the safest possible method for programming.
Program any number of bytes . This is the safest possible method for programming .
pub unsafe fn program_bytes(&mut self, from: &[u8], to: AlignedAddr) -> Result<(), Error> {
        if from.is_empty() {
            return Ok(());
        }
        if !flash_range().contains(&usize::from(to).saturating_add(from.len())) {
            return Err(Error::Overflow);
        }
        let chunks_exact: ChunksExact<u8> = from.chunks_exact(8);
        let remainder: &[u8] = chunks_exact.remainder();
        let remainder_len: usize = remainder.len();
        let last_u64: u64 = chunks_exact
            .remainder()
            .iter()
            .enumerate()
            .fold(0, |acc, (n, byte)| acc | u64::from(*byte) << (8 * n));
        for (n, chunk) in chunks_exact.enumerate() {
            let chunk_u64: u64 = u64::from_le_bytes(chunk.try_into().unwrap());
            let addr: usize = n * size_of::<u64>() + usize::from(to);
            self.standard_program(&chunk_u64, addr as *mut u64)?;
        }
        if remainder_len != 0 {
            let last_addr: usize = (usize::from(to) + from.len()).prev_multiple_of(&8);
            self.standard_program(&last_u64, last_addr as *mut u64)?;
        }
        Ok(())
    }
pub unsafe fn program_bytes ( & mut self , from : & [ u8 ] , to : AlignedAddr ) -> Result < ( ) , Error > { if from . is_empty ( ) { return Ok ( ( ) ) ; } if ! flash_range ( ) . contains ( & usize :: from ( to ) . saturating_add ( from . len ( ) ) ) { return Err ( Error :: Overflow ) ; } let chunks_exact : ChunksExact < u8 > = from . chunks_exact ( 8 ) ; let remainder : & [ u8 ] = chunks_exact . remainder ( ) ; let remainder_len : usize = remainder . len ( ) ; let last_u64 : u64 = chunks_exact . remainder ( ) . iter ( ) . enumerate ( ) . fold ( 0 , | acc , ( n , byte ) | acc | u64 :: from ( * byte ) << ( 8 * n ) ) ; for ( n , chunk ) in chunks_exact . enumerate ( ) { let chunk_u64 : u64 = u64 :: from_le_bytes ( chunk . try_into ( ) . unwrap ( ) ) ; let addr : usize = n * size_of :: < u64 > ( ) + usize :: from ( to ) ; self . standard_program ( & chunk_u64 , addr as * mut u64 ) ? ; } if remainder_len != 0 { let last_addr : usize = ( usize :: from ( to ) + from . len ( ) ) . prev_multiple_of ( & 8 ) ; self . standard_program ( & last_u64 , last_addr as * mut u64 ) ? ; } Ok ( ( ) ) }
Program any number of bytes.
Program any number of bytes .
&mut self
from
&[u8]
to
AlignedAddr
safety
1. Do not write to flash memory that is being used for your code.
1 . Do not write to flash memory that is being used for your code .
example


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)?;
flash.program_bytes(&my_data, last_page.into())?;
}
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 ) ? ; flash . program_bytes ( &my_data last_page . into () ) ? ; }
ok::<(), stm32wlxx_hal::flash::error>(())
None