pub unsafe fn page_erase(&mut self, page: Page) -> Result<(), Error> {
        let sr: u32 = self.sr();
        if sr & flags::BSY != 0 {
            return Err(Error::Busy);
        }
        if sr & flags::PESD != 0 {
            return Err(Error::Suspend);
        }

        self.clear_all_err();

        c1_c2!(
            self.flash.cr.modify(|_, w| w
                .per()
                .set_bit()
                .pnb()
                .bits(page.to_index())
                .strt()
                .set_bit()),
            self.flash.c2cr.modify(|_, w| w
                .per()
                .set_bit()
                .pnb()
                .bits(page.to_index())
                .strt()
                .set_bit())
        );

        let ret: Result<(), Error> = self.wait_for_not_busy();

        c1_c2!(
            self.flash.cr.modify(|_, w| w.per().clear_bit()),
            self.flash.c2cr.modify(|_, w| w.per().clear_bit())
        );

        ret
    }
/// 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.
///
/// ```no_run
/// 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)? };
/// # Ok::<(), stm32wlxx_hal::flash::Error>(())
/// ```
Erases a 2048 byte page, setting all the bits to `1`.
Erases a 2048 byte page setting all the bits to ` 1 ` .
pub unsafe fn page_erase(&mut self, page: Page) -> Result<(), Error> {
        let sr: u32 = self.sr();
        if sr & flags::BSY != 0 {
            return Err(Error::Busy);
        }
        if sr & flags::PESD != 0 {
            return Err(Error::Suspend);
        }
        self.clear_all_err();
        c1_c2!(
            self.flash.cr.modify(|_, w| w
                .per()
                .set_bit()
                .pnb()
                .bits(page.to_index())
                .strt()
                .set_bit()),
            self.flash.c2cr.modify(|_, w| w
                .per()
                .set_bit()
                .pnb()
                .bits(page.to_index())
                .strt()
                .set_bit())
        );
        let ret: Result<(), Error> = self.wait_for_not_busy();
        c1_c2!(
            self.flash.cr.modify(|_, w| w.per().clear_bit()),
            self.flash.c2cr.modify(|_, w| w.per().clear_bit())
        );
        ret
    }
pub unsafe fn page_erase ( & mut self , page : Page ) -> Result < ( ) , Error > { let sr : u32 = self . sr ( ) ; if sr & flags :: BSY != 0 { return Err ( Error :: Busy ) ; } if sr & flags :: PESD != 0 { return Err ( Error :: Suspend ) ; } self . clear_all_err ( ) ; c1_c2 ! ( self flash cr modify ( w w per ( ) set_bit ( ) pnb ( ) bits ( page to_index ( ) ) strt ( ) set_bit ( ) ) self flash c2cr modify ( w w per ( ) set_bit ( ) pnb ( ) bits ( page to_index ( ) ) strt ( ) set_bit ( ) ) ) ; let ret : Result < ( ) , Error > = self . wait_for_not_busy ( ) ; c1_c2 ! ( self flash cr modify ( w w per ( ) clear_bit ( ) ) self flash c2cr modify ( w w per ( ) clear_bit ( ) ) ) ; ret }
Erases a 2048 byte page, setting all the bits to `1`.
Erases a 2048 byte page setting all the bits to ` 1 ` .
&mut self
page
Page
safety
1. Do not erase flash memory that is being used for your code.
1 . Do not erase flash memory that is being used for your code .
example
Erase the last page.



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).
Erase the last page . 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 ) .
ok::<(), stm32wlxx_hal::flash::error>(())
None