diff options
| author | William <[email protected]> | 2024-11-27 17:29:08 +0100 |
|---|---|---|
| committer | William <[email protected]> | 2024-11-27 17:29:08 +0100 |
| commit | b035ff114502b0e63f578441250b6ff94c5efda1 (patch) | |
| tree | 0435aa91339e838a1acf4c594bfaed9664d503e8 | |
| parent | 7a9c4889960aa2fdc48af99d3765a6277da30e8e (diff) | |
stm32u5: Add flash bank selection when erasing a sector
| -rw-r--r-- | embassy-stm32/src/flash/u5.rs | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/embassy-stm32/src/flash/u5.rs b/embassy-stm32/src/flash/u5.rs index 0601017ce..e5af4f1f7 100644 --- a/embassy-stm32/src/flash/u5.rs +++ b/embassy-stm32/src/flash/u5.rs | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | use core::ptr::write_volatile; | 1 | use core::ptr::write_volatile; |
| 2 | use core::sync::atomic::{fence, Ordering}; | 2 | use core::sync::atomic::{fence, Ordering}; |
| 3 | 3 | ||
| 4 | use super::{FlashRegion, FlashSector, FLASH_REGIONS, WRITE_SIZE}; | 4 | use super::{FlashBank, FlashRegion, FlashSector, FLASH_REGIONS, WRITE_SIZE}; |
| 5 | use crate::flash::Error; | 5 | use crate::flash::Error; |
| 6 | use crate::pac; | 6 | use crate::pac; |
| 7 | 7 | ||
| @@ -70,12 +70,22 @@ pub(crate) unsafe fn blocking_erase_sector(sector: &FlashSector) -> Result<(), E | |||
| 70 | #[cfg(feature = "trustzone-secure")] | 70 | #[cfg(feature = "trustzone-secure")] |
| 71 | pac::FLASH.seccr().modify(|w| { | 71 | pac::FLASH.seccr().modify(|w| { |
| 72 | w.set_per(pac::flash::vals::SeccrPer::B_0X1); | 72 | w.set_per(pac::flash::vals::SeccrPer::B_0X1); |
| 73 | w.set_pnb(sector.index_in_bank) | 73 | w.set_pnb(sector.index_in_bank); |
| 74 | // TODO: add check for bank swap | ||
| 75 | w.set_bker(match sector.bank { | ||
| 76 | FlashBank::Bank1 => pac::flash::vals::SeccrBker::B_0X0, | ||
| 77 | FlashBank::Bank2 => pac::flash::vals::SeccrBker::B_0X1, | ||
| 78 | }); | ||
| 74 | }); | 79 | }); |
| 75 | #[cfg(not(feature = "trustzone-secure"))] | 80 | #[cfg(not(feature = "trustzone-secure"))] |
| 76 | pac::FLASH.nscr().modify(|w| { | 81 | pac::FLASH.nscr().modify(|w| { |
| 77 | w.set_per(pac::flash::vals::NscrPer::B_0X1); | 82 | w.set_per(pac::flash::vals::NscrPer::B_0X1); |
| 78 | w.set_pnb(sector.index_in_bank) | 83 | w.set_pnb(sector.index_in_bank); |
| 84 | // TODO: add check for bank swap | ||
| 85 | w.set_bker(match sector.bank { | ||
| 86 | FlashBank::Bank1 => pac::flash::vals::NscrBker::B_0X0, | ||
| 87 | FlashBank::Bank2 => pac::flash::vals::NscrBker::B_0X1, | ||
| 88 | }); | ||
| 79 | }); | 89 | }); |
| 80 | 90 | ||
| 81 | #[cfg(feature = "trustzone-secure")] | 91 | #[cfg(feature = "trustzone-secure")] |
