aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2025-07-17 19:32:30 +0000
committerGitHub <[email protected]>2025-07-17 19:32:30 +0000
commite3aff148f488221829b55b8ff3266d7ce0d05a32 (patch)
tree5998fa98beecc685320a6bc8288809458048418d
parentbe312850c851d1e18452d9b79860b4d56ceea8e1 (diff)
parenta3c367d54ef6ec0fe7a2c358c209871a486eadcb (diff)
Merge pull request #3653 from fwolter/add-remap
STM32F0/F3 Remap DMA channels
-rw-r--r--embassy-stm32/CHANGELOG.md1
-rw-r--r--embassy-stm32/Cargo.toml4
-rw-r--r--embassy-stm32/build.rs28
-rw-r--r--embassy-stm32/src/macros.rs14
4 files changed, 43 insertions, 4 deletions
diff --git a/embassy-stm32/CHANGELOG.md b/embassy-stm32/CHANGELOG.md
index b6781905e..c4c2cd013 100644
--- a/embassy-stm32/CHANGELOG.md
+++ b/embassy-stm32/CHANGELOG.md
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
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- 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))
11- Add automatic setting of remap bits when using alternate DMA channels on STM32F0 and STM32F3 devices ([#3653](https://github.com/embassy-rs/embassy/pull/3653))
11 12
12## 0.2.0 - 2025-01-10 13## 0.2.0 - 2025-01-10
13 14
diff --git a/embassy-stm32/Cargo.toml b/embassy-stm32/Cargo.toml
index 0266b53b6..d9c5d1dd9 100644
--- a/embassy-stm32/Cargo.toml
+++ b/embassy-stm32/Cargo.toml
@@ -81,7 +81,7 @@ futures-util = { version = "0.3.30", default-features = false }
81sdio-host = "0.9.0" 81sdio-host = "0.9.0"
82critical-section = "1.1" 82critical-section = "1.1"
83#stm32-metapac = { version = "16" } 83#stm32-metapac = { version = "16" }
84stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-f761780b74faf840220b367b15d556b9e10c2334" } 84stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-6e47f105286c0de07f641e22f27db060f1395e86" }
85 85
86vcell = "0.1.3" 86vcell = "0.1.3"
87nb = "1.0.0" 87nb = "1.0.0"
@@ -110,7 +110,7 @@ proc-macro2 = "1.0.36"
110quote = "1.0.15" 110quote = "1.0.15"
111 111
112#stm32-metapac = { version = "16", default-features = false, features = ["metadata"]} 112#stm32-metapac = { version = "16", default-features = false, features = ["metadata"]}
113stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-f761780b74faf840220b367b15d556b9e10c2334", default-features = false, features = ["metadata"] } 113stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-6e47f105286c0de07f641e22f27db060f1395e86", default-features = false, features = ["metadata"] }
114 114
115[features] 115[features]
116default = ["rt"] 116default = ["rt"]
diff --git a/embassy-stm32/build.rs b/embassy-stm32/build.rs
index 753f241c7..ad07b0269 100644
--- a/embassy-stm32/build.rs
+++ b/embassy-stm32/build.rs
@@ -1551,9 +1551,35 @@ fn main() {
1551 quote!(()) 1551 quote!(())
1552 }; 1552 };
1553 1553
1554 let mut remap = quote!();
1555 for remap_info in ch.remap {
1556 let register = format_ident!("{}", remap_info.register.to_lowercase());
1557 let setter = format_ident!("set_{}", remap_info.field.to_lowercase());
1558
1559 let field_metadata = METADATA
1560 .peripherals
1561 .iter()
1562 .filter(|p| p.name == "SYSCFG")
1563 .flat_map(|p| p.registers.as_ref().unwrap().ir.fieldsets.iter())
1564 .filter(|f| f.name.eq_ignore_ascii_case(remap_info.register))
1565 .flat_map(|f| f.fields.iter())
1566 .find(|f| f.name.eq_ignore_ascii_case(remap_info.field))
1567 .unwrap();
1568
1569 let value = if field_metadata.bit_size == 1 {
1570 let bool_value = format_ident!("{}", remap_info.value > 0);
1571 quote!(#bool_value)
1572 } else {
1573 let value = remap_info.value;
1574 quote!(#value.into())
1575 };
1576
1577 remap.extend(quote!(crate::pac::SYSCFG.#register().modify(|w| w.#setter(#value));));
1578 }
1579
1554 let channel = format_ident!("{}", channel); 1580 let channel = format_ident!("{}", channel);
1555 g.extend(quote! { 1581 g.extend(quote! {
1556 dma_trait_impl!(#tr, #peri, #channel, #request); 1582 dma_trait_impl!(#tr, #peri, #channel, #request, {#remap});
1557 }); 1583 });
1558 } 1584 }
1559 } 1585 }
diff --git a/embassy-stm32/src/macros.rs b/embassy-stm32/src/macros.rs
index 7526bb180..3a0b490ba 100644
--- a/embassy-stm32/src/macros.rs
+++ b/embassy-stm32/src/macros.rs
@@ -81,17 +81,28 @@ macro_rules! dma_trait {
81 /// Note: in some chips, ST calls this the "channel", and calls channels "streams". 81 /// Note: in some chips, ST calls this the "channel", and calls channels "streams".
82 /// `embassy-stm32` always uses the "channel" and "request number" names. 82 /// `embassy-stm32` always uses the "channel" and "request number" names.
83 fn request(&self) -> crate::dma::Request; 83 fn request(&self) -> crate::dma::Request;
84 #[doc = "Remap the DMA channel"]
85 fn remap(&self);
84 } 86 }
85 }; 87 };
86} 88}
87 89
88#[allow(unused)] 90#[allow(unused)]
89macro_rules! dma_trait_impl { 91macro_rules! dma_trait_impl {
90 (crate::$mod:ident::$trait:ident$(<$mode:ident>)?, $instance:ident, $channel:ident, $request:expr) => { 92 (crate::$mod:ident::$trait:ident$(<$mode:ident>)?, $instance:ident, $channel:ident, $request:expr, $remap:expr) => {
91 impl crate::$mod::$trait<crate::peripherals::$instance $(, crate::$mod::$mode)?> for crate::peripherals::$channel { 93 impl crate::$mod::$trait<crate::peripherals::$instance $(, crate::$mod::$mode)?> for crate::peripherals::$channel {
92 fn request(&self) -> crate::dma::Request { 94 fn request(&self) -> crate::dma::Request {
93 $request 95 $request
94 } 96 }
97
98 fn remap(&self) {
99 critical_section::with(|_| {
100 #[allow(unused_unsafe)]
101 unsafe {
102 $remap;
103 }
104 });
105 }
95 } 106 }
96 }; 107 };
97} 108}
@@ -111,6 +122,7 @@ macro_rules! new_dma_nonopt {
111macro_rules! new_dma { 122macro_rules! new_dma {
112 ($name:ident) => {{ 123 ($name:ident) => {{
113 let dma = $name; 124 let dma = $name;
125 dma.remap();
114 let request = dma.request(); 126 let request = dma.request();
115 Some(crate::dma::ChannelAndRequest { 127 Some(crate::dma::ChannelAndRequest {
116 channel: dma.into(), 128 channel: dma.into(),