aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--embassy-stm32/Cargo.toml131
-rw-r--r--embassy-stm32/build.rs137
-rw-r--r--embassy-stm32/src/exti.rs9
-rw-r--r--embassy-stm32/src/flash/common.rs2
-rw-r--r--embassy-stm32/src/flash/f4.rs4
-rw-r--r--embassy-stm32/src/flash/mod.rs3
-rw-r--r--embassy-stm32/src/gpio.rs6
7 files changed, 216 insertions, 76 deletions
diff --git a/embassy-stm32/Cargo.toml b/embassy-stm32/Cargo.toml
index 30ea143c0..d66d3bc1d 100644
--- a/embassy-stm32/Cargo.toml
+++ b/embassy-stm32/Cargo.toml
@@ -73,7 +73,7 @@ rand_core = "0.6.3"
73sdio-host = "0.5.0" 73sdio-host = "0.5.0"
74critical-section = "1.1" 74critical-section = "1.1"
75#stm32-metapac = { version = "15" } 75#stm32-metapac = { version = "15" }
76stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-274eeb0ed4477768d026276c4e9873586c1b9a05" } 76stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-fad4bc0f2baac29ecebb5153d2997b649b71025f" }
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 = "15", default-features = false, features = ["metadata"]} 104#stm32-metapac = { version = "15", default-features = false, features = ["metadata"]}
105stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-274eeb0ed4477768d026276c4e9873586c1b9a05", default-features = false, features = ["metadata"] } 105stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-fad4bc0f2baac29ecebb5153d2997b649b71025f", default-features = false, features = ["metadata"] }
106 106
107[features] 107[features]
108default = ["rt"] 108default = ["rt"]
@@ -127,8 +127,8 @@ exti = []
127low-power = [ "dep:embassy-executor", "embassy-executor?/arch-cortex-m", "time" ] 127low-power = [ "dep:embassy-executor", "embassy-executor?/arch-cortex-m", "time" ]
128low-power-debug-with-sleep = [] 128low-power-debug-with-sleep = []
129 129
130## Automatically generate `memory.x` file using [`stm32-metapac`](https://docs.rs/stm32-metapac/) 130## Automatically generate `memory.x` file based on the memory map from [`stm32-metapac`](https://docs.rs/stm32-metapac/)
131memory-x = ["stm32-metapac/memory-x"] 131memory-x = []
132 132
133## Use secure registers when TrustZone is enabled 133## Use secure registers when TrustZone is enabled
134trustzone-secure = [] 134trustzone-secure = []
@@ -202,6 +202,9 @@ _split-pins-enabled = []
202 202
203## internal use only 203## internal use only
204_dual-core = [] 204_dual-core = []
205_core-cm0p = []
206_core-cm4 = []
207_core-cm7 = []
205 208
206#! ## Chip-selection features 209#! ## Chip-selection features
207#! Select your chip by specifying the model as a feature, e.g. `stm32c011d6`. 210#! Select your chip by specifying the model as a feature, e.g. `stm32c011d6`.
@@ -1026,40 +1029,40 @@ stm32h743xg = [ "stm32-metapac/stm32h743xg" ]
1026stm32h743xi = [ "stm32-metapac/stm32h743xi" ] 1029stm32h743xi = [ "stm32-metapac/stm32h743xi" ]
1027stm32h743zg = [ "stm32-metapac/stm32h743zg" ] 1030stm32h743zg = [ "stm32-metapac/stm32h743zg" ]
1028stm32h743zi = [ "stm32-metapac/stm32h743zi" ] 1031stm32h743zi = [ "stm32-metapac/stm32h743zi" ]
1029stm32h745bg-cm7 = [ "stm32-metapac/stm32h745bg-cm7", "_dual-core" ] 1032stm32h745bg-cm7 = [ "stm32-metapac/stm32h745bg-cm7", "_dual-core", "_core-cm7" ]
1030stm32h745bg-cm4 = [ "stm32-metapac/stm32h745bg-cm4", "_dual-core" ] 1033stm32h745bg-cm4 = [ "stm32-metapac/stm32h745bg-cm4", "_dual-core", "_core-cm4" ]
1031stm32h745bi-cm7 = [ "stm32-metapac/stm32h745bi-cm7", "_dual-core" ] 1034stm32h745bi-cm7 = [ "stm32-metapac/stm32h745bi-cm7", "_dual-core", "_core-cm7" ]
1032stm32h745bi-cm4 = [ "stm32-metapac/stm32h745bi-cm4", "_dual-core" ] 1035stm32h745bi-cm4 = [ "stm32-metapac/stm32h745bi-cm4", "_dual-core", "_core-cm4" ]
1033stm32h745ig-cm7 = [ "stm32-metapac/stm32h745ig-cm7", "_dual-core" ] 1036stm32h745ig-cm7 = [ "stm32-metapac/stm32h745ig-cm7", "_dual-core", "_core-cm7" ]
1034stm32h745ig-cm4 = [ "stm32-metapac/stm32h745ig-cm4", "_dual-core" ] 1037stm32h745ig-cm4 = [ "stm32-metapac/stm32h745ig-cm4", "_dual-core", "_core-cm4" ]
1035stm32h745ii-cm7 = [ "stm32-metapac/stm32h745ii-cm7", "_dual-core" ] 1038stm32h745ii-cm7 = [ "stm32-metapac/stm32h745ii-cm7", "_dual-core", "_core-cm7" ]
1036stm32h745ii-cm4 = [ "stm32-metapac/stm32h745ii-cm4", "_dual-core" ] 1039stm32h745ii-cm4 = [ "stm32-metapac/stm32h745ii-cm4", "_dual-core", "_core-cm4" ]
1037stm32h745xg-cm7 = [ "stm32-metapac/stm32h745xg-cm7", "_dual-core" ] 1040stm32h745xg-cm7 = [ "stm32-metapac/stm32h745xg-cm7", "_dual-core", "_core-cm7" ]
1038stm32h745xg-cm4 = [ "stm32-metapac/stm32h745xg-cm4", "_dual-core" ] 1041stm32h745xg-cm4 = [ "stm32-metapac/stm32h745xg-cm4", "_dual-core", "_core-cm4" ]
1039stm32h745xi-cm7 = [ "stm32-metapac/stm32h745xi-cm7", "_dual-core" ] 1042stm32h745xi-cm7 = [ "stm32-metapac/stm32h745xi-cm7", "_dual-core", "_core-cm7" ]
1040stm32h745xi-cm4 = [ "stm32-metapac/stm32h745xi-cm4", "_dual-core" ] 1043stm32h745xi-cm4 = [ "stm32-metapac/stm32h745xi-cm4", "_dual-core", "_core-cm4" ]
1041stm32h745zg-cm7 = [ "stm32-metapac/stm32h745zg-cm7", "_dual-core" ] 1044stm32h745zg-cm7 = [ "stm32-metapac/stm32h745zg-cm7", "_dual-core", "_core-cm7" ]
1042stm32h745zg-cm4 = [ "stm32-metapac/stm32h745zg-cm4", "_dual-core" ] 1045stm32h745zg-cm4 = [ "stm32-metapac/stm32h745zg-cm4", "_dual-core", "_core-cm4" ]
1043stm32h745zi-cm7 = [ "stm32-metapac/stm32h745zi-cm7", "_dual-core" ] 1046stm32h745zi-cm7 = [ "stm32-metapac/stm32h745zi-cm7", "_dual-core", "_core-cm7" ]
1044stm32h745zi-cm4 = [ "stm32-metapac/stm32h745zi-cm4", "_dual-core" ] 1047stm32h745zi-cm4 = [ "stm32-metapac/stm32h745zi-cm4", "_dual-core", "_core-cm4" ]
1045stm32h747ag-cm7 = [ "stm32-metapac/stm32h747ag-cm7", "_dual-core" ] 1048stm32h747ag-cm7 = [ "stm32-metapac/stm32h747ag-cm7", "_dual-core", "_core-cm7" ]
1046stm32h747ag-cm4 = [ "stm32-metapac/stm32h747ag-cm4", "_dual-core" ] 1049stm32h747ag-cm4 = [ "stm32-metapac/stm32h747ag-cm4", "_dual-core", "_core-cm4" ]
1047stm32h747ai-cm7 = [ "stm32-metapac/stm32h747ai-cm7", "_dual-core" ] 1050stm32h747ai-cm7 = [ "stm32-metapac/stm32h747ai-cm7", "_dual-core", "_core-cm7" ]
1048stm32h747ai-cm4 = [ "stm32-metapac/stm32h747ai-cm4", "_dual-core" ] 1051stm32h747ai-cm4 = [ "stm32-metapac/stm32h747ai-cm4", "_dual-core", "_core-cm4" ]
1049stm32h747bg-cm7 = [ "stm32-metapac/stm32h747bg-cm7", "_dual-core" ] 1052stm32h747bg-cm7 = [ "stm32-metapac/stm32h747bg-cm7", "_dual-core", "_core-cm7" ]
1050stm32h747bg-cm4 = [ "stm32-metapac/stm32h747bg-cm4", "_dual-core" ] 1053stm32h747bg-cm4 = [ "stm32-metapac/stm32h747bg-cm4", "_dual-core", "_core-cm4" ]
1051stm32h747bi-cm7 = [ "stm32-metapac/stm32h747bi-cm7", "_dual-core" ] 1054stm32h747bi-cm7 = [ "stm32-metapac/stm32h747bi-cm7", "_dual-core", "_core-cm7" ]
1052stm32h747bi-cm4 = [ "stm32-metapac/stm32h747bi-cm4", "_dual-core" ] 1055stm32h747bi-cm4 = [ "stm32-metapac/stm32h747bi-cm4", "_dual-core", "_core-cm4" ]
1053stm32h747ig-cm7 = [ "stm32-metapac/stm32h747ig-cm7", "_dual-core" ] 1056stm32h747ig-cm7 = [ "stm32-metapac/stm32h747ig-cm7", "_dual-core", "_core-cm7" ]
1054stm32h747ig-cm4 = [ "stm32-metapac/stm32h747ig-cm4", "_dual-core" ] 1057stm32h747ig-cm4 = [ "stm32-metapac/stm32h747ig-cm4", "_dual-core", "_core-cm4" ]
1055stm32h747ii-cm7 = [ "stm32-metapac/stm32h747ii-cm7", "_dual-core" ] 1058stm32h747ii-cm7 = [ "stm32-metapac/stm32h747ii-cm7", "_dual-core", "_core-cm7" ]
1056stm32h747ii-cm4 = [ "stm32-metapac/stm32h747ii-cm4", "_dual-core" ] 1059stm32h747ii-cm4 = [ "stm32-metapac/stm32h747ii-cm4", "_dual-core", "_core-cm4" ]
1057stm32h747xg-cm7 = [ "stm32-metapac/stm32h747xg-cm7", "_dual-core" ] 1060stm32h747xg-cm7 = [ "stm32-metapac/stm32h747xg-cm7", "_dual-core", "_core-cm7" ]
1058stm32h747xg-cm4 = [ "stm32-metapac/stm32h747xg-cm4", "_dual-core" ] 1061stm32h747xg-cm4 = [ "stm32-metapac/stm32h747xg-cm4", "_dual-core", "_core-cm4" ]
1059stm32h747xi-cm7 = [ "stm32-metapac/stm32h747xi-cm7", "_dual-core" ] 1062stm32h747xi-cm7 = [ "stm32-metapac/stm32h747xi-cm7", "_dual-core", "_core-cm7" ]
1060stm32h747xi-cm4 = [ "stm32-metapac/stm32h747xi-cm4", "_dual-core" ] 1063stm32h747xi-cm4 = [ "stm32-metapac/stm32h747xi-cm4", "_dual-core", "_core-cm4" ]
1061stm32h747zi-cm7 = [ "stm32-metapac/stm32h747zi-cm7", "_dual-core" ] 1064stm32h747zi-cm7 = [ "stm32-metapac/stm32h747zi-cm7", "_dual-core", "_core-cm7" ]
1062stm32h747zi-cm4 = [ "stm32-metapac/stm32h747zi-cm4", "_dual-core" ] 1065stm32h747zi-cm4 = [ "stm32-metapac/stm32h747zi-cm4", "_dual-core", "_core-cm4" ]
1063stm32h750ib = [ "stm32-metapac/stm32h750ib" ] 1066stm32h750ib = [ "stm32-metapac/stm32h750ib" ]
1064stm32h750vb = [ "stm32-metapac/stm32h750vb" ] 1067stm32h750vb = [ "stm32-metapac/stm32h750vb" ]
1065stm32h750xb = [ "stm32-metapac/stm32h750xb" ] 1068stm32h750xb = [ "stm32-metapac/stm32h750xb" ]
@@ -1070,24 +1073,24 @@ stm32h753ii = [ "stm32-metapac/stm32h753ii" ]
1070stm32h753vi = [ "stm32-metapac/stm32h753vi" ] 1073stm32h753vi = [ "stm32-metapac/stm32h753vi" ]
1071stm32h753xi = [ "stm32-metapac/stm32h753xi" ] 1074stm32h753xi = [ "stm32-metapac/stm32h753xi" ]
1072stm32h753zi = [ "stm32-metapac/stm32h753zi" ] 1075stm32h753zi = [ "stm32-metapac/stm32h753zi" ]
1073stm32h755bi-cm7 = [ "stm32-metapac/stm32h755bi-cm7", "_dual-core" ] 1076stm32h755bi-cm7 = [ "stm32-metapac/stm32h755bi-cm7", "_dual-core", "_core-cm7" ]
1074stm32h755bi-cm4 = [ "stm32-metapac/stm32h755bi-cm4", "_dual-core" ] 1077stm32h755bi-cm4 = [ "stm32-metapac/stm32h755bi-cm4", "_dual-core", "_core-cm4" ]
1075stm32h755ii-cm7 = [ "stm32-metapac/stm32h755ii-cm7", "_dual-core" ] 1078stm32h755ii-cm7 = [ "stm32-metapac/stm32h755ii-cm7", "_dual-core", "_core-cm7" ]
1076stm32h755ii-cm4 = [ "stm32-metapac/stm32h755ii-cm4", "_dual-core" ] 1079stm32h755ii-cm4 = [ "stm32-metapac/stm32h755ii-cm4", "_dual-core", "_core-cm4" ]
1077stm32h755xi-cm7 = [ "stm32-metapac/stm32h755xi-cm7", "_dual-core" ] 1080stm32h755xi-cm7 = [ "stm32-metapac/stm32h755xi-cm7", "_dual-core", "_core-cm7" ]
1078stm32h755xi-cm4 = [ "stm32-metapac/stm32h755xi-cm4", "_dual-core" ] 1081stm32h755xi-cm4 = [ "stm32-metapac/stm32h755xi-cm4", "_dual-core", "_core-cm4" ]
1079stm32h755zi-cm7 = [ "stm32-metapac/stm32h755zi-cm7", "_dual-core" ] 1082stm32h755zi-cm7 = [ "stm32-metapac/stm32h755zi-cm7", "_dual-core", "_core-cm7" ]
1080stm32h755zi-cm4 = [ "stm32-metapac/stm32h755zi-cm4", "_dual-core" ] 1083stm32h755zi-cm4 = [ "stm32-metapac/stm32h755zi-cm4", "_dual-core", "_core-cm4" ]
1081stm32h757ai-cm7 = [ "stm32-metapac/stm32h757ai-cm7", "_dual-core" ] 1084stm32h757ai-cm7 = [ "stm32-metapac/stm32h757ai-cm7", "_dual-core", "_core-cm7" ]
1082stm32h757ai-cm4 = [ "stm32-metapac/stm32h757ai-cm4", "_dual-core" ] 1085stm32h757ai-cm4 = [ "stm32-metapac/stm32h757ai-cm4", "_dual-core", "_core-cm4" ]
1083stm32h757bi-cm7 = [ "stm32-metapac/stm32h757bi-cm7", "_dual-core" ] 1086stm32h757bi-cm7 = [ "stm32-metapac/stm32h757bi-cm7", "_dual-core", "_core-cm7" ]
1084stm32h757bi-cm4 = [ "stm32-metapac/stm32h757bi-cm4", "_dual-core" ] 1087stm32h757bi-cm4 = [ "stm32-metapac/stm32h757bi-cm4", "_dual-core", "_core-cm4" ]
1085stm32h757ii-cm7 = [ "stm32-metapac/stm32h757ii-cm7", "_dual-core" ] 1088stm32h757ii-cm7 = [ "stm32-metapac/stm32h757ii-cm7", "_dual-core", "_core-cm7" ]
1086stm32h757ii-cm4 = [ "stm32-metapac/stm32h757ii-cm4", "_dual-core" ] 1089stm32h757ii-cm4 = [ "stm32-metapac/stm32h757ii-cm4", "_dual-core", "_core-cm4" ]
1087stm32h757xi-cm7 = [ "stm32-metapac/stm32h757xi-cm7", "_dual-core" ] 1090stm32h757xi-cm7 = [ "stm32-metapac/stm32h757xi-cm7", "_dual-core", "_core-cm7" ]
1088stm32h757xi-cm4 = [ "stm32-metapac/stm32h757xi-cm4", "_dual-core" ] 1091stm32h757xi-cm4 = [ "stm32-metapac/stm32h757xi-cm4", "_dual-core", "_core-cm4" ]
1089stm32h757zi-cm7 = [ "stm32-metapac/stm32h757zi-cm7", "_dual-core" ] 1092stm32h757zi-cm7 = [ "stm32-metapac/stm32h757zi-cm7", "_dual-core", "_core-cm7" ]
1090stm32h757zi-cm4 = [ "stm32-metapac/stm32h757zi-cm4", "_dual-core" ] 1093stm32h757zi-cm4 = [ "stm32-metapac/stm32h757zi-cm4", "_dual-core", "_core-cm4" ]
1091stm32h7a3ag = [ "stm32-metapac/stm32h7a3ag" ] 1094stm32h7a3ag = [ "stm32-metapac/stm32h7a3ag" ]
1092stm32h7a3ai = [ "stm32-metapac/stm32h7a3ai" ] 1095stm32h7a3ai = [ "stm32-metapac/stm32h7a3ai" ]
1093stm32h7a3ig = [ "stm32-metapac/stm32h7a3ig" ] 1096stm32h7a3ig = [ "stm32-metapac/stm32h7a3ig" ]
@@ -1620,14 +1623,14 @@ stm32wba55he = [ "stm32-metapac/stm32wba55he" ]
1620stm32wba55hg = [ "stm32-metapac/stm32wba55hg" ] 1623stm32wba55hg = [ "stm32-metapac/stm32wba55hg" ]
1621stm32wba55ue = [ "stm32-metapac/stm32wba55ue" ] 1624stm32wba55ue = [ "stm32-metapac/stm32wba55ue" ]
1622stm32wba55ug = [ "stm32-metapac/stm32wba55ug" ] 1625stm32wba55ug = [ "stm32-metapac/stm32wba55ug" ]
1623stm32wl54cc-cm4 = [ "stm32-metapac/stm32wl54cc-cm4", "_dual-core" ] 1626stm32wl54cc-cm4 = [ "stm32-metapac/stm32wl54cc-cm4", "_dual-core", "_core-cm4" ]
1624stm32wl54cc-cm0p = [ "stm32-metapac/stm32wl54cc-cm0p", "_dual-core" ] 1627stm32wl54cc-cm0p = [ "stm32-metapac/stm32wl54cc-cm0p", "_dual-core", "_core-cm0p" ]
1625stm32wl54jc-cm4 = [ "stm32-metapac/stm32wl54jc-cm4", "_dual-core" ] 1628stm32wl54jc-cm4 = [ "stm32-metapac/stm32wl54jc-cm4", "_dual-core", "_core-cm4" ]
1626stm32wl54jc-cm0p = [ "stm32-metapac/stm32wl54jc-cm0p", "_dual-core" ] 1629stm32wl54jc-cm0p = [ "stm32-metapac/stm32wl54jc-cm0p", "_dual-core", "_core-cm0p" ]
1627stm32wl55cc-cm4 = [ "stm32-metapac/stm32wl55cc-cm4", "_dual-core" ] 1630stm32wl55cc-cm4 = [ "stm32-metapac/stm32wl55cc-cm4", "_dual-core", "_core-cm4" ]
1628stm32wl55cc-cm0p = [ "stm32-metapac/stm32wl55cc-cm0p", "_dual-core" ] 1631stm32wl55cc-cm0p = [ "stm32-metapac/stm32wl55cc-cm0p", "_dual-core", "_core-cm0p" ]
1629stm32wl55jc-cm4 = [ "stm32-metapac/stm32wl55jc-cm4", "_dual-core" ] 1632stm32wl55jc-cm4 = [ "stm32-metapac/stm32wl55jc-cm4", "_dual-core", "_core-cm4" ]
1630stm32wl55jc-cm0p = [ "stm32-metapac/stm32wl55jc-cm0p", "_dual-core" ] 1633stm32wl55jc-cm0p = [ "stm32-metapac/stm32wl55jc-cm0p", "_dual-core", "_core-cm0p" ]
1631stm32wle4c8 = [ "stm32-metapac/stm32wle4c8" ] 1634stm32wle4c8 = [ "stm32-metapac/stm32wle4c8" ]
1632stm32wle4cb = [ "stm32-metapac/stm32wle4cb" ] 1635stm32wle4cb = [ "stm32-metapac/stm32wle4cb" ]
1633stm32wle4cc = [ "stm32-metapac/stm32wle4cc" ] 1636stm32wle4cc = [ "stm32-metapac/stm32wle4cc" ]
diff --git a/embassy-stm32/build.rs b/embassy-stm32/build.rs
index e293cf965..43bbef7e4 100644
--- a/embassy-stm32/build.rs
+++ b/embassy-stm32/build.rs
@@ -9,8 +9,8 @@ use proc_macro2::{Ident, TokenStream};
9use quote::{format_ident, quote}; 9use quote::{format_ident, quote};
10use stm32_metapac::metadata::ir::BitOffset; 10use stm32_metapac::metadata::ir::BitOffset;
11use stm32_metapac::metadata::{ 11use stm32_metapac::metadata::{
12 MemoryRegionKind, PeripheralRccKernelClock, PeripheralRccRegister, PeripheralRegisters, StopMode, ALL_CHIPS, 12 MemoryRegion, MemoryRegionKind, PeripheralRccKernelClock, PeripheralRccRegister, PeripheralRegisters, StopMode,
13 ALL_PERIPHERAL_VERSIONS, METADATA, 13 ALL_CHIPS, ALL_PERIPHERAL_VERSIONS, METADATA,
14}; 14};
15 15
16#[path = "./build_common.rs"] 16#[path = "./build_common.rs"]
@@ -1678,6 +1678,59 @@ fn main() {
1678 pub(crate) const DMA_CHANNELS: &[crate::dma::ChannelInfo] = &[#dmas]; 1678 pub(crate) const DMA_CHANNELS: &[crate::dma::ChannelInfo] = &[#dmas];
1679 }); 1679 });
1680 1680
1681 // ========
1682 // Generate gpio_block() function
1683
1684 let gpio_base = METADATA.peripherals.iter().find(|p| p.name == "GPIOA").unwrap().address as usize;
1685 let gpio_stride = 0x400 as usize;
1686
1687 for p in METADATA.peripherals {
1688 if let Some(bi) = &p.registers {
1689 if bi.kind == "gpio" {
1690 assert_eq!(0, (p.address as usize - gpio_base) % gpio_stride);
1691 }
1692 }
1693 }
1694
1695 g.extend(quote!(
1696 pub fn gpio_block(n: usize) -> crate::pac::gpio::Gpio {{
1697 unsafe {{ crate::pac::gpio::Gpio::from_ptr((#gpio_base + #gpio_stride*n) as _) }}
1698 }}
1699 ));
1700
1701 // ========
1702 // Generate flash constants
1703
1704 let flash_regions: Vec<&MemoryRegion> = METADATA
1705 .memory
1706 .iter()
1707 .filter(|x| x.kind == MemoryRegionKind::Flash && x.name.starts_with("BANK_"))
1708 .collect();
1709 let first_flash = flash_regions.first().unwrap();
1710 let total_flash_size = flash_regions
1711 .iter()
1712 .map(|x| x.size)
1713 .reduce(|acc, item| acc + item)
1714 .unwrap();
1715 let write_sizes: HashSet<_> = flash_regions
1716 .iter()
1717 .map(|r| r.settings.as_ref().unwrap().write_size)
1718 .collect();
1719 assert_eq!(1, write_sizes.len());
1720
1721 let flash_base = first_flash.address as usize;
1722 let total_flash_size = total_flash_size as usize;
1723 let write_size = (*write_sizes.iter().next().unwrap()) as usize;
1724
1725 g.extend(quote!(
1726 pub const FLASH_BASE: usize = #flash_base;
1727 pub const FLASH_SIZE: usize = #total_flash_size;
1728 pub const WRITE_SIZE: usize = #write_size;
1729 ));
1730
1731 // ========
1732 // Generate macro-tables
1733
1681 for irq in METADATA.interrupts { 1734 for irq in METADATA.interrupts {
1682 let name = irq.name.to_ascii_uppercase(); 1735 let name = irq.name.to_ascii_uppercase();
1683 interrupts_table.push(vec![name.clone()]); 1736 interrupts_table.push(vec![name.clone()]);
@@ -1772,6 +1825,11 @@ fn main() {
1772 } 1825 }
1773 1826
1774 println!("cargo:rerun-if-changed=build.rs"); 1827 println!("cargo:rerun-if-changed=build.rs");
1828
1829 if cfg!(feature = "memory-x") {
1830 gen_memory_x(out_dir);
1831 println!("cargo:rustc-link-search={}", out_dir.display());
1832 }
1775} 1833}
1776 1834
1777enum GetOneError { 1835enum GetOneError {
@@ -1857,3 +1915,78 @@ fn rustfmt(path: impl AsRef<Path>) {
1857 } 1915 }
1858 } 1916 }
1859} 1917}
1918
1919fn gen_memory_x(out_dir: &Path) {
1920 let mut memory_x = String::new();
1921
1922 let flash = get_memory_range(MemoryRegionKind::Flash);
1923 let ram = get_memory_range(MemoryRegionKind::Ram);
1924
1925 write!(memory_x, "MEMORY\n{{\n").unwrap();
1926 writeln!(
1927 memory_x,
1928 " FLASH : ORIGIN = 0x{:08x}, LENGTH = {:>4}K /* {} */",
1929 flash.0,
1930 flash.1 / 1024,
1931 flash.2
1932 )
1933 .unwrap();
1934 writeln!(
1935 memory_x,
1936 " RAM : ORIGIN = 0x{:08x}, LENGTH = {:>4}K /* {} */",
1937 ram.0,
1938 ram.1 / 1024,
1939 ram.2
1940 )
1941 .unwrap();
1942 write!(memory_x, "}}").unwrap();
1943
1944 std::fs::write(out_dir.join("memory.x"), memory_x.as_bytes()).unwrap();
1945}
1946
1947fn get_memory_range(kind: MemoryRegionKind) -> (u32, u32, String) {
1948 let mut mems: Vec<_> = METADATA
1949 .memory
1950 .iter()
1951 .filter(|m| m.kind == kind && m.size != 0)
1952 .collect();
1953 mems.sort_by_key(|m| m.address);
1954
1955 let mut start = u32::MAX;
1956 let mut end = u32::MAX;
1957 let mut names = Vec::new();
1958 let mut best: Option<(u32, u32, String)> = None;
1959 for m in mems {
1960 if !mem_filter(&METADATA.name, &m.name) {
1961 continue;
1962 }
1963
1964 if m.address != end {
1965 names = Vec::new();
1966 start = m.address;
1967 end = m.address;
1968 }
1969
1970 end += m.size;
1971 names.push(m.name.to_string());
1972
1973 if best.is_none() || end - start > best.as_ref().unwrap().1 {
1974 best = Some((start, end - start, names.join(" + ")));
1975 }
1976 }
1977
1978 best.unwrap()
1979}
1980
1981fn mem_filter(chip: &str, region: &str) -> bool {
1982 // in STM32WB, SRAM2a/SRAM2b are reserved for the radio core.
1983 if chip.starts_with("STM32WB")
1984 && !chip.starts_with("STM32WBA")
1985 && !chip.starts_with("STM32WB0")
1986 && region.starts_with("SRAM2")
1987 {
1988 return false;
1989 }
1990
1991 true
1992}
diff --git a/embassy-stm32/src/exti.rs b/embassy-stm32/src/exti.rs
index 5cff74264..9604c5149 100644
--- a/embassy-stm32/src/exti.rs
+++ b/embassy-stm32/src/exti.rs
@@ -16,9 +16,14 @@ use crate::{interrupt, pac, peripherals, Peripheral};
16const EXTI_COUNT: usize = 16; 16const EXTI_COUNT: usize = 16;
17static EXTI_WAKERS: [AtomicWaker; EXTI_COUNT] = [const { AtomicWaker::new() }; EXTI_COUNT]; 17static EXTI_WAKERS: [AtomicWaker; EXTI_COUNT] = [const { AtomicWaker::new() }; EXTI_COUNT];
18 18
19#[cfg(exti_w)] 19#[cfg(all(exti_w, feature = "_core-cm0p"))]
20fn cpu_regs() -> pac::exti::Cpu { 20fn cpu_regs() -> pac::exti::Cpu {
21 EXTI.cpu(crate::pac::CORE_INDEX) 21 EXTI.cpu(1)
22}
23
24#[cfg(all(exti_w, not(feature = "_core-cm0p")))]
25fn cpu_regs() -> pac::exti::Cpu {
26 EXTI.cpu(0)
22} 27}
23 28
24#[cfg(not(exti_w))] 29#[cfg(not(exti_w))]
diff --git a/embassy-stm32/src/flash/common.rs b/embassy-stm32/src/flash/common.rs
index 8ec4bb2a1..0004a7488 100644
--- a/embassy-stm32/src/flash/common.rs
+++ b/embassy-stm32/src/flash/common.rs
@@ -3,12 +3,12 @@ use core::sync::atomic::{fence, Ordering};
3 3
4use embassy_hal_internal::drop::OnDrop; 4use embassy_hal_internal::drop::OnDrop;
5use embassy_hal_internal::{into_ref, PeripheralRef}; 5use embassy_hal_internal::{into_ref, PeripheralRef};
6use stm32_metapac::FLASH_BASE;
7 6
8use super::{ 7use super::{
9 family, Async, Blocking, Error, FlashBank, FlashLayout, FlashRegion, FlashSector, FLASH_SIZE, MAX_ERASE_SIZE, 8 family, Async, Blocking, Error, FlashBank, FlashLayout, FlashRegion, FlashSector, FLASH_SIZE, MAX_ERASE_SIZE,
10 READ_SIZE, WRITE_SIZE, 9 READ_SIZE, WRITE_SIZE,
11}; 10};
11use crate::_generated::FLASH_BASE;
12use crate::peripherals::FLASH; 12use crate::peripherals::FLASH;
13use crate::Peripheral; 13use crate::Peripheral;
14 14
diff --git a/embassy-stm32/src/flash/f4.rs b/embassy-stm32/src/flash/f4.rs
index 8ebeae95b..d818c77d0 100644
--- a/embassy-stm32/src/flash/f4.rs
+++ b/embassy-stm32/src/flash/f4.rs
@@ -3,9 +3,9 @@ use core::sync::atomic::{fence, AtomicBool, Ordering};
3 3
4use embassy_sync::waitqueue::AtomicWaker; 4use embassy_sync::waitqueue::AtomicWaker;
5use pac::flash::regs::Sr; 5use pac::flash::regs::Sr;
6use pac::FLASH_SIZE;
7 6
8use super::{FlashBank, FlashRegion, FlashSector, FLASH_REGIONS, WRITE_SIZE}; 7use super::{FlashBank, FlashRegion, FlashSector, FLASH_REGIONS, WRITE_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 11#[allow(missing_docs)] // TODO
@@ -14,9 +14,9 @@ mod alt_regions {
14 use core::marker::PhantomData; 14 use core::marker::PhantomData;
15 15
16 use embassy_hal_internal::PeripheralRef; 16 use embassy_hal_internal::PeripheralRef;
17 use stm32_metapac::FLASH_SIZE;
18 17
19 use crate::_generated::flash_regions::{BANK1_REGION1, BANK1_REGION2, BANK1_REGION3}; 18 use crate::_generated::flash_regions::{BANK1_REGION1, BANK1_REGION2, BANK1_REGION3};
19 use crate::_generated::FLASH_SIZE;
20 use crate::flash::{asynch, Async, Bank1Region1, Bank1Region2, Blocking, Error, Flash, FlashBank, FlashRegion}; 20 use crate::flash::{asynch, Async, Bank1Region1, Bank1Region2, Blocking, Error, Flash, FlashBank, FlashRegion};
21 use crate::peripherals::FLASH; 21 use crate::peripherals::FLASH;
22 22
diff --git a/embassy-stm32/src/flash/mod.rs b/embassy-stm32/src/flash/mod.rs
index aef1f1482..b564de093 100644
--- a/embassy-stm32/src/flash/mod.rs
+++ b/embassy-stm32/src/flash/mod.rs
@@ -12,8 +12,7 @@ pub use asynch::InterruptHandler;
12pub use common::*; 12pub use common::*;
13 13
14pub use crate::_generated::flash_regions::*; 14pub use crate::_generated::flash_regions::*;
15pub use crate::_generated::MAX_ERASE_SIZE; 15pub use crate::_generated::{FLASH_BASE, FLASH_SIZE, MAX_ERASE_SIZE, WRITE_SIZE};
16pub use crate::pac::{FLASH_BASE, FLASH_SIZE, WRITE_SIZE};
17 16
18/// Get whether the default flash layout is being used. 17/// Get whether the default flash layout is being used.
19/// 18///
diff --git a/embassy-stm32/src/gpio.rs b/embassy-stm32/src/gpio.rs
index 6967ecc7c..65e1bfb8c 100644
--- a/embassy-stm32/src/gpio.rs
+++ b/embassy-stm32/src/gpio.rs
@@ -7,7 +7,7 @@ use critical_section::CriticalSection;
7use embassy_hal_internal::{impl_peripheral, into_ref, PeripheralRef}; 7use embassy_hal_internal::{impl_peripheral, into_ref, PeripheralRef};
8 8
9use crate::pac::gpio::{self, vals}; 9use crate::pac::gpio::{self, vals};
10use crate::{pac, peripherals, Peripheral}; 10use crate::{peripherals, Peripheral};
11 11
12/// GPIO flexible pin. 12/// GPIO flexible pin.
13/// 13///
@@ -726,7 +726,7 @@ pub(crate) trait SealedPin {
726 726
727 #[inline] 727 #[inline]
728 fn block(&self) -> gpio::Gpio { 728 fn block(&self) -> gpio::Gpio {
729 pac::GPIO(self._port() as _) 729 crate::_generated::gpio_block(self._port() as _)
730 } 730 }
731 731
732 /// Set the output as high. 732 /// Set the output as high.
@@ -835,7 +835,7 @@ impl AnyPin {
835 #[cfg(feature = "unstable-pac")] 835 #[cfg(feature = "unstable-pac")]
836 #[inline] 836 #[inline]
837 pub fn block(&self) -> gpio::Gpio { 837 pub fn block(&self) -> gpio::Gpio {
838 pac::GPIO(self._port() as _) 838 crate::_generated::gpio_block(self._port() as _)
839 } 839 }
840} 840}
841 841