aboutsummaryrefslogtreecommitdiff
path: root/embassy-stm32/src/flash
diff options
context:
space:
mode:
authorRasmus Melchior Jacobsen <[email protected]>2023-05-26 15:23:36 +0200
committerRasmus Melchior Jacobsen <[email protected]>2023-05-26 15:41:08 +0200
commitfee89ed7c7f79d7e70421e7f0915c13bcfdefb2f (patch)
tree3e3c4e1ab20de454a1ff2485aec30c2e76e2c622 /embassy-stm32/src/flash
parent31b364b9b0a18a9ebb341747861441b11f621ea0 (diff)
Remove ability to set alt layout - it does not work.
Diffstat (limited to 'embassy-stm32/src/flash')
-rw-r--r--embassy-stm32/src/flash/asynch.rs2
-rw-r--r--embassy-stm32/src/flash/common.rs2
-rw-r--r--embassy-stm32/src/flash/f0.rs4
-rw-r--r--embassy-stm32/src/flash/f3.rs4
-rw-r--r--embassy-stm32/src/flash/f4.rs35
-rw-r--r--embassy-stm32/src/flash/f7.rs4
-rw-r--r--embassy-stm32/src/flash/h7.rs4
-rw-r--r--embassy-stm32/src/flash/l.rs4
-rw-r--r--embassy-stm32/src/flash/other.rs4
9 files changed, 29 insertions, 34 deletions
diff --git a/embassy-stm32/src/flash/asynch.rs b/embassy-stm32/src/flash/asynch.rs
index a0d994956..3c3ece99a 100644
--- a/embassy-stm32/src/flash/asynch.rs
+++ b/embassy-stm32/src/flash/asynch.rs
@@ -34,7 +34,7 @@ impl<'d> Flash<'d, Async> {
34 } 34 }
35 35
36 pub fn into_regions(self) -> FlashLayout<'d, Async> { 36 pub fn into_regions(self) -> FlashLayout<'d, Async> {
37 family::set_default_layout(); 37 assert!(family::is_default_layout());
38 FlashLayout::new(self.inner) 38 FlashLayout::new(self.inner)
39 } 39 }
40 40
diff --git a/embassy-stm32/src/flash/common.rs b/embassy-stm32/src/flash/common.rs
index cc0e2572b..6c1912900 100644
--- a/embassy-stm32/src/flash/common.rs
+++ b/embassy-stm32/src/flash/common.rs
@@ -30,7 +30,7 @@ impl<'d> Flash<'d, Blocking> {
30 30
31impl<'d, MODE> Flash<'d, MODE> { 31impl<'d, MODE> Flash<'d, MODE> {
32 pub fn into_blocking_regions(self) -> FlashLayout<'d, Blocking> { 32 pub fn into_blocking_regions(self) -> FlashLayout<'d, Blocking> {
33 family::set_default_layout(); 33 assert!(family::is_default_layout());
34 FlashLayout::new(self.inner) 34 FlashLayout::new(self.inner)
35 } 35 }
36 36
diff --git a/embassy-stm32/src/flash/f0.rs b/embassy-stm32/src/flash/f0.rs
index e9916d14b..02bd4cc1f 100644
--- a/embassy-stm32/src/flash/f0.rs
+++ b/embassy-stm32/src/flash/f0.rs
@@ -7,7 +7,9 @@ use super::{FlashRegion, FlashSector, FLASH_REGIONS, WRITE_SIZE};
7use crate::flash::Error; 7use crate::flash::Error;
8use crate::pac; 8use crate::pac;
9 9
10pub const fn set_default_layout() {} 10pub const fn is_default_layout() -> bool {
11 true
12}
11 13
12pub const fn get_flash_regions() -> &'static [&'static FlashRegion] { 14pub const fn get_flash_regions() -> &'static [&'static FlashRegion] {
13 &FLASH_REGIONS 15 &FLASH_REGIONS
diff --git a/embassy-stm32/src/flash/f3.rs b/embassy-stm32/src/flash/f3.rs
index 4e65f5580..b093a7837 100644
--- a/embassy-stm32/src/flash/f3.rs
+++ b/embassy-stm32/src/flash/f3.rs
@@ -7,7 +7,9 @@ use super::{FlashRegion, FlashSector, FLASH_REGIONS, WRITE_SIZE};
7use crate::flash::Error; 7use crate::flash::Error;
8use crate::pac; 8use crate::pac;
9 9
10pub const fn set_default_layout() {} 10pub const fn is_default_layout() -> bool {
11 true
12}
11 13
12pub const fn get_flash_regions() -> &'static [&'static FlashRegion] { 14pub const fn get_flash_regions() -> &'static [&'static FlashRegion] {
13 &FLASH_REGIONS 15 &FLASH_REGIONS
diff --git a/embassy-stm32/src/flash/f4.rs b/embassy-stm32/src/flash/f4.rs
index 25d96ca1e..5e1fc696f 100644
--- a/embassy-stm32/src/flash/f4.rs
+++ b/embassy-stm32/src/flash/f4.rs
@@ -69,7 +69,7 @@ mod alt_regions {
69 69
70 impl<'d> Flash<'d> { 70 impl<'d> Flash<'d> {
71 pub fn into_alt_regions(self) -> AltFlashLayout<'d, Async> { 71 pub fn into_alt_regions(self) -> AltFlashLayout<'d, Async> {
72 super::set_alt_layout(); 72 assert!(!super::is_default_layout());
73 73
74 // SAFETY: We never expose the cloned peripheral references, and their instance is not public. 74 // SAFETY: We never expose the cloned peripheral references, and their instance is not public.
75 // Also, all async flash region operations are protected with a mutex. 75 // Also, all async flash region operations are protected with a mutex.
@@ -86,7 +86,7 @@ mod alt_regions {
86 } 86 }
87 87
88 pub fn into_alt_blocking_regions(self) -> AltFlashLayout<'d, Blocking> { 88 pub fn into_alt_blocking_regions(self) -> AltFlashLayout<'d, Blocking> {
89 super::set_alt_layout(); 89 assert!(!super::is_default_layout());
90 90
91 // SAFETY: We never expose the cloned peripheral references, and their instance is not public. 91 // SAFETY: We never expose the cloned peripheral references, and their instance is not public.
92 // Also, all blocking flash region operations are protected with a cs. 92 // Also, all blocking flash region operations are protected with a cs.
@@ -191,38 +191,21 @@ impl FlashSector {
191} 191}
192 192
193#[cfg(any(stm32f427, stm32f429, stm32f437, stm32f439, stm32f469, stm32f479))] 193#[cfg(any(stm32f427, stm32f429, stm32f437, stm32f439, stm32f469, stm32f479))]
194pub fn set_default_layout() { 194pub(crate) fn is_default_layout() -> bool {
195 unsafe { 195 unsafe { !pac::FLASH.optcr().read().db1m() }
196 pac::FLASH.optkeyr().write(|w| w.set_optkey(0x08192A3B));
197 pac::FLASH.optkeyr().write(|w| w.set_optkey(0x4C5D6E7F));
198 pac::FLASH.optcr().modify(|r| {
199 r.set_db1m(false);
200 r.set_optlock(true)
201 });
202 };
203} 196}
204 197
205#[cfg(not(any(stm32f427, stm32f429, stm32f437, stm32f439, stm32f469, stm32f479)))] 198#[cfg(not(any(stm32f427, stm32f429, stm32f437, stm32f439, stm32f469, stm32f479)))]
206pub const fn set_default_layout() {} 199pub(crate) const fn is_default_layout() -> bool {
207 200 true
208#[cfg(any(stm32f427, stm32f429, stm32f437, stm32f439, stm32f469, stm32f479))]
209fn set_alt_layout() {
210 unsafe {
211 pac::FLASH.optkeyr().write(|w| w.set_optkey(0x08192A3B));
212 pac::FLASH.optkeyr().write(|w| w.set_optkey(0x4C5D6E7F));
213 pac::FLASH.optcr().modify(|r| {
214 r.set_db1m(true);
215 r.set_optlock(true)
216 });
217 };
218} 201}
219 202
220#[cfg(any(stm32f427, stm32f429, stm32f437, stm32f439, stm32f469, stm32f479))] 203#[cfg(any(stm32f427, stm32f429, stm32f437, stm32f439, stm32f469, stm32f479))]
221pub fn get_flash_regions() -> &'static [&'static FlashRegion] { 204pub fn get_flash_regions() -> &'static [&'static FlashRegion] {
222 if unsafe { pac::FLASH.optcr().read().db1m() } { 205 if is_default_layout() {
223 &ALT_FLASH_REGIONS
224 } else {
225 &FLASH_REGIONS 206 &FLASH_REGIONS
207 } else {
208 &ALT_FLASH_REGIONS
226 } 209 }
227} 210}
228 211
diff --git a/embassy-stm32/src/flash/f7.rs b/embassy-stm32/src/flash/f7.rs
index e6267e178..1a6d6bb03 100644
--- a/embassy-stm32/src/flash/f7.rs
+++ b/embassy-stm32/src/flash/f7.rs
@@ -6,7 +6,9 @@ use super::{FlashRegion, FlashSector, FLASH_REGIONS, WRITE_SIZE};
6use crate::flash::Error; 6use crate::flash::Error;
7use crate::pac; 7use crate::pac;
8 8
9pub const fn set_default_layout() {} 9pub const fn is_default_layout() -> bool {
10 true
11}
10 12
11pub const fn get_flash_regions() -> &'static [&'static FlashRegion] { 13pub const fn get_flash_regions() -> &'static [&'static FlashRegion] {
12 &FLASH_REGIONS 14 &FLASH_REGIONS
diff --git a/embassy-stm32/src/flash/h7.rs b/embassy-stm32/src/flash/h7.rs
index d09ebc0dd..9baf059ee 100644
--- a/embassy-stm32/src/flash/h7.rs
+++ b/embassy-stm32/src/flash/h7.rs
@@ -7,7 +7,9 @@ use super::{FlashRegion, FlashSector, BANK1_REGION, FLASH_REGIONS, WRITE_SIZE};
7use crate::flash::Error; 7use crate::flash::Error;
8use crate::pac; 8use crate::pac;
9 9
10pub const fn set_default_layout() {} 10pub const fn is_default_layout() -> bool {
11 true
12}
11 13
12const fn is_dual_bank() -> bool { 14const fn is_dual_bank() -> bool {
13 FLASH_REGIONS.len() == 2 15 FLASH_REGIONS.len() == 2
diff --git a/embassy-stm32/src/flash/l.rs b/embassy-stm32/src/flash/l.rs
index c4bbd5477..deefd05ed 100644
--- a/embassy-stm32/src/flash/l.rs
+++ b/embassy-stm32/src/flash/l.rs
@@ -6,7 +6,9 @@ use super::{FlashRegion, FlashSector, FLASH_REGIONS, WRITE_SIZE};
6use crate::flash::Error; 6use crate::flash::Error;
7use crate::pac; 7use crate::pac;
8 8
9pub const fn set_default_layout() {} 9pub const fn is_default_layout() -> bool {
10 true
11}
10 12
11pub const fn get_flash_regions() -> &'static [&'static FlashRegion] { 13pub const fn get_flash_regions() -> &'static [&'static FlashRegion] {
12 &FLASH_REGIONS 14 &FLASH_REGIONS
diff --git a/embassy-stm32/src/flash/other.rs b/embassy-stm32/src/flash/other.rs
index ccdcfeb7a..a7e8d1d57 100644
--- a/embassy-stm32/src/flash/other.rs
+++ b/embassy-stm32/src/flash/other.rs
@@ -2,7 +2,9 @@
2 2
3use super::{Error, FlashRegion, FlashSector, FLASH_REGIONS, WRITE_SIZE}; 3use super::{Error, FlashRegion, FlashSector, FLASH_REGIONS, WRITE_SIZE};
4 4
5pub const fn set_default_layout() {} 5pub const fn is_default_layout() -> bool {
6 true
7}
6 8
7pub const fn get_flash_regions() -> &'static [&'static FlashRegion] { 9pub const fn get_flash_regions() -> &'static [&'static FlashRegion] {
8 &FLASH_REGIONS 10 &FLASH_REGIONS