aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRasmus Melchior Jacobsen <[email protected]>2023-05-25 13:08:40 +0200
committerRasmus Melchior Jacobsen <[email protected]>2023-05-25 13:08:40 +0200
commitcd8198037fa37db9af7e9dde1e00122df9ed15a3 (patch)
tree252f6ad129a3ffd9cdbf0bba1f370df5e422c627
parente65ff85b88deef3e32cc437d28e36274b82ce03e (diff)
Actually transition to dual bank mode - key was required
-rw-r--r--embassy-stm32/src/flash/f4.rs29
1 files changed, 24 insertions, 5 deletions
diff --git a/embassy-stm32/src/flash/f4.rs b/embassy-stm32/src/flash/f4.rs
index 3d696223c..50ab446bd 100644
--- a/embassy-stm32/src/flash/f4.rs
+++ b/embassy-stm32/src/flash/f4.rs
@@ -71,7 +71,7 @@ mod alt_regions {
71 71
72 impl<'d> Flash<'d> { 72 impl<'d> Flash<'d> {
73 pub fn into_alt_regions(self) -> AltFlashLayout<'d, Async> { 73 pub fn into_alt_regions(self) -> AltFlashLayout<'d, Async> {
74 unsafe { crate::pac::FLASH.optcr().modify(|r| r.set_db1m(true)) }; 74 super::set_alt_layout();
75 75
76 // SAFETY: We never expose the cloned peripheral references, and their instance is not public. 76 // SAFETY: We never expose the cloned peripheral references, and their instance is not public.
77 // Also, all async flash region operations are protected with a mutex. 77 // Also, all async flash region operations are protected with a mutex.
@@ -88,7 +88,7 @@ mod alt_regions {
88 } 88 }
89 89
90 pub fn into_alt_blocking_regions(self) -> AltFlashLayout<'d, Blocking> { 90 pub fn into_alt_blocking_regions(self) -> AltFlashLayout<'d, Blocking> {
91 unsafe { crate::pac::FLASH.optcr().modify(|r| r.set_db1m(true)) }; 91 super::set_alt_layout();
92 92
93 // SAFETY: We never expose the cloned peripheral references, and their instance is not public. 93 // SAFETY: We never expose the cloned peripheral references, and their instance is not public.
94 // Also, all blocking flash region operations are protected with a cs. 94 // Also, all blocking flash region operations are protected with a cs.
@@ -171,13 +171,32 @@ static WAKER: AtomicWaker = AtomicWaker::new();
171 171
172#[cfg(any(stm32f427, stm32f429, stm32f437, stm32f439, stm32f469, stm32f479))] 172#[cfg(any(stm32f427, stm32f429, stm32f437, stm32f439, stm32f469, stm32f479))]
173pub fn set_default_layout() { 173pub fn set_default_layout() {
174 unsafe { crate::pac::FLASH.optcr().modify(|r| r.set_db1m(false)) }; 174 unsafe {
175 pac::FLASH.optkeyr().write(|w| w.set_optkey(0x08192A3B));
176 pac::FLASH.optkeyr().write(|w| w.set_optkey(0x4C5D6E7F));
177 pac::FLASH.optcr().modify(|r| {
178 r.set_db1m(false);
179 r.set_optlock(true)
180 });
181 };
175} 182}
176 183
177#[cfg(not(any(stm32f427, stm32f429, stm32f437, stm32f439, stm32f469, stm32f479)))] 184#[cfg(not(any(stm32f427, stm32f429, stm32f437, stm32f439, stm32f469, stm32f479)))]
178pub const fn set_default_layout() {} 185pub const fn set_default_layout() {}
179 186
180#[cfg(any(stm32f427, stm32f429, stm32f437, stm32f439, stm32f469, stm32f479))] 187#[cfg(any(stm32f427, stm32f429, stm32f437, stm32f439, stm32f469, stm32f479))]
188fn set_alt_layout() {
189 unsafe {
190 pac::FLASH.optkeyr().write(|w| w.set_optkey(0x08192A3B));
191 pac::FLASH.optkeyr().write(|w| w.set_optkey(0x4C5D6E7F));
192 pac::FLASH.optcr().modify(|r| {
193 r.set_db1m(true);
194 r.set_optlock(true)
195 });
196 };
197}
198
199#[cfg(any(stm32f427, stm32f429, stm32f437, stm32f439, stm32f469, stm32f479))]
181pub fn get_flash_regions() -> &'static [&'static FlashRegion] { 200pub fn get_flash_regions() -> &'static [&'static FlashRegion] {
182 if unsafe { pac::FLASH.optcr().read().db1m() } { 201 if unsafe { pac::FLASH.optcr().read().db1m() } {
183 &ALT_FLASH_REGIONS 202 &ALT_FLASH_REGIONS
@@ -207,8 +226,8 @@ pub(crate) unsafe fn lock() {
207} 226}
208 227
209pub(crate) unsafe fn unlock() { 228pub(crate) unsafe fn unlock() {
210 pac::FLASH.keyr().write(|w| w.set_key(0x4567_0123)); 229 pac::FLASH.keyr().write(|w| w.set_key(0x45670123));
211 pac::FLASH.keyr().write(|w| w.set_key(0xCDEF_89AB)); 230 pac::FLASH.keyr().write(|w| w.set_key(0xCDEF89AB));
212} 231}
213 232
214#[cfg(feature = "nightly")] 233#[cfg(feature = "nightly")]