Skip to content

Commit

Permalink
stm32u5: Add flash bank selection when erasing a sector
Browse files Browse the repository at this point in the history
  • Loading branch information
williams-one committed Nov 27, 2024
1 parent 7a9c488 commit b035ff1
Showing 1 changed file with 13 additions and 3 deletions.
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 b035ff1

Please sign in to comment.