From 7d64f5cda7226f7a30a38da68d9d4e2a31a21eaa Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Tue, 7 Jun 2022 15:59:22 +0200 Subject: [PATCH] Use correct index and bank --- embassy-stm32/src/flash/l.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/embassy-stm32/src/flash/l.rs b/embassy-stm32/src/flash/l.rs index 6ec4796a..cad950e6 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); }); }