diff --git a/embassy-stm32/src/flash/f3.rs b/embassy-stm32/src/flash/f3.rs index 1cb08ee1..dea4c3e8 100644 --- a/embassy-stm32/src/flash/f3.rs +++ b/embassy-stm32/src/flash/f3.rs @@ -99,3 +99,12 @@ pub(crate) unsafe fn blocking_wait_ready() -> Result<(), Error> { } } } + +// safety: must be called only once at startup +pub(crate) unsafe fn init() { + crate::pac::FLASH.acr().modify(|w| { + w.set_dcen(true); + w.set_icen(true); + w.set_prften(true); + }); +} diff --git a/embassy-stm32/src/flash/f4.rs b/embassy-stm32/src/flash/f4.rs index b8327ce4..614cd8d3 100644 --- a/embassy-stm32/src/flash/f4.rs +++ b/embassy-stm32/src/flash/f4.rs @@ -174,3 +174,12 @@ pub(crate) unsafe fn blocking_wait_ready() -> Result<(), Error> { } } } + +// safety: must be called only once at startup +pub(crate) unsafe fn init() { + crate::pac::FLASH.acr().modify(|w| { + w.set_dcen(true); + w.set_icen(true); + w.set_prften(true); + }); +} diff --git a/embassy-stm32/src/flash/f7.rs b/embassy-stm32/src/flash/f7.rs index 6d47b78a..3e87705e 100644 --- a/embassy-stm32/src/flash/f7.rs +++ b/embassy-stm32/src/flash/f7.rs @@ -133,3 +133,12 @@ pub(crate) unsafe fn blocking_wait_ready() -> Result<(), Error> { } } } + +// safety: must be called only once at startup +pub(crate) unsafe fn init() { + crate::pac::FLASH.acr().modify(|w| { + w.set_dcen(true); + w.set_icen(true); + w.set_prften(true); + }); +} diff --git a/embassy-stm32/src/flash/h7.rs b/embassy-stm32/src/flash/h7.rs index 3178b3be..49ba8ef3 100644 --- a/embassy-stm32/src/flash/h7.rs +++ b/embassy-stm32/src/flash/h7.rs @@ -199,3 +199,6 @@ pub(crate) unsafe fn blocking_wait_ready(bank: pac::flash::Bank) -> Result<(), E } } } + +// safety: must be called only once at startup +pub(crate) unsafe fn init() {} diff --git a/embassy-stm32/src/flash/l.rs b/embassy-stm32/src/flash/l.rs index 5048a331..e6c1826a 100644 --- a/embassy-stm32/src/flash/l.rs +++ b/embassy-stm32/src/flash/l.rs @@ -185,3 +185,12 @@ pub(crate) unsafe fn blocking_wait_ready() -> Result<(), Error> { } } } + +// safety: must be called only once at startup +pub(crate) unsafe fn init() { + crate::pac::FLASH.acr().modify(|w| { + w.set_dcen(true); + w.set_icen(true); + w.set_prften(true); + }); +} diff --git a/embassy-stm32/src/flash/mod.rs b/embassy-stm32/src/flash/mod.rs index 5d5115c9..b491f7dc 100644 --- a/embassy-stm32/src/flash/mod.rs +++ b/embassy-stm32/src/flash/mod.rs @@ -181,9 +181,5 @@ cfg_if::cfg_if! { // safety: must be called only once at startup pub(crate) unsafe fn init() { - crate::pac::FLASH.acr().modify(|w| { - w.set_dcen(true); - w.set_icen(true); - w.set_prften(true); - }); + family::init(); }