aboutsummaryrefslogtreecommitdiff
path: root/embassy-stm32
diff options
context:
space:
mode:
authorFabian Wolter <[email protected]>2024-12-15 20:15:11 +0100
committerFabian Wolter <[email protected]>2025-07-17 21:17:27 +0200
commitc279063c426b57f22d8bdeb7356b3c541b16bb08 (patch)
treebaf7e4e13be7b72442f5ca005eba02ac9f622664 /embassy-stm32
parentbe312850c851d1e18452d9b79860b4d56ceea8e1 (diff)
STM32F0/F3 Remap DMA channels
Fixes #3643
Diffstat (limited to 'embassy-stm32')
-rw-r--r--embassy-stm32/CHANGELOG.md1
-rw-r--r--embassy-stm32/build.rs19
-rw-r--r--embassy-stm32/src/macros.rs14
3 files changed, 32 insertions, 2 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/build.rs b/embassy-stm32/build.rs
index 753f241c7..068dadf4b 100644
--- a/embassy-stm32/build.rs
+++ b/embassy-stm32/build.rs
@@ -1551,9 +1551,26 @@ fn main() {
1551 quote!(()) 1551 quote!(())
1552 }; 1552 };
1553 1553
1554 let mut remap = quote!();
1555 for remap_info in ch.remap {
1556 let peripheral = format_ident!("{}", remap_info.peripheral);
1557 let register = format_ident!("{}", remap_info.register.to_lowercase());
1558 let setter = format_ident!("set_{}", remap_info.field.to_lowercase());
1559
1560 let value = if remap_info.value.contains("true") || remap_info.value.contains("false") {
1561 let value = format_ident!("{}", remap_info.value);
1562 quote!(#value)
1563 } else {
1564 let value = remap_info.value.parse::<u8>().unwrap();
1565 quote!(#value.into())
1566 };
1567
1568 remap.extend(quote!(crate::pac::#peripheral.#register().modify(|w| w.#setter(#value));));
1569 }
1570
1554 let channel = format_ident!("{}", channel); 1571 let channel = format_ident!("{}", channel);
1555 g.extend(quote! { 1572 g.extend(quote! {
1556 dma_trait_impl!(#tr, #peri, #channel, #request); 1573 dma_trait_impl!(#tr, #peri, #channel, #request, {#remap});
1557 }); 1574 });
1558 } 1575 }
1559 } 1576 }
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(),