diff --git a/embassy-stm32/src/flash/l.rs b/embassy-stm32/src/flash/l.rs index 6ec4796a5..cad950e6f 100644 --- a/embassy-stm32/src/flash/l.rs +++ b/embassy-stm32/src/flash/l.rs @@ -77,7 +77,14 @@ pub(crate) unsafe fn blocking_erase(from: u32, to: u32) -> Result<(), Error> { #[cfg(any(flash_wl, flash_wb, flash_l4))] { - let idx = page / super::ERASE_SIZE as u32; + let idx = (page - super::FLASH_BASE as u32) / super::ERASE_SIZE as u32; + + #[cfg(flash_l4)] + let (idx, bank) = if idx > 255 { + (idx - 256, true) + } else { + (idx, false) + }; pac::FLASH.cr().modify(|w| { w.set_per(true); @@ -86,6 +93,8 @@ pub(crate) unsafe fn blocking_erase(from: u32, to: u32) -> Result<(), Error> { w.set_strt(true); #[cfg(any(flash_l4))] w.set_start(true); + #[cfg(any(flash_l4))] + w.set_bker(bank); }); }