Skip to content

Commit

Permalink
Merge pull request #3583 from williams-one/add-flash-bank-selection-f…
Browse files Browse the repository at this point in the history
…or-erase

STM32U5: Add flash bank selection when erasing a sector
  • Loading branch information
Dirbaio authored Nov 28, 2024
2 parents 0349a8d + b035ff1 commit e9d310b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
4 changes: 2 additions & 2 deletions embassy-stm32/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ rand_core = "0.6.3"
sdio-host = "0.5.0"
critical-section = "1.1"
#stm32-metapac = { version = "15" }
stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-04833817666290047257c65c6547d28e1bd10dc9" }
stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-ab0ec4c19f81854189bab8215544ccd1256e1045" }

vcell = "0.1.3"
nb = "1.0.0"
Expand Down Expand Up @@ -101,7 +101,7 @@ proc-macro2 = "1.0.36"
quote = "1.0.15"

#stm32-metapac = { version = "15", default-features = false, features = ["metadata"]}
stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-04833817666290047257c65c6547d28e1bd10dc9", default-features = false, features = ["metadata"] }
stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-ab0ec4c19f81854189bab8215544ccd1256e1045", default-features = false, features = ["metadata"] }

[features]
default = ["rt"]
Expand Down
16 changes: 13 additions & 3 deletions embassy-stm32/src/flash/u5.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use core::ptr::write_volatile;
use core::sync::atomic::{fence, Ordering};

use super::{FlashRegion, FlashSector, FLASH_REGIONS, WRITE_SIZE};
use super::{FlashBank, FlashRegion, FlashSector, FLASH_REGIONS, WRITE_SIZE};
use crate::flash::Error;
use crate::pac;

Expand Down Expand Up @@ -70,12 +70,22 @@ pub(crate) unsafe fn blocking_erase_sector(sector: &FlashSector) -> Result<(), E
#[cfg(feature = "trustzone-secure")]
pac::FLASH.seccr().modify(|w| {
w.set_per(pac::flash::vals::SeccrPer::B_0X1);
w.set_pnb(sector.index_in_bank)
w.set_pnb(sector.index_in_bank);
// TODO: add check for bank swap
w.set_bker(match sector.bank {
FlashBank::Bank1 => pac::flash::vals::SeccrBker::B_0X0,
FlashBank::Bank2 => pac::flash::vals::SeccrBker::B_0X1,
});
});
#[cfg(not(feature = "trustzone-secure"))]
pac::FLASH.nscr().modify(|w| {
w.set_per(pac::flash::vals::NscrPer::B_0X1);
w.set_pnb(sector.index_in_bank)
w.set_pnb(sector.index_in_bank);
// TODO: add check for bank swap
w.set_bker(match sector.bank {
FlashBank::Bank1 => pac::flash::vals::NscrBker::B_0X0,
FlashBank::Bank2 => pac::flash::vals::NscrBker::B_0X1,
});
});

#[cfg(feature = "trustzone-secure")]
Expand Down

0 comments on commit e9d310b

Please sign in to comment.