diff options
| -rw-r--r-- | embassy-stm32/CHANGELOG.md | 1 | ||||
| -rw-r--r-- | embassy-stm32/build.rs | 19 | ||||
| -rw-r--r-- | embassy-stm32/src/macros.rs | 14 |
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)] |
| 89 | macro_rules! dma_trait_impl { | 91 | macro_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 { | |||
| 111 | macro_rules! new_dma { | 122 | macro_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(), |
