797: Use correct index and bank for stm32 flash r=Dirbaio a=lulf

The page index was wrong because it doesn't take FLASH_BASE into account. 

For l4, the page index register also depends on a bank selection register.

Co-authored-by: Ulf Lilleengen <lulf@redhat.com>
This commit is contained in:
bors[bot] 2022-06-07 14:09:54 +00:00 committed by GitHub
commit 77c7d8f31b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -77,7 +77,14 @@ pub(crate) unsafe fn blocking_erase(from: u32, to: u32) -> Result<(), Error> {
#[cfg(any(flash_wl, flash_wb, flash_l4))] #[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| { pac::FLASH.cr().modify(|w| {
w.set_per(true); w.set_per(true);
@ -86,6 +93,8 @@ pub(crate) unsafe fn blocking_erase(from: u32, to: u32) -> Result<(), Error> {
w.set_strt(true); w.set_strt(true);
#[cfg(any(flash_l4))] #[cfg(any(flash_l4))]
w.set_start(true); w.set_start(true);
#[cfg(any(flash_l4))]
w.set_bker(bank);
}); });
} }