aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUlf Lilleengen <[email protected]>2025-05-06 12:12:10 +0000
committerGitHub <[email protected]>2025-05-06 12:12:10 +0000
commit966914f4654f30f13964f90c1e2bd491f1105c6f (patch)
tree81c3254e160d67cb08255d0557276614db86a240
parentaf6f5ca0c42bc5a3e740bbeb09ba00a543d21d6b (diff)
parent8017d58eb941c6e7700c2cd21ebcb216d9d9f556 (diff)
Merge pull request #4125 from diondokter/configurable-bank-support
STM32: Configurable bank support
-rwxr-xr-x.github/ci/test.sh8
-rwxr-xr-xci.sh25
-rw-r--r--embassy-stm32/CHANGELOG.md1
-rw-r--r--embassy-stm32/Cargo.toml7
-rw-r--r--embassy-stm32/build.rs63
-rw-r--r--embassy-stm32/src/flash/asynch.rs7
-rw-r--r--embassy-stm32/src/flash/common.rs11
-rw-r--r--embassy-stm32/src/flash/f0.rs10
-rw-r--r--embassy-stm32/src/flash/f1f3.rs10
-rw-r--r--embassy-stm32/src/flash/f2.rs10
-rw-r--r--embassy-stm32/src/flash/f4.rs337
-rw-r--r--embassy-stm32/src/flash/f7.rs77
-rw-r--r--embassy-stm32/src/flash/g.rs30
-rw-r--r--embassy-stm32/src/flash/h5.rs14
-rw-r--r--embassy-stm32/src/flash/h50.rs10
-rw-r--r--embassy-stm32/src/flash/h7.rs10
-rw-r--r--embassy-stm32/src/flash/l.rs30
-rw-r--r--embassy-stm32/src/flash/mod.rs10
-rw-r--r--embassy-stm32/src/flash/other.rs10
-rw-r--r--embassy-stm32/src/flash/u0.rs10
-rw-r--r--embassy-stm32/src/flash/u5.rs10
-rw-r--r--examples/boot/application/stm32f7/Cargo.toml2
-rw-r--r--examples/stm32f7/Cargo.toml2
-rw-r--r--examples/stm32l4/Cargo.toml2
-rw-r--r--examples/stm32l5/Cargo.toml2
-rw-r--r--tests/stm32/Cargo.toml8
26 files changed, 287 insertions, 429 deletions
diff --git a/.github/ci/test.sh b/.github/ci/test.sh
index c78865e54..c9b332cf8 100755
--- a/.github/ci/test.sh
+++ b/.github/ci/test.sh
@@ -29,8 +29,10 @@ cargo test --manifest-path ./embassy-nrf/Cargo.toml --no-default-features --feat
29cargo test --manifest-path ./embassy-rp/Cargo.toml --no-default-features --features time-driver,rp2040,_test 29cargo test --manifest-path ./embassy-rp/Cargo.toml --no-default-features --features time-driver,rp2040,_test
30cargo test --manifest-path ./embassy-rp/Cargo.toml --no-default-features --features time-driver,rp235xa,_test 30cargo test --manifest-path ./embassy-rp/Cargo.toml --no-default-features --features time-driver,rp235xa,_test
31 31
32cargo test --manifest-path ./embassy-stm32/Cargo.toml --no-default-features --features stm32f429vg,exti,time-driver-any,exti 32cargo test --manifest-path ./embassy-stm32/Cargo.toml --no-default-features --features stm32f429vg,time-driver-any,exti,single-bank
33cargo test --manifest-path ./embassy-stm32/Cargo.toml --no-default-features --features stm32f732ze,exti,time-driver-any,exti 33cargo test --manifest-path ./embassy-stm32/Cargo.toml --no-default-features --features stm32f429vg,time-driver-any,exti,dual-bank
34cargo test --manifest-path ./embassy-stm32/Cargo.toml --no-default-features --features stm32f769ni,exti,time-driver-any,exti 34cargo test --manifest-path ./embassy-stm32/Cargo.toml --no-default-features --features stm32f732ze,time-driver-any,exti
35cargo test --manifest-path ./embassy-stm32/Cargo.toml --no-default-features --features stm32f769ni,time-driver-any,exti,single-bank
36cargo test --manifest-path ./embassy-stm32/Cargo.toml --no-default-features --features stm32f769ni,time-driver-any,exti,dual-bank
35 37
36cargo test --manifest-path ./embassy-net-adin1110/Cargo.toml 38cargo test --manifest-path ./embassy-net-adin1110/Cargo.toml
diff --git a/ci.sh b/ci.sh
index 5a438f0b1..6e320e4d1 100755
--- a/ci.sh
+++ b/ci.sh
@@ -88,16 +88,17 @@ cargo batch \
88 --- build --release --manifest-path embassy-rp/Cargo.toml --target thumbv8m.main-none-eabihf --features time-driver,defmt,rp235xa \ 88 --- build --release --manifest-path embassy-rp/Cargo.toml --target thumbv8m.main-none-eabihf --features time-driver,defmt,rp235xa \
89 --- build --release --manifest-path embassy-rp/Cargo.toml --target thumbv8m.main-none-eabihf --features time-driver,log,rp235xa \ 89 --- build --release --manifest-path embassy-rp/Cargo.toml --target thumbv8m.main-none-eabihf --features time-driver,log,rp235xa \
90 --- build --release --manifest-path embassy-rp/Cargo.toml --target thumbv8m.main-none-eabihf --features time-driver,rp235xa,binary-info \ 90 --- build --release --manifest-path embassy-rp/Cargo.toml --target thumbv8m.main-none-eabihf --features time-driver,rp235xa,binary-info \
91 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv8m.main-none-eabihf --features stm32l552ze,defmt,exti,time-driver-any,time \ 91 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv8m.main-none-eabihf --features stm32l552ze,dual-bank,defmt,exti,time-driver-any,time \
92 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv8m.main-none-eabihf --features stm32l552ze,defmt,time-driver-any,time \ 92 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv8m.main-none-eabihf --features stm32l552ze,dual-bank,defmt,time-driver-any,time \
93 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv8m.main-none-eabihf --features stm32l552ze,defmt,exti,time \ 93 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv8m.main-none-eabihf --features stm32l552ze,dual-bank,defmt,exti,time \
94 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv8m.main-none-eabihf --features stm32l552ze,defmt,time \ 94 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv8m.main-none-eabihf --features stm32l552ze,dual-bank,defmt,time \
95 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv8m.main-none-eabihf --features stm32l552ze,defmt,exti,time-driver-any,time \ 95 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv8m.main-none-eabihf --features stm32l552ze,dual-bank,defmt,exti,time-driver-any,time \
96 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv8m.main-none-eabihf --features stm32l552ze,defmt,time-driver-any,time \ 96 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv8m.main-none-eabihf --features stm32l552ze,dual-bank,defmt,time-driver-any,time \
97 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv8m.main-none-eabihf --features stm32l552ze,defmt,exti,time \ 97 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv8m.main-none-eabihf --features stm32l552ze,dual-bank,defmt,exti,time \
98 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv8m.main-none-eabihf --features stm32l552ze,defmt,time \ 98 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv8m.main-none-eabihf --features stm32l552ze,dual-bank,defmt,time \
99 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv8m.main-none-eabihf --features stm32l552ze,defmt,exti \ 99 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv8m.main-none-eabihf --features stm32l552ze,dual-bank,defmt,exti \
100 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv8m.main-none-eabihf --features stm32l552ze,defmt \ 100 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv8m.main-none-eabihf --features stm32l552ze,dual-bank,defmt \
101 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv8m.main-none-eabihf --features stm32l552ze,single-bank,defmt \
101 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv6m-none-eabi --features stm32f038f6,defmt,exti,time-driver-any,time \ 102 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv6m-none-eabi --features stm32f038f6,defmt,exti,time-driver-any,time \
102 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv6m-none-eabi --features stm32f030c6,defmt,exti,time-driver-any,time \ 103 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv6m-none-eabi --features stm32f030c6,defmt,exti,time-driver-any,time \
103 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv6m-none-eabi --features stm32f058t8,defmt,exti,time-driver-any,time \ 104 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv6m-none-eabi --features stm32f058t8,defmt,exti,time-driver-any,time \
@@ -153,10 +154,10 @@ cargo batch \
153 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f378cc,defmt,exti,time-driver-any,time \ 154 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f378cc,defmt,exti,time-driver-any,time \
154 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv6m-none-eabi --features stm32g0c1ve,defmt,exti,time-driver-any,time \ 155 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv6m-none-eabi --features stm32g0c1ve,defmt,exti,time-driver-any,time \
155 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features stm32f217zg,defmt,exti,time-driver-any,time \ 156 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features stm32f217zg,defmt,exti,time-driver-any,time \
156 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv8m.main-none-eabihf --features stm32l552ze,defmt,exti,time-driver-any,low-power,time \ 157 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv8m.main-none-eabihf --features stm32l552ze,dual-bank,defmt,exti,time-driver-any,low-power,time \
157 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv6m-none-eabi --features stm32wl54jc-cm0p,defmt,exti,time-driver-any,time \ 158 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv6m-none-eabi --features stm32wl54jc-cm0p,defmt,exti,time-driver-any,time \
158 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32wle5jb,defmt,exti,time-driver-any,time \ 159 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32wle5jb,defmt,exti,time-driver-any,time \
159 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32g474pe,defmt,exti,time-driver-any,time \ 160 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32g474pe,dual-bank,defmt,exti,time-driver-any,time \
160 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features stm32f107vc,defmt,exti,time-driver-any,time \ 161 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features stm32f107vc,defmt,exti,time-driver-any,time \
161 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features stm32f103re,defmt,exti,time-driver-any,time \ 162 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features stm32f103re,defmt,exti,time-driver-any,time \
162 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features stm32f100c4,defmt,exti,time-driver-any,time \ 163 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features stm32f100c4,defmt,exti,time-driver-any,time \
diff --git a/embassy-stm32/CHANGELOG.md b/embassy-stm32/CHANGELOG.md
index c50ab5294..b6781905e 100644
--- a/embassy-stm32/CHANGELOG.md
+++ b/embassy-stm32/CHANGELOG.md
@@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7 7
8## Unreleased 8## Unreleased
9- Modify BufferedUart initialization to take pins before interrupts ([#3983](https://github.com/embassy-rs/embassy/pull/3983)) 9- Modify BufferedUart initialization to take pins before interrupts ([#3983](https://github.com/embassy-rs/embassy/pull/3983))
10- Added a 'single-bank' and a 'dual-bank' feature so chips with configurable flash bank setups are be supported in embassy ([#4125](https://github.com/embassy-rs/embassy/pull/4125))
10 11
11## 0.2.0 - 2025-01-10 12## 0.2.0 - 2025-01-10
12 13
diff --git a/embassy-stm32/Cargo.toml b/embassy-stm32/Cargo.toml
index e9f236881..972307bec 100644
--- a/embassy-stm32/Cargo.toml
+++ b/embassy-stm32/Cargo.toml
@@ -73,7 +73,7 @@ rand_core = "0.6.3"
73sdio-host = "0.9.0" 73sdio-host = "0.9.0"
74critical-section = "1.1" 74critical-section = "1.1"
75#stm32-metapac = { version = "16" } 75#stm32-metapac = { version = "16" }
76stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-169e38298f9421dddbabc0eb81d0c30fb1eec0a7" } 76stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-7251801e3273011ce28a89e8f2e45eec2e419e26" }
77 77
78vcell = "0.1.3" 78vcell = "0.1.3"
79nb = "1.0.0" 79nb = "1.0.0"
@@ -102,7 +102,7 @@ proc-macro2 = "1.0.36"
102quote = "1.0.15" 102quote = "1.0.15"
103 103
104#stm32-metapac = { version = "16", default-features = false, features = ["metadata"]} 104#stm32-metapac = { version = "16", default-features = false, features = ["metadata"]}
105stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-169e38298f9421dddbabc0eb81d0c30fb1eec0a7", default-features = false, features = ["metadata"] } 105stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-7251801e3273011ce28a89e8f2e45eec2e419e26", default-features = false, features = ["metadata"] }
106 106
107[features] 107[features]
108default = ["rt"] 108default = ["rt"]
@@ -197,6 +197,9 @@ split-pc2 = ["_split-pins-enabled"]
197## Split PC3 197## Split PC3
198split-pc3 = ["_split-pins-enabled"] 198split-pc3 = ["_split-pins-enabled"]
199 199
200dual-bank = []
201single-bank = []
202
200## internal use only 203## internal use only
201_split-pins-enabled = [] 204_split-pins-enabled = []
202 205
diff --git a/embassy-stm32/build.rs b/embassy-stm32/build.rs
index 3fefa9717..b00b6a7ac 100644
--- a/embassy-stm32/build.rs
+++ b/embassy-stm32/build.rs
@@ -50,6 +50,44 @@ fn main() {
50 } 50 }
51 51
52 // ======== 52 // ========
53 // Select the memory variant to use
54 let memory = {
55 let single_bank_selected = env::var("CARGO_FEATURE_SINGLE_BANK").is_ok();
56 let dual_bank_selected = env::var("CARGO_FEATURE_DUAL_BANK").is_ok();
57
58 let single_bank_memory = METADATA.memory.iter().find(|mem| {
59 mem.iter().any(|region| region.name.contains("BANK_1"))
60 && !mem.iter().any(|region| region.name.contains("BANK_2"))
61 });
62
63 let dual_bank_memory = METADATA.memory.iter().find(|mem| {
64 mem.iter().any(|region| region.name.contains("BANK_1"))
65 && mem.iter().any(|region| region.name.contains("BANK_2"))
66 });
67
68 cfgs.set(
69 "bank_setup_configurable",
70 single_bank_memory.is_some() && dual_bank_memory.is_some(),
71 );
72
73 match (single_bank_selected, dual_bank_selected) {
74 (true, true) => panic!("Both 'single-bank' and 'dual-bank' features enabled"),
75 (true, false) => {
76 single_bank_memory.expect("The 'single-bank' feature is not supported on this dual bank chip")
77 }
78 (false, true) => {
79 dual_bank_memory.expect("The 'dual-bank' feature is not supported on this single bank chip")
80 }
81 (false, false) => {
82 if METADATA.memory.len() != 1 {
83 panic!("Chip supports single and dual bank configuration. No Cargo feature to select one is enabled. Use the 'single-bank' or 'dual-bank' feature to make your selection")
84 }
85 METADATA.memory[0]
86 }
87 }
88 };
89
90 // ========
53 // Generate singletons 91 // Generate singletons
54 92
55 let mut singletons: Vec<String> = Vec::new(); 93 let mut singletons: Vec<String> = Vec::new();
@@ -290,8 +328,7 @@ fn main() {
290 // ======== 328 // ========
291 // Generate FLASH regions 329 // Generate FLASH regions
292 let mut flash_regions = TokenStream::new(); 330 let mut flash_regions = TokenStream::new();
293 let flash_memory_regions: Vec<_> = METADATA 331 let flash_memory_regions: Vec<_> = memory
294 .memory
295 .iter() 332 .iter()
296 .filter(|x| x.kind == MemoryRegionKind::Flash && x.settings.is_some()) 333 .filter(|x| x.kind == MemoryRegionKind::Flash && x.settings.is_some())
297 .collect(); 334 .collect();
@@ -1621,8 +1658,7 @@ fn main() {
1621 let mut pins_table: Vec<Vec<String>> = Vec::new(); 1658 let mut pins_table: Vec<Vec<String>> = Vec::new();
1622 let mut adc_table: Vec<Vec<String>> = Vec::new(); 1659 let mut adc_table: Vec<Vec<String>> = Vec::new();
1623 1660
1624 for m in METADATA 1661 for m in memory
1625 .memory
1626 .iter() 1662 .iter()
1627 .filter(|m| m.kind == MemoryRegionKind::Flash && m.settings.is_some()) 1663 .filter(|m| m.kind == MemoryRegionKind::Flash && m.settings.is_some())
1628 { 1664 {
@@ -1860,8 +1896,7 @@ fn main() {
1860 // ======== 1896 // ========
1861 // Generate flash constants 1897 // Generate flash constants
1862 1898
1863 let flash_regions: Vec<&MemoryRegion> = METADATA 1899 let flash_regions: Vec<&MemoryRegion> = memory
1864 .memory
1865 .iter() 1900 .iter()
1866 .filter(|x| x.kind == MemoryRegionKind::Flash && x.name.starts_with("BANK_")) 1901 .filter(|x| x.kind == MemoryRegionKind::Flash && x.name.starts_with("BANK_"))
1867 .collect(); 1902 .collect();
@@ -1986,7 +2021,7 @@ fn main() {
1986 println!("cargo:rerun-if-changed=build.rs"); 2021 println!("cargo:rerun-if-changed=build.rs");
1987 2022
1988 if cfg!(feature = "memory-x") { 2023 if cfg!(feature = "memory-x") {
1989 gen_memory_x(out_dir); 2024 gen_memory_x(memory, out_dir);
1990 println!("cargo:rustc-link-search={}", out_dir.display()); 2025 println!("cargo:rustc-link-search={}", out_dir.display());
1991 } 2026 }
1992} 2027}
@@ -2075,11 +2110,11 @@ fn rustfmt(path: impl AsRef<Path>) {
2075 } 2110 }
2076} 2111}
2077 2112
2078fn gen_memory_x(out_dir: &Path) { 2113fn gen_memory_x(memory: &[MemoryRegion], out_dir: &Path) {
2079 let mut memory_x = String::new(); 2114 let mut memory_x = String::new();
2080 2115
2081 let flash = get_memory_range(MemoryRegionKind::Flash); 2116 let flash = get_memory_range(memory, MemoryRegionKind::Flash);
2082 let ram = get_memory_range(MemoryRegionKind::Ram); 2117 let ram = get_memory_range(memory, MemoryRegionKind::Ram);
2083 2118
2084 write!(memory_x, "MEMORY\n{{\n").unwrap(); 2119 write!(memory_x, "MEMORY\n{{\n").unwrap();
2085 writeln!( 2120 writeln!(
@@ -2103,12 +2138,8 @@ fn gen_memory_x(out_dir: &Path) {
2103 std::fs::write(out_dir.join("memory.x"), memory_x.as_bytes()).unwrap(); 2138 std::fs::write(out_dir.join("memory.x"), memory_x.as_bytes()).unwrap();
2104} 2139}
2105 2140
2106fn get_memory_range(kind: MemoryRegionKind) -> (u32, u32, String) { 2141fn get_memory_range(memory: &[MemoryRegion], kind: MemoryRegionKind) -> (u32, u32, String) {
2107 let mut mems: Vec<_> = METADATA 2142 let mut mems: Vec<_> = memory.iter().filter(|m| m.kind == kind && m.size != 0).collect();
2108 .memory
2109 .iter()
2110 .filter(|m| m.kind == kind && m.size != 0)
2111 .collect();
2112 mems.sort_by_key(|m| m.address); 2143 mems.sort_by_key(|m| m.address);
2113 2144
2114 let mut start = u32::MAX; 2145 let mut start = u32::MAX;
diff --git a/embassy-stm32/src/flash/asynch.rs b/embassy-stm32/src/flash/asynch.rs
index 599b7bb4e..006dcddeb 100644
--- a/embassy-stm32/src/flash/asynch.rs
+++ b/embassy-stm32/src/flash/asynch.rs
@@ -6,8 +6,8 @@ use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
6use embassy_sync::mutex::Mutex; 6use embassy_sync::mutex::Mutex;
7 7
8use super::{ 8use super::{
9 blocking_read, ensure_sector_aligned, family, get_sector, Async, Error, Flash, FlashLayout, FLASH_BASE, FLASH_SIZE, 9 blocking_read, ensure_sector_aligned, family, get_flash_regions, get_sector, Async, Error, Flash, FlashLayout,
10 WRITE_SIZE, 10 FLASH_BASE, FLASH_SIZE, WRITE_SIZE,
11}; 11};
12use crate::interrupt::InterruptExt; 12use crate::interrupt::InterruptExt;
13use crate::peripherals::FLASH; 13use crate::peripherals::FLASH;
@@ -34,7 +34,6 @@ impl<'d> Flash<'d, Async> {
34 /// 34 ///
35 /// See module-level documentation for details on how memory regions work. 35 /// See module-level documentation for details on how memory regions work.
36 pub fn into_regions(self) -> FlashLayout<'d, Async> { 36 pub fn into_regions(self) -> FlashLayout<'d, Async> {
37 assert!(family::is_default_layout());
38 FlashLayout::new(self.inner) 37 FlashLayout::new(self.inner)
39 } 38 }
40 39
@@ -123,7 +122,7 @@ pub(super) async unsafe fn write_chunked(base: u32, size: u32, offset: u32, byte
123pub(super) async unsafe fn erase_sectored(base: u32, from: u32, to: u32) -> Result<(), Error> { 122pub(super) async unsafe fn erase_sectored(base: u32, from: u32, to: u32) -> Result<(), Error> {
124 let start_address = base + from; 123 let start_address = base + from;
125 let end_address = base + to; 124 let end_address = base + to;
126 let regions = family::get_flash_regions(); 125 let regions = get_flash_regions();
127 126
128 ensure_sector_aligned(start_address, end_address, regions)?; 127 ensure_sector_aligned(start_address, end_address, regions)?;
129 128
diff --git a/embassy-stm32/src/flash/common.rs b/embassy-stm32/src/flash/common.rs
index 1376ca4b4..10023e637 100644
--- a/embassy-stm32/src/flash/common.rs
+++ b/embassy-stm32/src/flash/common.rs
@@ -4,8 +4,8 @@ use core::sync::atomic::{fence, Ordering};
4use embassy_hal_internal::drop::OnDrop; 4use embassy_hal_internal::drop::OnDrop;
5 5
6use super::{ 6use super::{
7 family, Async, Blocking, Error, FlashBank, FlashLayout, FlashRegion, FlashSector, FLASH_SIZE, MAX_ERASE_SIZE, 7 family, get_flash_regions, Async, Blocking, Error, FlashBank, FlashLayout, FlashRegion, FlashSector, FLASH_SIZE,
8 READ_SIZE, WRITE_SIZE, 8 MAX_ERASE_SIZE, READ_SIZE, WRITE_SIZE,
9}; 9};
10use crate::Peri; 10use crate::Peri;
11use crate::_generated::FLASH_BASE; 11use crate::_generated::FLASH_BASE;
@@ -20,6 +20,10 @@ pub struct Flash<'d, MODE = Async> {
20impl<'d> Flash<'d, Blocking> { 20impl<'d> Flash<'d, Blocking> {
21 /// Create a new flash driver, usable in blocking mode. 21 /// Create a new flash driver, usable in blocking mode.
22 pub fn new_blocking(p: Peri<'d, FLASH>) -> Self { 22 pub fn new_blocking(p: Peri<'d, FLASH>) -> Self {
23 #[cfg(bank_setup_configurable)]
24 // Check if the configuration matches the embassy setup
25 super::check_bank_setup();
26
23 Self { 27 Self {
24 inner: p, 28 inner: p,
25 _mode: PhantomData, 29 _mode: PhantomData,
@@ -32,7 +36,6 @@ impl<'d, MODE> Flash<'d, MODE> {
32 /// 36 ///
33 /// See module-level documentation for details on how memory regions work. 37 /// See module-level documentation for details on how memory regions work.
34 pub fn into_blocking_regions(self) -> FlashLayout<'d, Blocking> { 38 pub fn into_blocking_regions(self) -> FlashLayout<'d, Blocking> {
35 assert!(family::is_default_layout());
36 FlashLayout::new(self.inner) 39 FlashLayout::new(self.inner)
37 } 40 }
38 41
@@ -137,7 +140,7 @@ pub(super) unsafe fn blocking_erase(
137) -> Result<(), Error> { 140) -> Result<(), Error> {
138 let start_address = base + from; 141 let start_address = base + from;
139 let end_address = base + to; 142 let end_address = base + to;
140 let regions = family::get_flash_regions(); 143 let regions = get_flash_regions();
141 144
142 ensure_sector_aligned(start_address, end_address, regions)?; 145 ensure_sector_aligned(start_address, end_address, regions)?;
143 146
diff --git a/embassy-stm32/src/flash/f0.rs b/embassy-stm32/src/flash/f0.rs
index 402312f68..3f9dbe945 100644
--- a/embassy-stm32/src/flash/f0.rs
+++ b/embassy-stm32/src/flash/f0.rs
@@ -1,18 +1,10 @@
1use core::ptr::write_volatile; 1use core::ptr::write_volatile;
2use core::sync::atomic::{fence, Ordering}; 2use core::sync::atomic::{fence, Ordering};
3 3
4use super::{FlashRegion, FlashSector, FLASH_REGIONS, WRITE_SIZE}; 4use super::{FlashSector, WRITE_SIZE};
5use crate::flash::Error; 5use crate::flash::Error;
6use crate::pac; 6use crate::pac;
7 7
8pub(crate) const fn is_default_layout() -> bool {
9 true
10}
11
12pub(crate) const fn get_flash_regions() -> &'static [&'static FlashRegion] {
13 &FLASH_REGIONS
14}
15
16pub(crate) unsafe fn lock() { 8pub(crate) unsafe fn lock() {
17 pac::FLASH.cr().modify(|w| w.set_lock(true)); 9 pac::FLASH.cr().modify(|w| w.set_lock(true));
18} 10}
diff --git a/embassy-stm32/src/flash/f1f3.rs b/embassy-stm32/src/flash/f1f3.rs
index ec237b9ff..bf9ad2893 100644
--- a/embassy-stm32/src/flash/f1f3.rs
+++ b/embassy-stm32/src/flash/f1f3.rs
@@ -1,18 +1,10 @@
1use core::ptr::write_volatile; 1use core::ptr::write_volatile;
2use core::sync::atomic::{fence, Ordering}; 2use core::sync::atomic::{fence, Ordering};
3 3
4use super::{FlashRegion, FlashSector, FLASH_REGIONS, WRITE_SIZE}; 4use super::{FlashSector, WRITE_SIZE};
5use crate::flash::Error; 5use crate::flash::Error;
6use crate::pac; 6use crate::pac;
7 7
8pub(crate) const fn is_default_layout() -> bool {
9 true
10}
11
12pub(crate) const fn get_flash_regions() -> &'static [&'static FlashRegion] {
13 &FLASH_REGIONS
14}
15
16pub(crate) unsafe fn lock() { 8pub(crate) unsafe fn lock() {
17 pac::FLASH.cr().modify(|w| w.set_lock(true)); 9 pac::FLASH.cr().modify(|w| w.set_lock(true));
18} 10}
diff --git a/embassy-stm32/src/flash/f2.rs b/embassy-stm32/src/flash/f2.rs
index cdab1fd2d..67e380619 100644
--- a/embassy-stm32/src/flash/f2.rs
+++ b/embassy-stm32/src/flash/f2.rs
@@ -3,7 +3,7 @@ use core::sync::atomic::{fence, AtomicBool, Ordering};
3 3
4use pac::flash::regs::Sr; 4use pac::flash::regs::Sr;
5 5
6use super::{FlashBank, FlashRegion, FlashSector, FLASH_REGIONS, WRITE_SIZE}; 6use super::{get_flash_regions, FlashBank, FlashSector, WRITE_SIZE};
7use crate::flash::Error; 7use crate::flash::Error;
8use crate::pac; 8use crate::pac;
9 9
@@ -15,14 +15,6 @@ impl FlashSector {
15 } 15 }
16} 16}
17 17
18pub(crate) const fn is_default_layout() -> bool {
19 true
20}
21
22pub(crate) const fn get_flash_regions() -> &'static [&'static FlashRegion] {
23 &FLASH_REGIONS
24}
25
26pub(crate) unsafe fn lock() { 18pub(crate) unsafe fn lock() {
27 pac::FLASH.cr().modify(|w| w.set_lock(true)); 19 pac::FLASH.cr().modify(|w| w.set_lock(true));
28} 20}
diff --git a/embassy-stm32/src/flash/f4.rs b/embassy-stm32/src/flash/f4.rs
index 687eabaeb..62e0492b5 100644
--- a/embassy-stm32/src/flash/f4.rs
+++ b/embassy-stm32/src/flash/f4.rs
@@ -4,177 +4,10 @@ use core::sync::atomic::{fence, AtomicBool, Ordering};
4use embassy_sync::waitqueue::AtomicWaker; 4use embassy_sync::waitqueue::AtomicWaker;
5use pac::flash::regs::Sr; 5use pac::flash::regs::Sr;
6 6
7use super::{FlashBank, FlashRegion, FlashSector, FLASH_REGIONS, WRITE_SIZE}; 7use super::{get_flash_regions, FlashBank, FlashSector, WRITE_SIZE};
8use crate::_generated::FLASH_SIZE; 8use crate::_generated::FLASH_SIZE;
9use crate::flash::Error; 9use crate::flash::Error;
10use crate::pac; 10use crate::pac;
11#[allow(missing_docs)] // TODO
12#[cfg(any(stm32f427, stm32f429, stm32f437, stm32f439, stm32f469, stm32f479))]
13mod alt_regions {
14 use core::marker::PhantomData;
15
16 use crate::Peri;
17 use crate::_generated::flash_regions::{OTPRegion, BANK1_REGION1, BANK1_REGION2, BANK1_REGION3, OTP_REGION};
18 use crate::_generated::FLASH_SIZE;
19 use crate::flash::{asynch, Async, Bank1Region1, Bank1Region2, Blocking, Error, Flash, FlashBank, FlashRegion};
20 use crate::peripherals::FLASH;
21
22 pub const ALT_BANK1_REGION3: FlashRegion = FlashRegion {
23 size: 3 * BANK1_REGION3.erase_size,
24 ..BANK1_REGION3
25 };
26 pub const ALT_BANK2_REGION1: FlashRegion = FlashRegion {
27 bank: FlashBank::Bank2,
28 base: BANK1_REGION1.base + FLASH_SIZE as u32 / 2,
29 ..BANK1_REGION1
30 };
31 pub const ALT_BANK2_REGION2: FlashRegion = FlashRegion {
32 bank: FlashBank::Bank2,
33 base: BANK1_REGION2.base + FLASH_SIZE as u32 / 2,
34 ..BANK1_REGION2
35 };
36 pub const ALT_BANK2_REGION3: FlashRegion = FlashRegion {
37 bank: FlashBank::Bank2,
38 base: BANK1_REGION3.base + FLASH_SIZE as u32 / 2,
39 size: 3 * BANK1_REGION3.erase_size,
40 ..BANK1_REGION3
41 };
42
43 pub const ALT_FLASH_REGIONS: [&FlashRegion; 6] = [
44 &BANK1_REGION1,
45 &BANK1_REGION2,
46 &ALT_BANK1_REGION3,
47 &ALT_BANK2_REGION1,
48 &ALT_BANK2_REGION2,
49 &ALT_BANK2_REGION3,
50 ];
51
52 pub struct AltBank1Region3<'d, MODE = Async>(pub &'static FlashRegion, Peri<'d, FLASH>, PhantomData<MODE>);
53 pub struct AltBank2Region1<'d, MODE = Async>(pub &'static FlashRegion, Peri<'d, FLASH>, PhantomData<MODE>);
54 pub struct AltBank2Region2<'d, MODE = Async>(pub &'static FlashRegion, Peri<'d, FLASH>, PhantomData<MODE>);
55 pub struct AltBank2Region3<'d, MODE = Async>(pub &'static FlashRegion, Peri<'d, FLASH>, PhantomData<MODE>);
56
57 pub struct AltFlashLayout<'d, MODE = Async> {
58 pub bank1_region1: Bank1Region1<'d, MODE>,
59 pub bank1_region2: Bank1Region2<'d, MODE>,
60 pub bank1_region3: AltBank1Region3<'d, MODE>,
61 pub bank2_region1: AltBank2Region1<'d, MODE>,
62 pub bank2_region2: AltBank2Region2<'d, MODE>,
63 pub bank2_region3: AltBank2Region3<'d, MODE>,
64 pub otp_region: OTPRegion<'d, MODE>,
65 }
66
67 impl<'d> Flash<'d> {
68 pub fn into_alt_regions(self) -> AltFlashLayout<'d, Async> {
69 assert!(!super::is_default_layout());
70
71 // SAFETY: We never expose the cloned peripheral references, and their instance is not public.
72 // Also, all async flash region operations are protected with a mutex.
73 let p = self.inner;
74 AltFlashLayout {
75 bank1_region1: Bank1Region1(&BANK1_REGION1, unsafe { p.clone_unchecked() }, PhantomData),
76 bank1_region2: Bank1Region2(&BANK1_REGION2, unsafe { p.clone_unchecked() }, PhantomData),
77 bank1_region3: AltBank1Region3(&ALT_BANK1_REGION3, unsafe { p.clone_unchecked() }, PhantomData),
78 bank2_region1: AltBank2Region1(&ALT_BANK2_REGION1, unsafe { p.clone_unchecked() }, PhantomData),
79 bank2_region2: AltBank2Region2(&ALT_BANK2_REGION2, unsafe { p.clone_unchecked() }, PhantomData),
80 bank2_region3: AltBank2Region3(&ALT_BANK2_REGION3, unsafe { p.clone_unchecked() }, PhantomData),
81 otp_region: OTPRegion(&OTP_REGION, unsafe { p.clone_unchecked() }, PhantomData),
82 }
83 }
84
85 pub fn into_alt_blocking_regions(self) -> AltFlashLayout<'d, Blocking> {
86 assert!(!super::is_default_layout());
87
88 // SAFETY: We never expose the cloned peripheral references, and their instance is not public.
89 // Also, all blocking flash region operations are protected with a cs.
90 let p = self.inner;
91 AltFlashLayout {
92 bank1_region1: Bank1Region1(&BANK1_REGION1, unsafe { p.clone_unchecked() }, PhantomData),
93 bank1_region2: Bank1Region2(&BANK1_REGION2, unsafe { p.clone_unchecked() }, PhantomData),
94 bank1_region3: AltBank1Region3(&ALT_BANK1_REGION3, unsafe { p.clone_unchecked() }, PhantomData),
95 bank2_region1: AltBank2Region1(&ALT_BANK2_REGION1, unsafe { p.clone_unchecked() }, PhantomData),
96 bank2_region2: AltBank2Region2(&ALT_BANK2_REGION2, unsafe { p.clone_unchecked() }, PhantomData),
97 bank2_region3: AltBank2Region3(&ALT_BANK2_REGION3, unsafe { p.clone_unchecked() }, PhantomData),
98 otp_region: OTPRegion(&OTP_REGION, unsafe { p.clone_unchecked() }, PhantomData),
99 }
100 }
101 }
102
103 macro_rules! foreach_altflash_region {
104 ($type_name:ident, $region:ident) => {
105 impl<MODE> $type_name<'_, MODE> {
106 pub fn blocking_read(&mut self, offset: u32, bytes: &mut [u8]) -> Result<(), Error> {
107 crate::flash::common::blocking_read(self.0.base, self.0.size, offset, bytes)
108 }
109 }
110
111 impl $type_name<'_, Async> {
112 pub async fn read(&mut self, offset: u32, bytes: &mut [u8]) -> Result<(), Error> {
113 self.blocking_read(offset, bytes)
114 }
115
116 pub async fn write(&mut self, offset: u32, bytes: &[u8]) -> Result<(), Error> {
117 let _guard = asynch::REGION_ACCESS.lock().await;
118 unsafe { asynch::write_chunked(self.0.base, self.0.size, offset, bytes).await }
119 }
120
121 pub async fn erase(&mut self, from: u32, to: u32) -> Result<(), Error> {
122 let _guard = asynch::REGION_ACCESS.lock().await;
123 unsafe { asynch::erase_sectored(self.0.base, from, to).await }
124 }
125 }
126
127 impl<MODE> embedded_storage::nor_flash::ErrorType for $type_name<'_, MODE> {
128 type Error = Error;
129 }
130
131 impl<MODE> embedded_storage::nor_flash::ReadNorFlash for $type_name<'_, MODE> {
132 const READ_SIZE: usize = crate::flash::READ_SIZE;
133
134 fn read(&mut self, offset: u32, bytes: &mut [u8]) -> Result<(), Self::Error> {
135 self.blocking_read(offset, bytes)
136 }
137
138 fn capacity(&self) -> usize {
139 self.0.size as usize
140 }
141 }
142
143 impl embedded_storage_async::nor_flash::ReadNorFlash for $type_name<'_, Async> {
144 const READ_SIZE: usize = crate::flash::READ_SIZE;
145
146 async fn read(&mut self, offset: u32, bytes: &mut [u8]) -> Result<(), Self::Error> {
147 self.read(offset, bytes).await
148 }
149
150 fn capacity(&self) -> usize {
151 self.0.size as usize
152 }
153 }
154
155 impl embedded_storage_async::nor_flash::NorFlash for $type_name<'_, Async> {
156 const WRITE_SIZE: usize = $region.write_size as usize;
157 const ERASE_SIZE: usize = $region.erase_size as usize;
158
159 async fn write(&mut self, offset: u32, bytes: &[u8]) -> Result<(), Self::Error> {
160 self.write(offset, bytes).await
161 }
162
163 async fn erase(&mut self, from: u32, to: u32) -> Result<(), Self::Error> {
164 self.erase(from, to).await
165 }
166 }
167 };
168 }
169
170 foreach_altflash_region!(AltBank1Region3, ALT_BANK1_REGION3);
171 foreach_altflash_region!(AltBank2Region1, ALT_BANK2_REGION1);
172 foreach_altflash_region!(AltBank2Region2, ALT_BANK2_REGION2);
173 foreach_altflash_region!(AltBank2Region3, ALT_BANK2_REGION3);
174}
175
176#[cfg(any(stm32f427, stm32f429, stm32f437, stm32f439, stm32f469, stm32f479))]
177pub use alt_regions::*;
178 11
179static WAKER: AtomicWaker = AtomicWaker::new(); 12static WAKER: AtomicWaker = AtomicWaker::new();
180static DATA_CACHE_WAS_ENABLED: AtomicBool = AtomicBool::new(false); 13static DATA_CACHE_WAS_ENABLED: AtomicBool = AtomicBool::new(false);
@@ -185,30 +18,6 @@ impl FlashSector {
185 } 18 }
186} 19}
187 20
188#[cfg(any(stm32f427, stm32f429, stm32f437, stm32f439, stm32f469, stm32f479))]
189pub(crate) fn is_default_layout() -> bool {
190 !pac::FLASH.optcr().read().db1m()
191}
192
193#[cfg(not(any(stm32f427, stm32f429, stm32f437, stm32f439, stm32f469, stm32f479)))]
194pub(crate) const fn is_default_layout() -> bool {
195 true
196}
197
198#[cfg(any(stm32f427, stm32f429, stm32f437, stm32f439, stm32f469, stm32f479))]
199pub fn get_flash_regions() -> &'static [&'static FlashRegion] {
200 if is_default_layout() {
201 &FLASH_REGIONS
202 } else {
203 &ALT_FLASH_REGIONS
204 }
205}
206
207#[cfg(not(any(stm32f427, stm32f429, stm32f437, stm32f439, stm32f469, stm32f479)))]
208pub const fn get_flash_regions() -> &'static [&'static FlashRegion] {
209 &FLASH_REGIONS
210}
211
212pub(crate) unsafe fn on_interrupt() { 21pub(crate) unsafe fn on_interrupt() {
213 // Clear IRQ flags 22 // Clear IRQ flags
214 pac::FLASH.sr().write(|w| { 23 pac::FLASH.sr().write(|w| {
@@ -487,71 +296,83 @@ mod tests {
487 const MEDIUM_SECTOR_SIZE: u32 = 64 * 1024; 296 const MEDIUM_SECTOR_SIZE: u32 = 64 * 1024;
488 const LARGE_SECTOR_SIZE: u32 = 128 * 1024; 297 const LARGE_SECTOR_SIZE: u32 = 128 * 1024;
489 298
490 let assert_sector = |snb: u8, index_in_bank: u8, start: u32, size: u32, address: u32| { 299 if !cfg!(feature = "dual-bank") {
491 let sector = get_sector(address, &FLASH_REGIONS); 300 let assert_sector = |snb: u8, index_in_bank: u8, start: u32, size: u32, address: u32| {
492 assert_eq!(snb, sector.snb()); 301 let sector = get_sector(address, crate::flash::get_flash_regions());
493 assert_eq!( 302 assert_eq!(snb, sector.snb());
494 FlashSector { 303 assert_eq!(
495 bank: FlashBank::Bank1, 304 FlashSector {
496 index_in_bank, 305 bank: sector.bank,
497 start, 306 index_in_bank,
498 size 307 start,
499 }, 308 size
500 sector 309 },
501 ); 310 sector
502 }; 311 );
503 312 };
504 assert_sector(0x00, 0, 0x0800_0000, SMALL_SECTOR_SIZE, 0x0800_0000); 313
505 assert_sector(0x00, 0, 0x0800_0000, SMALL_SECTOR_SIZE, 0x0800_3FFF); 314 assert_sector(0x00, 0, 0x0800_0000, SMALL_SECTOR_SIZE, 0x0800_0000);
506 assert_sector(0x03, 3, 0x0800_C000, SMALL_SECTOR_SIZE, 0x0800_C000); 315 assert_sector(0x00, 0, 0x0800_0000, SMALL_SECTOR_SIZE, 0x0800_3FFF);
507 assert_sector(0x03, 3, 0x0800_C000, SMALL_SECTOR_SIZE, 0x0800_FFFF); 316 assert_sector(0x03, 3, 0x0800_C000, SMALL_SECTOR_SIZE, 0x0800_C000);
508 317 assert_sector(0x03, 3, 0x0800_C000, SMALL_SECTOR_SIZE, 0x0800_FFFF);
509 assert_sector(0x04, 4, 0x0801_0000, MEDIUM_SECTOR_SIZE, 0x0801_0000); 318
510 assert_sector(0x04, 4, 0x0801_0000, MEDIUM_SECTOR_SIZE, 0x0801_FFFF); 319 assert_sector(0x04, 4, 0x0801_0000, MEDIUM_SECTOR_SIZE, 0x0801_0000);
511 320 assert_sector(0x04, 4, 0x0801_0000, MEDIUM_SECTOR_SIZE, 0x0801_FFFF);
512 assert_sector(0x05, 5, 0x0802_0000, LARGE_SECTOR_SIZE, 0x0802_0000); 321
513 assert_sector(0x05, 5, 0x0802_0000, LARGE_SECTOR_SIZE, 0x0803_FFFF); 322 assert_sector(0x05, 5, 0x0802_0000, LARGE_SECTOR_SIZE, 0x0802_0000);
514 assert_sector(0x0B, 11, 0x080E_0000, LARGE_SECTOR_SIZE, 0x080E_0000); 323 assert_sector(0x05, 5, 0x0802_0000, LARGE_SECTOR_SIZE, 0x0803_FFFF);
515 assert_sector(0x0B, 11, 0x080E_0000, LARGE_SECTOR_SIZE, 0x080F_FFFF); 324 assert_sector(0x0B, 11, 0x080E_0000, LARGE_SECTOR_SIZE, 0x080E_0000);
516 325 assert_sector(0x0B, 11, 0x080E_0000, LARGE_SECTOR_SIZE, 0x080F_FFFF);
517 let assert_sector = |snb: u8, bank: FlashBank, index_in_bank: u8, start: u32, size: u32, address: u32| { 326 } else {
518 let sector = get_sector(address, &ALT_FLASH_REGIONS); 327 let assert_sector = |snb: u8, bank: FlashBank, index_in_bank: u8, start: u32, size: u32, address: u32| {
519 assert_eq!(snb, sector.snb()); 328 let sector = get_sector(address, crate::flash::get_flash_regions());
520 assert_eq!( 329 assert_eq!(snb, sector.snb());
521 FlashSector { 330 assert_eq!(
522 bank, 331 FlashSector {
523 index_in_bank, 332 bank,
524 start, 333 index_in_bank,
525 size 334 start,
526 }, 335 size
527 sector 336 },
528 ) 337 sector
529 }; 338 )
530 339 };
531 assert_sector(0x00, FlashBank::Bank1, 0, 0x0800_0000, SMALL_SECTOR_SIZE, 0x0800_0000); 340
532 assert_sector(0x00, FlashBank::Bank1, 0, 0x0800_0000, SMALL_SECTOR_SIZE, 0x0800_3FFF); 341 assert_sector(0x00, FlashBank::Bank1, 0, 0x0800_0000, SMALL_SECTOR_SIZE, 0x0800_0000);
533 assert_sector(0x03, FlashBank::Bank1, 3, 0x0800_C000, SMALL_SECTOR_SIZE, 0x0800_C000); 342 assert_sector(0x00, FlashBank::Bank1, 0, 0x0800_0000, SMALL_SECTOR_SIZE, 0x0800_3FFF);
534 assert_sector(0x03, FlashBank::Bank1, 3, 0x0800_C000, SMALL_SECTOR_SIZE, 0x0800_FFFF); 343 assert_sector(0x03, FlashBank::Bank1, 3, 0x0800_C000, SMALL_SECTOR_SIZE, 0x0800_C000);
535 344 assert_sector(0x03, FlashBank::Bank1, 3, 0x0800_C000, SMALL_SECTOR_SIZE, 0x0800_FFFF);
536 assert_sector(0x04, FlashBank::Bank1, 4, 0x0801_0000, MEDIUM_SECTOR_SIZE, 0x0801_0000); 345
537 assert_sector(0x04, FlashBank::Bank1, 4, 0x0801_0000, MEDIUM_SECTOR_SIZE, 0x0801_FFFF); 346 assert_sector(0x04, FlashBank::Bank1, 4, 0x0801_0000, MEDIUM_SECTOR_SIZE, 0x0801_0000);
538 347 assert_sector(0x04, FlashBank::Bank1, 4, 0x0801_0000, MEDIUM_SECTOR_SIZE, 0x0801_FFFF);
539 assert_sector(0x05, FlashBank::Bank1, 5, 0x0802_0000, LARGE_SECTOR_SIZE, 0x0802_0000); 348
540 assert_sector(0x05, FlashBank::Bank1, 5, 0x0802_0000, LARGE_SECTOR_SIZE, 0x0803_FFFF); 349 assert_sector(0x05, FlashBank::Bank1, 5, 0x0802_0000, LARGE_SECTOR_SIZE, 0x0802_0000);
541 assert_sector(0x07, FlashBank::Bank1, 7, 0x0806_0000, LARGE_SECTOR_SIZE, 0x0806_0000); 350 assert_sector(0x05, FlashBank::Bank1, 5, 0x0802_0000, LARGE_SECTOR_SIZE, 0x0803_FFFF);
542 assert_sector(0x07, FlashBank::Bank1, 7, 0x0806_0000, LARGE_SECTOR_SIZE, 0x0807_FFFF); 351 assert_sector(0x07, FlashBank::Bank1, 7, 0x0806_0000, LARGE_SECTOR_SIZE, 0x0806_0000);
543 352 assert_sector(0x07, FlashBank::Bank1, 7, 0x0806_0000, LARGE_SECTOR_SIZE, 0x0807_FFFF);
544 assert_sector(0x10, FlashBank::Bank2, 0, 0x0808_0000, SMALL_SECTOR_SIZE, 0x0808_0000); 353
545 assert_sector(0x10, FlashBank::Bank2, 0, 0x0808_0000, SMALL_SECTOR_SIZE, 0x0808_3FFF); 354 assert_sector(0x10, FlashBank::Bank2, 0, 0x0808_0000, SMALL_SECTOR_SIZE, 0x0808_0000);
546 assert_sector(0x13, FlashBank::Bank2, 3, 0x0808_C000, SMALL_SECTOR_SIZE, 0x0808_C000); 355 assert_sector(0x10, FlashBank::Bank2, 0, 0x0808_0000, SMALL_SECTOR_SIZE, 0x0808_3FFF);
547 assert_sector(0x13, FlashBank::Bank2, 3, 0x0808_C000, SMALL_SECTOR_SIZE, 0x0808_FFFF); 356 assert_sector(0x13, FlashBank::Bank2, 3, 0x0808_C000, SMALL_SECTOR_SIZE, 0x0808_C000);
548 357 assert_sector(0x13, FlashBank::Bank2, 3, 0x0808_C000, SMALL_SECTOR_SIZE, 0x0808_FFFF);
549 assert_sector(0x14, FlashBank::Bank2, 4, 0x0809_0000, MEDIUM_SECTOR_SIZE, 0x0809_0000); 358
550 assert_sector(0x14, FlashBank::Bank2, 4, 0x0809_0000, MEDIUM_SECTOR_SIZE, 0x0809_FFFF); 359 assert_sector(0x14, FlashBank::Bank2, 4, 0x0809_0000, MEDIUM_SECTOR_SIZE, 0x0809_0000);
551 360 assert_sector(0x14, FlashBank::Bank2, 4, 0x0809_0000, MEDIUM_SECTOR_SIZE, 0x0809_FFFF);
552 assert_sector(0x15, FlashBank::Bank2, 5, 0x080A_0000, LARGE_SECTOR_SIZE, 0x080A_0000); 361
553 assert_sector(0x15, FlashBank::Bank2, 5, 0x080A_0000, LARGE_SECTOR_SIZE, 0x080B_FFFF); 362 assert_sector(0x15, FlashBank::Bank2, 5, 0x080A_0000, LARGE_SECTOR_SIZE, 0x080A_0000);
554 assert_sector(0x17, FlashBank::Bank2, 7, 0x080E_0000, LARGE_SECTOR_SIZE, 0x080E_0000); 363 assert_sector(0x15, FlashBank::Bank2, 5, 0x080A_0000, LARGE_SECTOR_SIZE, 0x080B_FFFF);
555 assert_sector(0x17, FlashBank::Bank2, 7, 0x080E_0000, LARGE_SECTOR_SIZE, 0x080F_FFFF); 364 assert_sector(0x17, FlashBank::Bank2, 7, 0x080E_0000, LARGE_SECTOR_SIZE, 0x080E_0000);
365 assert_sector(0x17, FlashBank::Bank2, 7, 0x080E_0000, LARGE_SECTOR_SIZE, 0x080F_FFFF);
366 }
367 }
368}
369
370#[cfg(all(bank_setup_configurable))]
371pub(crate) fn check_bank_setup() {
372 if cfg!(feature = "single-bank") && pac::FLASH.optcr().read().db1m() {
373 panic!("Embassy is configured as single-bank, but the hardware is running in dual-bank mode. Change the hardware by changing the db1m value in the user option bytes or configure embassy to use dual-bank config");
374 }
375 if cfg!(feature = "dual-bank") && !pac::FLASH.optcr().read().db1m() {
376 panic!("Embassy is configured as dual-bank, but the hardware is running in single-bank mode. Change the hardware by changing the db1m value in the user option bytes or configure embassy to use single-bank config");
556 } 377 }
557} 378}
diff --git a/embassy-stm32/src/flash/f7.rs b/embassy-stm32/src/flash/f7.rs
index 09ebe9db9..0547c747a 100644
--- a/embassy-stm32/src/flash/f7.rs
+++ b/embassy-stm32/src/flash/f7.rs
@@ -1,16 +1,14 @@
1use core::ptr::write_volatile; 1use core::ptr::write_volatile;
2use core::sync::atomic::{fence, Ordering}; 2use core::sync::atomic::{fence, Ordering};
3 3
4use super::{FlashRegion, FlashSector, FLASH_REGIONS, WRITE_SIZE}; 4use super::{FlashSector, WRITE_SIZE};
5use crate::flash::Error; 5use crate::flash::Error;
6use crate::pac; 6use crate::pac;
7 7
8pub(crate) const fn is_default_layout() -> bool { 8impl FlashSector {
9 true 9 const fn snb(&self) -> u8 {
10} 10 ((self.bank as u8) << 4) + self.index_in_bank
11 11 }
12pub(crate) const fn get_flash_regions() -> &'static [&'static FlashRegion] {
13 &FLASH_REGIONS
14} 12}
15 13
16pub(crate) unsafe fn lock() { 14pub(crate) unsafe fn lock() {
@@ -53,7 +51,7 @@ pub(crate) unsafe fn blocking_write(start_address: u32, buf: &[u8; WRITE_SIZE])
53pub(crate) unsafe fn blocking_erase_sector(sector: &FlashSector) -> Result<(), Error> { 51pub(crate) unsafe fn blocking_erase_sector(sector: &FlashSector) -> Result<(), Error> {
54 pac::FLASH.cr().modify(|w| { 52 pac::FLASH.cr().modify(|w| {
55 w.set_ser(true); 53 w.set_ser(true);
56 w.set_snb(sector.index_in_bank) 54 w.set_snb(sector.snb())
57 }); 55 });
58 56
59 pac::FLASH.cr().modify(|w| { 57 pac::FLASH.cr().modify(|w| {
@@ -118,7 +116,7 @@ mod tests {
118 start, 116 start,
119 size 117 size
120 }, 118 },
121 get_sector(address, &FLASH_REGIONS) 119 get_sector(address, crate::flash::get_flash_regions())
122 ) 120 )
123 }; 121 };
124 122
@@ -137,7 +135,7 @@ mod tests {
137 } 135 }
138 136
139 #[test] 137 #[test]
140 #[cfg(stm32f769)] 138 #[cfg(all(stm32f769, feature = "single-bank"))]
141 fn can_get_sector() { 139 fn can_get_sector() {
142 const SMALL_SECTOR_SIZE: u32 = 32 * 1024; 140 const SMALL_SECTOR_SIZE: u32 = 32 * 1024;
143 const MEDIUM_SECTOR_SIZE: u32 = 128 * 1024; 141 const MEDIUM_SECTOR_SIZE: u32 = 128 * 1024;
@@ -151,7 +149,7 @@ mod tests {
151 start, 149 start,
152 size 150 size
153 }, 151 },
154 get_sector(address, &FLASH_REGIONS) 152 get_sector(address, crate::flash::get_flash_regions())
155 ) 153 )
156 }; 154 };
157 155
@@ -168,4 +166,61 @@ mod tests {
168 assert_sector(7, 0x080C_0000, LARGE_SECTOR_SIZE, 0x080C_0000); 166 assert_sector(7, 0x080C_0000, LARGE_SECTOR_SIZE, 0x080C_0000);
169 assert_sector(7, 0x080C_0000, LARGE_SECTOR_SIZE, 0x080F_FFFF); 167 assert_sector(7, 0x080C_0000, LARGE_SECTOR_SIZE, 0x080F_FFFF);
170 } 168 }
169
170 #[test]
171 #[cfg(all(stm32f769, feature = "dual-bank"))]
172 fn can_get_sector() {
173 const SMALL_SECTOR_SIZE: u32 = 16 * 1024;
174 const MEDIUM_SECTOR_SIZE: u32 = 64 * 1024;
175 const LARGE_SECTOR_SIZE: u32 = 128 * 1024;
176
177 let assert_sector = |index_in_bank: u8, start: u32, size: u32, address: u32, snb: u8, bank: FlashBank| {
178 assert_eq!(
179 FlashSector {
180 bank: bank,
181 index_in_bank,
182 start,
183 size
184 },
185 get_sector(address, crate::flash::get_flash_regions())
186 );
187 assert_eq!(get_sector(address, crate::flash::get_flash_regions()).snb(), snb);
188 };
189
190 assert_sector(0, 0x0800_0000, SMALL_SECTOR_SIZE, 0x0800_0000, 0x00, FlashBank::Bank1);
191 assert_sector(0, 0x0800_0000, SMALL_SECTOR_SIZE, 0x0800_3FFF, 0x00, FlashBank::Bank1);
192 assert_sector(3, 0x0800_C000, SMALL_SECTOR_SIZE, 0x0800_C000, 0x03, FlashBank::Bank1);
193 assert_sector(3, 0x0800_C000, SMALL_SECTOR_SIZE, 0x0800_FFFF, 0x03, FlashBank::Bank1);
194
195 assert_sector(4, 0x0801_0000, MEDIUM_SECTOR_SIZE, 0x0801_0000, 0x04, FlashBank::Bank1);
196 assert_sector(4, 0x0801_0000, MEDIUM_SECTOR_SIZE, 0x0801_FFFF, 0x04, FlashBank::Bank1);
197
198 assert_sector(5, 0x0802_0000, LARGE_SECTOR_SIZE, 0x0802_0000, 0x05, FlashBank::Bank1);
199 assert_sector(5, 0x0802_0000, LARGE_SECTOR_SIZE, 0x0803_FFFF, 0x05, FlashBank::Bank1);
200 assert_sector(10, 0x080C_0000, LARGE_SECTOR_SIZE, 0x080C_0000, 0x0A, FlashBank::Bank1);
201 assert_sector(10, 0x080C_0000, LARGE_SECTOR_SIZE, 0x080D_FFFF, 0x0A, FlashBank::Bank1);
202
203 assert_sector(0, 0x0810_0000, SMALL_SECTOR_SIZE, 0x0810_0000, 0x10, FlashBank::Bank2);
204 assert_sector(0, 0x0810_0000, SMALL_SECTOR_SIZE, 0x0810_3FFF, 0x10, FlashBank::Bank2);
205 assert_sector(3, 0x0810_C000, SMALL_SECTOR_SIZE, 0x0810_C000, 0x13, FlashBank::Bank2);
206 assert_sector(3, 0x0810_C000, SMALL_SECTOR_SIZE, 0x0810_FFFF, 0x13, FlashBank::Bank2);
207
208 assert_sector(4, 0x0811_0000, MEDIUM_SECTOR_SIZE, 0x0811_0000, 0x14, FlashBank::Bank2);
209 assert_sector(4, 0x0811_0000, MEDIUM_SECTOR_SIZE, 0x0811_FFFF, 0x14, FlashBank::Bank2);
210
211 assert_sector(5, 0x0812_0000, LARGE_SECTOR_SIZE, 0x0812_0000, 0x15, FlashBank::Bank2);
212 assert_sector(5, 0x0812_0000, LARGE_SECTOR_SIZE, 0x0813_FFFF, 0x15, FlashBank::Bank2);
213 assert_sector(10, 0x081C_0000, LARGE_SECTOR_SIZE, 0x081C_0000, 0x1A, FlashBank::Bank2);
214 assert_sector(10, 0x081C_0000, LARGE_SECTOR_SIZE, 0x081D_FFFF, 0x1A, FlashBank::Bank2);
215 }
216}
217
218#[cfg(all(bank_setup_configurable))]
219pub(crate) fn check_bank_setup() {
220 if cfg!(feature = "single-bank") && !pac::FLASH.optcr().read().n_dbank() {
221 panic!("Embassy is configured as single-bank, but the hardware is running in dual-bank mode. Change the hardware by changing the ndbank value in the user option bytes or configure embassy to use dual-bank config");
222 }
223 if cfg!(feature = "dual-bank") && pac::FLASH.optcr().read().n_dbank() {
224 panic!("Embassy is configured as dual-bank, but the hardware is running in single-bank mode. Change the hardware by changing the ndbank value in the user option bytes or configure embassy to use single-bank config");
225 }
171} 226}
diff --git a/embassy-stm32/src/flash/g.rs b/embassy-stm32/src/flash/g.rs
index 83663743c..bc1fd360c 100644
--- a/embassy-stm32/src/flash/g.rs
+++ b/embassy-stm32/src/flash/g.rs
@@ -3,18 +3,10 @@ use core::sync::atomic::{fence, Ordering};
3 3
4use cortex_m::interrupt; 4use cortex_m::interrupt;
5 5
6use super::{FlashRegion, FlashSector, FLASH_REGIONS, WRITE_SIZE}; 6use super::{FlashSector, WRITE_SIZE};
7use crate::flash::Error; 7use crate::flash::Error;
8use crate::pac; 8use crate::pac;
9 9
10pub(crate) const fn is_default_layout() -> bool {
11 true
12}
13
14pub(crate) const fn get_flash_regions() -> &'static [&'static FlashRegion] {
15 &FLASH_REGIONS
16}
17
18pub(crate) unsafe fn lock() { 10pub(crate) unsafe fn lock() {
19 pac::FLASH.cr().modify(|w| w.set_lock(true)); 11 pac::FLASH.cr().modify(|w| w.set_lock(true));
20} 12}
@@ -109,3 +101,23 @@ fn wait_busy() {
109fn wait_busy() { 101fn wait_busy() {
110 while pac::FLASH.sr().read().bsy() {} 102 while pac::FLASH.sr().read().bsy() {}
111} 103}
104
105#[cfg(all(bank_setup_configurable, any(flash_g4c2, flash_g4c3, flash_g4c4)))]
106pub(crate) fn check_bank_setup() {
107 if cfg!(feature = "single-bank") && pac::FLASH.optr().read().dbank() {
108 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");
109 }
110 if cfg!(feature = "dual-bank") && !pac::FLASH.optr().read().dbank() {
111 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");
112 }
113}
114
115#[cfg(all(bank_setup_configurable, flash_g0x1))]
116pub(crate) fn check_bank_setup() {
117 if cfg!(feature = "single-bank") && pac::FLASH.optr().read().dual_bank() {
118 panic!("Embassy is configured as single-bank, but the hardware is running in dual-bank mode. Change the hardware by changing the dual_bank value in the user option bytes or configure embassy to use dual-bank config");
119 }
120 if cfg!(feature = "dual-bank") && !pac::FLASH.optr().read().dual_bank() {
121 panic!("Embassy is configured as dual-bank, but the hardware is running in single-bank mode. Change the hardware by changing the dual_bank value in the user option bytes or configure embassy to use single-bank config");
122 }
123}
diff --git a/embassy-stm32/src/flash/h5.rs b/embassy-stm32/src/flash/h5.rs
index d95de2e38..fd9bfcc75 100644
--- a/embassy-stm32/src/flash/h5.rs
+++ b/embassy-stm32/src/flash/h5.rs
@@ -1,22 +1,10 @@
1use core::ptr::write_volatile; 1use core::ptr::write_volatile;
2use core::sync::atomic::{fence, Ordering}; 2use core::sync::atomic::{fence, Ordering};
3 3
4use super::{FlashRegion, FlashSector, FLASH_REGIONS, WRITE_SIZE}; 4use super::{FlashSector, WRITE_SIZE};
5use crate::flash::Error; 5use crate::flash::Error;
6use crate::pac; 6use crate::pac;
7 7
8pub(crate) const fn is_default_layout() -> bool {
9 true
10}
11
12// const fn is_dual_bank() -> bool {
13// FLASH_REGIONS.len() >= 2
14// }
15
16pub(crate) fn get_flash_regions() -> &'static [&'static FlashRegion] {
17 &FLASH_REGIONS
18}
19
20pub(crate) unsafe fn lock() { 8pub(crate) unsafe fn lock() {
21 if !pac::FLASH.nscr().read().lock() { 9 if !pac::FLASH.nscr().read().lock() {
22 pac::FLASH.nscr().modify(|r| { 10 pac::FLASH.nscr().modify(|r| {
diff --git a/embassy-stm32/src/flash/h50.rs b/embassy-stm32/src/flash/h50.rs
index 74cd6cc03..f8e210556 100644
--- a/embassy-stm32/src/flash/h50.rs
+++ b/embassy-stm32/src/flash/h50.rs
@@ -8,17 +8,9 @@ use cortex_m::interrupt;
8use pac::flash::regs::Nssr; 8use pac::flash::regs::Nssr;
9use pac::flash::vals::Bksel; 9use pac::flash::vals::Bksel;
10 10
11use super::{Error, FlashBank, FlashRegion, FlashSector, FLASH_REGIONS, WRITE_SIZE}; 11use super::{Error, FlashBank, FlashSector, WRITE_SIZE};
12use crate::pac; 12use crate::pac;
13 13
14pub(crate) const fn is_default_layout() -> bool {
15 true
16}
17
18pub(crate) const fn get_flash_regions() -> &'static [&'static FlashRegion] {
19 &FLASH_REGIONS
20}
21
22pub(crate) unsafe fn lock() { 14pub(crate) unsafe fn lock() {
23 pac::FLASH.nscr().modify(|w| w.set_lock(true)); 15 pac::FLASH.nscr().modify(|w| w.set_lock(true));
24} 16}
diff --git a/embassy-stm32/src/flash/h7.rs b/embassy-stm32/src/flash/h7.rs
index 254915381..f1d84101c 100644
--- a/embassy-stm32/src/flash/h7.rs
+++ b/embassy-stm32/src/flash/h7.rs
@@ -1,22 +1,14 @@
1use core::ptr::write_volatile; 1use core::ptr::write_volatile;
2use core::sync::atomic::{fence, Ordering}; 2use core::sync::atomic::{fence, Ordering};
3 3
4use super::{FlashRegion, FlashSector, BANK1_REGION, FLASH_REGIONS, WRITE_SIZE}; 4use super::{FlashSector, BANK1_REGION, FLASH_REGIONS, WRITE_SIZE};
5use crate::flash::Error; 5use crate::flash::Error;
6use crate::pac; 6use crate::pac;
7 7
8pub(crate) const fn is_default_layout() -> bool {
9 true
10}
11
12const fn is_dual_bank() -> bool { 8const fn is_dual_bank() -> bool {
13 FLASH_REGIONS.len() >= 2 9 FLASH_REGIONS.len() >= 2
14} 10}
15 11
16pub(crate) fn get_flash_regions() -> &'static [&'static FlashRegion] {
17 &FLASH_REGIONS
18}
19
20pub(crate) unsafe fn lock() { 12pub(crate) unsafe fn lock() {
21 pac::FLASH.bank(0).cr().modify(|w| w.set_lock(true)); 13 pac::FLASH.bank(0).cr().modify(|w| w.set_lock(true));
22 if is_dual_bank() { 14 if is_dual_bank() {
diff --git a/embassy-stm32/src/flash/l.rs b/embassy-stm32/src/flash/l.rs
index ea00bf499..65cea005c 100644
--- a/embassy-stm32/src/flash/l.rs
+++ b/embassy-stm32/src/flash/l.rs
@@ -1,18 +1,10 @@
1use core::ptr::write_volatile; 1use core::ptr::write_volatile;
2use core::sync::atomic::{fence, Ordering}; 2use core::sync::atomic::{fence, Ordering};
3 3
4use super::{FlashRegion, FlashSector, FLASH_REGIONS, WRITE_SIZE}; 4use super::{FlashSector, WRITE_SIZE};
5use crate::flash::Error; 5use crate::flash::Error;
6use crate::pac; 6use crate::pac;
7 7
8pub(crate) const fn is_default_layout() -> bool {
9 true
10}
11
12pub(crate) const fn get_flash_regions() -> &'static [&'static FlashRegion] {
13 &FLASH_REGIONS
14}
15
16pub(crate) unsafe fn lock() { 8pub(crate) unsafe fn lock() {
17 #[cfg(any(flash_wl, flash_wb, flash_l4))] 9 #[cfg(any(flash_wl, flash_wb, flash_l4))]
18 pac::FLASH.cr().modify(|w| w.set_lock(true)); 10 pac::FLASH.cr().modify(|w| w.set_lock(true));
@@ -238,3 +230,23 @@ unsafe fn wait_ready_blocking() -> Result<(), Error> {
238 } 230 }
239 } 231 }
240} 232}
233
234#[cfg(all(bank_setup_configurable, flash_l5))]
235pub(crate) fn check_bank_setup() {
236 if cfg!(feature = "single-bank") && pac::FLASH.optr().read().dbank() {
237 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");
238 }
239 if cfg!(feature = "dual-bank") && !pac::FLASH.optr().read().dbank() {
240 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");
241 }
242}
243
244#[cfg(all(bank_setup_configurable, flash_l4))]
245pub(crate) fn check_bank_setup() {
246 if cfg!(feature = "single-bank") && pac::FLASH.optr().read().dualbank() {
247 panic!("Embassy is configured as single-bank, but the hardware is running in dual-bank mode. Change the hardware by changing the dualbank value in the user option bytes or configure embassy to use dual-bank config");
248 }
249 if cfg!(feature = "dual-bank") && !pac::FLASH.optr().read().dualbank() {
250 panic!("Embassy is configured as dual-bank, but the hardware is running in single-bank mode. Change the hardware by changing the dualbank value in the user option bytes or configure embassy to use single-bank config");
251 }
252}
diff --git a/embassy-stm32/src/flash/mod.rs b/embassy-stm32/src/flash/mod.rs
index c7488c8ef..adc45db9c 100644
--- a/embassy-stm32/src/flash/mod.rs
+++ b/embassy-stm32/src/flash/mod.rs
@@ -14,17 +14,9 @@ pub use common::*;
14pub use crate::_generated::flash_regions::*; 14pub use crate::_generated::flash_regions::*;
15pub use crate::_generated::{FLASH_BASE, FLASH_SIZE, MAX_ERASE_SIZE, WRITE_SIZE}; 15pub use crate::_generated::{FLASH_BASE, FLASH_SIZE, MAX_ERASE_SIZE, WRITE_SIZE};
16 16
17/// Get whether the default flash layout is being used.
18///
19/// In some chips, dual-bank is not default. This will then return `false`
20/// when dual-bank is enabled.
21pub fn is_default_layout() -> bool {
22 family::is_default_layout()
23}
24
25/// Get all flash regions. 17/// Get all flash regions.
26pub fn get_flash_regions() -> &'static [&'static FlashRegion] { 18pub fn get_flash_regions() -> &'static [&'static FlashRegion] {
27 family::get_flash_regions() 19 &FLASH_REGIONS
28} 20}
29 21
30/// Read size (always 1) 22/// Read size (always 1)
diff --git a/embassy-stm32/src/flash/other.rs b/embassy-stm32/src/flash/other.rs
index 20f84a72f..293a79be3 100644
--- a/embassy-stm32/src/flash/other.rs
+++ b/embassy-stm32/src/flash/other.rs
@@ -1,14 +1,6 @@
1#![allow(unused)] 1#![allow(unused)]
2 2
3use super::{Error, FlashRegion, FlashSector, FLASH_REGIONS, WRITE_SIZE}; 3use super::{Error, FlashSector, WRITE_SIZE};
4
5pub(crate) const fn is_default_layout() -> bool {
6 true
7}
8
9pub(crate) const fn get_flash_regions() -> &'static [&'static FlashRegion] {
10 &FLASH_REGIONS
11}
12 4
13pub(crate) unsafe fn lock() { 5pub(crate) unsafe fn lock() {
14 unimplemented!(); 6 unimplemented!();
diff --git a/embassy-stm32/src/flash/u0.rs b/embassy-stm32/src/flash/u0.rs
index bfdbd15a5..68d847eca 100644
--- a/embassy-stm32/src/flash/u0.rs
+++ b/embassy-stm32/src/flash/u0.rs
@@ -3,18 +3,10 @@ use core::sync::atomic::{fence, Ordering};
3 3
4use cortex_m::interrupt; 4use cortex_m::interrupt;
5 5
6use super::{FlashRegion, FlashSector, FLASH_REGIONS, WRITE_SIZE}; 6use super::{FlashSector, WRITE_SIZE};
7use crate::flash::Error; 7use crate::flash::Error;
8use crate::pac; 8use crate::pac;
9 9
10pub(crate) const fn is_default_layout() -> bool {
11 true
12}
13
14pub(crate) const fn get_flash_regions() -> &'static [&'static FlashRegion] {
15 &FLASH_REGIONS
16}
17
18pub(crate) unsafe fn lock() { 10pub(crate) unsafe fn lock() {
19 pac::FLASH.cr().modify(|w| w.set_lock(true)); 11 pac::FLASH.cr().modify(|w| w.set_lock(true));
20} 12}
diff --git a/embassy-stm32/src/flash/u5.rs b/embassy-stm32/src/flash/u5.rs
index dad698316..131caa195 100644
--- a/embassy-stm32/src/flash/u5.rs
+++ b/embassy-stm32/src/flash/u5.rs
@@ -1,18 +1,10 @@
1use core::ptr::write_volatile; 1use core::ptr::write_volatile;
2use core::sync::atomic::{fence, Ordering}; 2use core::sync::atomic::{fence, Ordering};
3 3
4use super::{FlashBank, FlashRegion, FlashSector, FLASH_REGIONS, WRITE_SIZE}; 4use super::{FlashBank, FlashSector, WRITE_SIZE};
5use crate::flash::Error; 5use crate::flash::Error;
6use crate::pac; 6use crate::pac;
7 7
8pub(crate) const fn is_default_layout() -> bool {
9 true
10}
11
12pub(crate) const fn get_flash_regions() -> &'static [&'static FlashRegion] {
13 &FLASH_REGIONS
14}
15
16pub(crate) unsafe fn lock() { 8pub(crate) unsafe fn lock() {
17 #[cfg(feature = "trustzone-secure")] 9 #[cfg(feature = "trustzone-secure")]
18 pac::FLASH.seccr().modify(|w| w.set_lock(true)); 10 pac::FLASH.seccr().modify(|w| w.set_lock(true));
diff --git a/examples/boot/application/stm32f7/Cargo.toml b/examples/boot/application/stm32f7/Cargo.toml
index 6a5a500de..d62c67742 100644
--- a/examples/boot/application/stm32f7/Cargo.toml
+++ b/examples/boot/application/stm32f7/Cargo.toml
@@ -8,7 +8,7 @@ license = "MIT OR Apache-2.0"
8embassy-sync = { version = "0.6.2", path = "../../../../embassy-sync" } 8embassy-sync = { version = "0.6.2", path = "../../../../embassy-sync" }
9embassy-executor = { version = "0.7.0", path = "../../../../embassy-executor", features = ["arch-cortex-m", "executor-thread"] } 9embassy-executor = { version = "0.7.0", path = "../../../../embassy-executor", features = ["arch-cortex-m", "executor-thread"] }
10embassy-time = { version = "0.4.0", path = "../../../../embassy-time", features = [ "tick-hz-32_768"] } 10embassy-time = { version = "0.4.0", path = "../../../../embassy-time", features = [ "tick-hz-32_768"] }
11embassy-stm32 = { version = "0.2.0", path = "../../../../embassy-stm32", features = ["stm32f767zi", "time-driver-any", "exti"] } 11embassy-stm32 = { version = "0.2.0", path = "../../../../embassy-stm32", features = ["stm32f767zi", "time-driver-any", "exti", "single-bank"] }
12embassy-boot-stm32 = { version = "0.2.0", path = "../../../../embassy-boot-stm32", features = [] } 12embassy-boot-stm32 = { version = "0.2.0", path = "../../../../embassy-boot-stm32", features = [] }
13embassy-embedded-hal = { version = "0.3.0", path = "../../../../embassy-embedded-hal" } 13embassy-embedded-hal = { version = "0.3.0", path = "../../../../embassy-embedded-hal" }
14 14
diff --git a/examples/stm32f7/Cargo.toml b/examples/stm32f7/Cargo.toml
index 9fbe2efc3..1a46931d9 100644
--- a/examples/stm32f7/Cargo.toml
+++ b/examples/stm32f7/Cargo.toml
@@ -6,7 +6,7 @@ license = "MIT OR Apache-2.0"
6 6
7[dependencies] 7[dependencies]
8# Change stm32f777zi to your chip name, if necessary. 8# Change stm32f777zi to your chip name, if necessary.
9embassy-stm32 = { version = "0.2.0", path = "../../embassy-stm32", features = ["defmt", "stm32f777zi", "memory-x", "unstable-pac", "time-driver-any", "exti"] } 9embassy-stm32 = { version = "0.2.0", path = "../../embassy-stm32", features = ["defmt", "stm32f777zi", "memory-x", "unstable-pac", "time-driver-any", "exti", "single-bank"] }
10embassy-sync = { version = "0.6.2", path = "../../embassy-sync", features = ["defmt"] } 10embassy-sync = { version = "0.6.2", path = "../../embassy-sync", features = ["defmt"] }
11embassy-executor = { version = "0.7.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt"] } 11embassy-executor = { version = "0.7.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt"] }
12embassy-time = { version = "0.4.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } 12embassy-time = { version = "0.4.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
diff --git a/examples/stm32l4/Cargo.toml b/examples/stm32l4/Cargo.toml
index b609110af..239bfcd79 100644
--- a/examples/stm32l4/Cargo.toml
+++ b/examples/stm32l4/Cargo.toml
@@ -6,7 +6,7 @@ license = "MIT OR Apache-2.0"
6 6
7[dependencies] 7[dependencies]
8# Change stm32l4s5vi to your chip name, if necessary. 8# Change stm32l4s5vi to your chip name, if necessary.
9embassy-stm32 = { version = "0.2.0", path = "../../embassy-stm32", features = [ "defmt", "unstable-pac", "stm32l4r5zi", "memory-x", "time-driver-any", "exti", "chrono"] } 9embassy-stm32 = { version = "0.2.0", path = "../../embassy-stm32", features = [ "defmt", "unstable-pac", "stm32l4r5zi", "memory-x", "time-driver-any", "exti", "chrono", "dual-bank"] }
10embassy-sync = { version = "0.6.2", path = "../../embassy-sync", features = ["defmt"] } 10embassy-sync = { version = "0.6.2", path = "../../embassy-sync", features = ["defmt"] }
11embassy-executor = { version = "0.7.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt"] } 11embassy-executor = { version = "0.7.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt"] }
12embassy-time = { version = "0.4.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768", ] } 12embassy-time = { version = "0.4.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768", ] }
diff --git a/examples/stm32l5/Cargo.toml b/examples/stm32l5/Cargo.toml
index fbf68c890..4c372a554 100644
--- a/examples/stm32l5/Cargo.toml
+++ b/examples/stm32l5/Cargo.toml
@@ -6,7 +6,7 @@ license = "MIT OR Apache-2.0"
6 6
7[dependencies] 7[dependencies]
8# Change stm32l552ze to your chip name, if necessary. 8# Change stm32l552ze to your chip name, if necessary.
9embassy-stm32 = { version = "0.2.0", path = "../../embassy-stm32", features = [ "defmt", "unstable-pac", "stm32l552ze", "time-driver-any", "exti", "memory-x", "low-power"] } 9embassy-stm32 = { version = "0.2.0", path = "../../embassy-stm32", features = [ "defmt", "unstable-pac", "stm32l552ze", "time-driver-any", "exti", "memory-x", "low-power", "dual-bank"] }
10embassy-sync = { version = "0.6.2", path = "../../embassy-sync", features = ["defmt"] } 10embassy-sync = { version = "0.6.2", path = "../../embassy-sync", features = ["defmt"] }
11embassy-executor = { version = "0.7.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt"] } 11embassy-executor = { version = "0.7.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt"] }
12embassy-time = { version = "0.4.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } 12embassy-time = { version = "0.4.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
diff --git a/tests/stm32/Cargo.toml b/tests/stm32/Cargo.toml
index a676aee53..3a347e279 100644
--- a/tests/stm32/Cargo.toml
+++ b/tests/stm32/Cargo.toml
@@ -12,7 +12,7 @@ stm32f207zg = ["embassy-stm32/stm32f207zg", "spi-v1", "chrono", "not-gpdma", "et
12stm32f303ze = ["embassy-stm32/stm32f303ze", "chrono", "not-gpdma"] 12stm32f303ze = ["embassy-stm32/stm32f303ze", "chrono", "not-gpdma"]
13stm32f429zi = ["embassy-stm32/stm32f429zi", "spi-v1", "chrono", "eth", "stop", "can", "not-gpdma", "dac", "rng"] 13stm32f429zi = ["embassy-stm32/stm32f429zi", "spi-v1", "chrono", "eth", "stop", "can", "not-gpdma", "dac", "rng"]
14stm32f446re = ["embassy-stm32/stm32f446re", "spi-v1", "chrono", "stop", "can", "not-gpdma", "dac", "sdmmc"] 14stm32f446re = ["embassy-stm32/stm32f446re", "spi-v1", "chrono", "stop", "can", "not-gpdma", "dac", "sdmmc"]
15stm32f767zi = ["embassy-stm32/stm32f767zi", "chrono", "not-gpdma", "eth", "rng"] 15stm32f767zi = ["embassy-stm32/stm32f767zi", "chrono", "not-gpdma", "eth", "rng", "single-bank"]
16stm32g071rb = ["embassy-stm32/stm32g071rb", "cm0", "not-gpdma", "dac", "ucpd"] 16stm32g071rb = ["embassy-stm32/stm32g071rb", "cm0", "not-gpdma", "dac", "ucpd"]
17stm32g491re = ["embassy-stm32/stm32g491re", "chrono", "stop", "not-gpdma", "rng", "fdcan", "cordic"] 17stm32g491re = ["embassy-stm32/stm32g491re", "chrono", "stop", "not-gpdma", "rng", "fdcan", "cordic"]
18stm32h563zi = ["embassy-stm32/stm32h563zi", "spi-v345", "chrono", "eth", "rng", "fdcan", "hash", "cordic", "stop"] 18stm32h563zi = ["embassy-stm32/stm32h563zi", "spi-v345", "chrono", "eth", "rng", "fdcan", "hash", "cordic", "stop"]
@@ -23,8 +23,8 @@ stm32l073rz = ["embassy-stm32/stm32l073rz", "cm0", "not-gpdma", "rng"]
23stm32l152re = ["embassy-stm32/stm32l152re", "spi-v1", "chrono", "not-gpdma"] 23stm32l152re = ["embassy-stm32/stm32l152re", "spi-v1", "chrono", "not-gpdma"]
24stm32l496zg = ["embassy-stm32/stm32l496zg", "not-gpdma", "rng"] 24stm32l496zg = ["embassy-stm32/stm32l496zg", "not-gpdma", "rng"]
25stm32l4a6zg = ["embassy-stm32/stm32l4a6zg", "chrono", "not-gpdma", "rng", "hash"] 25stm32l4a6zg = ["embassy-stm32/stm32l4a6zg", "chrono", "not-gpdma", "rng", "hash"]
26stm32l4r5zi = ["embassy-stm32/stm32l4r5zi", "chrono", "not-gpdma", "rng"] 26stm32l4r5zi = ["embassy-stm32/stm32l4r5zi", "chrono", "not-gpdma", "rng", "dual-bank"]
27stm32l552ze = ["embassy-stm32/stm32l552ze", "not-gpdma", "rng", "hash"] 27stm32l552ze = ["embassy-stm32/stm32l552ze", "not-gpdma", "rng", "hash", "dual-bank"]
28stm32u585ai = ["embassy-stm32/stm32u585ai", "spi-v345", "chrono", "rng", "hash", "cordic"] 28stm32u585ai = ["embassy-stm32/stm32u585ai", "spi-v345", "chrono", "rng", "hash", "cordic"]
29stm32u5a5zj = ["embassy-stm32/stm32u5a5zj", "spi-v345", "chrono", "rng", "hash"] # FIXME: cordic test cause it crash 29stm32u5a5zj = ["embassy-stm32/stm32u5a5zj", "spi-v345", "chrono", "rng", "hash"] # FIXME: cordic test cause it crash
30stm32wb55rg = ["embassy-stm32/stm32wb55rg", "chrono", "not-gpdma", "ble", "mac" , "rng"] 30stm32wb55rg = ["embassy-stm32/stm32wb55rg", "chrono", "not-gpdma", "ble", "mac" , "rng"]
@@ -53,6 +53,8 @@ not-gpdma = []
53dac = [] 53dac = []
54ucpd = [] 54ucpd = []
55cordic = ["dep:num-traits"] 55cordic = ["dep:num-traits"]
56dual-bank = ["embassy-stm32/dual-bank"]
57single-bank = ["embassy-stm32/single-bank"]
56 58
57cm0 = ["portable-atomic/unsafe-assume-single-core"] 59cm0 = ["portable-atomic/unsafe-assume-single-core"]
58 60