diff --git a/embassy-stm32/src/flash/common.rs b/embassy-stm32/src/flash/common.rs index 1376ca4b4..93d734b20 100644 --- a/embassy-stm32/src/flash/common.rs +++ b/embassy-stm32/src/flash/common.rs @@ -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, diff --git a/embassy-stm32/src/flash/g.rs b/embassy-stm32/src/flash/g.rs index 83663743c..f55c5e6a7 100644 --- a/embassy-stm32/src/flash/g.rs +++ b/embassy-stm32/src/flash/g.rs @@ -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"); + } +}