Check the bank setup when required

This commit is contained in:
Dion Dokter 2025-04-24 11:40:15 +02:00
parent 7259f20fe2
commit 19351c374a
2 changed files with 14 additions and 0 deletions

View File

@ -20,6 +20,10 @@ pub struct Flash<'d, MODE = Async> {
impl<'d> Flash<'d, Blocking> {
/// Create a new flash driver, usable in blocking mode.
pub fn new_blocking(p: Peri<'d, FLASH>) -> Self {
#[cfg(bank_setup_configurable)]
// Check if the configuration matches the embassy setup
super::check_bank_setup();
Self {
inner: p,
_mode: PhantomData,

View File

@ -109,3 +109,13 @@ fn wait_busy() {
fn wait_busy() {
while pac::FLASH.sr().read().bsy() {}
}
#[cfg(bank_setup_configurable)]
pub(crate) fn check_bank_setup() {
if cfg!(feature = "single-bank") && pac::FLASH.optr().read().dbank() {
panic!("Embassy is configured as single-bank, but the hardware is running in dual-bank mode. Change the hardware by changing the dbank value in the user option bytes or configure embassy to use dual-bank config");
}
if cfg!(feature = "dual-bank") && !pac::FLASH.optr().read().dbank() {
panic!("Embassy is configured as dual-bank, but the hardware is running in single-bank mode. Change the hardware by changing the dbank value in the user option bytes or configure embassy to use single-bank config");
}
}