From 54b5012c568f5b952fefe50ad6a032b54172dabd Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Sat, 17 Jul 2021 07:35:59 +0200 Subject: [PATCH] stm32/dma: update codegen+macrotables for new stm32-data --- embassy-stm32/src/dma/bdma.rs | 4 +- embassy-stm32/src/dma/dma.rs | 2 +- embassy-stm32/src/dma/dmamux.rs | 35 ++------------ embassy-stm32/src/usart/mod.rs | 26 +++------- stm32-data | 2 +- stm32-metapac-gen/src/lib.rs | 84 ++++++++++++--------------------- 6 files changed, 42 insertions(+), 111 deletions(-) diff --git a/embassy-stm32/src/dma/bdma.rs b/embassy-stm32/src/dma/bdma.rs index 26adda08..3d9ff9eb 100644 --- a/embassy-stm32/src/dma/bdma.rs +++ b/embassy-stm32/src/dma/bdma.rs @@ -150,8 +150,8 @@ pub(crate) unsafe fn init() { } } -pac::bdma_channels! { - ($channel_peri:ident, $dma_peri:ident, $channel_num:expr) => { +pac::dma_channels! { + ($channel_peri:ident, $dma_peri:ident, bdma, $channel_num:expr, $dmamux:tt) => { impl crate::dma::sealed::Channel for crate::peripherals::$channel_peri {} impl Channel for crate::peripherals::$channel_peri { diff --git a/embassy-stm32/src/dma/dma.rs b/embassy-stm32/src/dma/dma.rs index 1d6f7aee..9b1c1160 100644 --- a/embassy-stm32/src/dma/dma.rs +++ b/embassy-stm32/src/dma/dma.rs @@ -153,7 +153,7 @@ pub(crate) unsafe fn init() { } pac::dma_channels! { - ($channel_peri:ident, $dma_peri:ident, $channel_num:expr) => { + ($channel_peri:ident, $dma_peri:ident, dma, $channel_num:expr, $dmamux:tt) => { impl crate::dma::sealed::Channel for crate::peripherals::$channel_peri {} impl Channel for crate::peripherals::$channel_peri { diff --git a/embassy-stm32/src/dma/dmamux.rs b/embassy-stm32/src/dma/dmamux.rs index e9fa4823..186ec247 100644 --- a/embassy-stm32/src/dma/dmamux.rs +++ b/embassy-stm32/src/dma/dmamux.rs @@ -24,40 +24,11 @@ pub(crate) trait MuxChannel { const DMAMUX_REGS: pac::dmamux::Dmamux; } -macro_rules! dma_num { - (DMA1) => { - 0 - }; - (DMA2) => { - 1 - }; -} - -#[cfg(not(rcc_h7))] -pac::bdma_channels! { - ($channel_peri:ident, $dma_peri:ident, $channel_num:expr) => { - impl MuxChannel for peripherals::$channel_peri { - const DMAMUX_CH_NUM: u8 = (dma_num!($dma_peri) * 8) + $channel_num; - const DMAMUX_REGS: pac::dmamux::Dmamux = pac::DMAMUX1; - } - }; -} - -#[cfg(rcc_h7)] pac::dma_channels! { - ($channel_peri:ident, $dma_peri:ident, $channel_num:expr) => { + ($channel_peri:ident, $dma_peri:ident, $version:ident, $channel_num:expr, {dmamux: $dmamux:ident, dmamux_channel: $dmamux_channel:expr}) => { impl MuxChannel for peripherals::$channel_peri { - const DMAMUX_CH_NUM: u8 = (dma_num!($dma_peri) * 8) + $channel_num; - const DMAMUX_REGS: pac::dmamux::Dmamux = pac::DMAMUX1; - } - }; -} -#[cfg(rcc_h7)] -pac::bdma_channels! { - ($channel_peri:ident, $dma_peri:ident, $channel_num:expr) => { - impl MuxChannel for peripherals::$channel_peri { - const DMAMUX_CH_NUM: u8 = $channel_num; - const DMAMUX_REGS: pac::dmamux::Dmamux = pac::DMAMUX2; + const DMAMUX_CH_NUM: u8 = $dmamux_channel; + const DMAMUX_REGS: pac::dmamux::Dmamux = pac::$dmamux; } }; } diff --git a/embassy-stm32/src/usart/mod.rs b/embassy-stm32/src/usart/mod.rs index bf6fa913..92021d0a 100644 --- a/embassy-stm32/src/usart/mod.rs +++ b/embassy-stm32/src/usart/mod.rs @@ -171,7 +171,7 @@ crate::pac::peripheral_pins!( ); macro_rules! impl_dma { - ($inst:ident, ALL, $signal:ident, $request:expr) => { + ($inst:ident, {dmamux: $dmamux:ident}, $signal:ident, $request:expr) => { impl sealed::$signal for T { fn request(&self) -> dma::Request { $request @@ -180,7 +180,7 @@ macro_rules! impl_dma { impl $signal for T {} }; - ($inst:ident, $channel:ident, $signal:ident, $request:expr) => { + ($inst:ident, {channel: $channel:ident}, $signal:ident, $request:expr) => { impl sealed::$signal for peripherals::$channel { fn request(&self) -> dma::Request { $request @@ -192,30 +192,16 @@ macro_rules! impl_dma { } crate::pac::peripheral_dma_channels! { - ($peri:ident, usart, $kind:ident, RX, $channel:ident, $dma_peri:ident, $channel_num:expr, $request:expr) => { + ($peri:ident, usart, $kind:ident, RX, $channel:tt, $request:expr) => { impl_dma!($peri, $channel, RxDma, $request); }; - ($peri:ident, usart, $kind:ident, TX, $channel:ident, $dma_peri:ident, $channel_num:expr, $request:expr) => { + ($peri:ident, usart, $kind:ident, TX, $channel:tt, $request:expr) => { impl_dma!($peri, $channel, TxDma, $request); }; - ($peri:ident, uart, $kind:ident, RX, $channel:ident, $dma_peri:ident, $channel_num:expr, $request:expr) => { + ($peri:ident, uart, $kind:ident, RX, $channel:tt, $request:expr) => { impl_dma!($peri, $channel, RxDma, $request); }; - ($peri:ident, uart, $kind:ident, TX, $channel:ident, $dma_peri:ident, $channel_num:expr, $request:expr) => { + ($peri:ident, uart, $kind:ident, TX, $channel:tt, $request:expr) => { impl_dma!($peri, $channel, TxDma, $request); }; } -crate::pac::dma_requests! { - (usart, $peri:ident, RX, $request:expr) => { - impl_dma!($peri, ALL, RxDma, $request); - }; - (usart, $peri:ident, TX, $request:expr) => { - impl_dma!($peri, ALL, TxDma, $request); - }; - (uart, $peri:ident, RX, $request:expr) => { - impl_dma!($peri, ALL, RxDma, $request); - }; - (uart, $peri:ident, TX, $request:expr) => { - impl_dma!($peri, ALL, TxDma, $request); - }; -} diff --git a/stm32-data b/stm32-data index d285fced..8702a3a3 160000 --- a/stm32-data +++ b/stm32-data @@ -1 +1 @@ -Subproject commit d285fced6573703be875436409f8c83dd80ae183 +Subproject commit 8702a3a3bb83a59515dab2cf9f75952fa6edae8a diff --git a/stm32-metapac-gen/src/lib.rs b/stm32-metapac-gen/src/lib.rs index 5c2d605b..fee99111 100644 --- a/stm32-metapac-gen/src/lib.rs +++ b/stm32-metapac-gen/src/lib.rs @@ -49,8 +49,6 @@ pub struct Peripheral { pub pins: Vec, #[serde(default)] pub dma_channels: HashMap>, - #[serde(default)] - pub dma_requests: HashMap, } #[derive(Debug, Eq, PartialEq, Clone, Deserialize)] @@ -64,20 +62,17 @@ pub struct Pin { pub struct DmaChannel { pub dma: String, pub channel: u32, + pub dmamux: Option, + pub dmamux_channel: Option, } #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Hash)] pub struct PeripheralDmaChannel { - pub channel: String, + pub channel: Option, + pub dmamux: Option, pub request: Option, } -#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Hash)] -pub struct PeripheralDmaRequest { - pub dmamux: String, - pub request: u32, -} - struct BlockInfo { /// usart_v1/USART -> usart module: String, @@ -272,19 +267,10 @@ pub fn gen(options: Options) { let mut peripheral_pins_table: Vec> = Vec::new(); let mut peripheral_rcc_table: Vec> = Vec::new(); let mut dma_channels_table: Vec> = Vec::new(); - let mut bdma_channels_table: Vec> = Vec::new(); - let mut dma_requests_table: Vec> = Vec::new(); let mut peripheral_dma_channels_table: Vec> = Vec::new(); let mut peripheral_counts: HashMap = HashMap::new(); let mut dma_channel_counts: HashMap = HashMap::new(); - let dma_base = core - .peripherals - .get(&"DMA".to_string()) - .unwrap_or_else(|| core.peripherals.get(&"DMA1".to_string()).unwrap()) - .address; - let dma_stride = 0x400; - let gpio_base = core.peripherals.get(&"GPIOA".to_string()).unwrap().address; let gpio_stride = 0x400; @@ -336,26 +322,20 @@ pub fn gen(options: Options) { peripheral_pins_table.push(row); } - for dma_request in &p.dma_requests { - let mut row = Vec::new(); - row.push(bi.module.clone()); - row.push(name.clone()); - row.push(dma_request.0.clone()); - row.push(dma_request.1.request.to_string()); - // TODO add the `dmamux` column - dma_requests_table.push(row); - } - - for (event, dma_channels) in &p.dma_channels { + for (request, dma_channels) in &p.dma_channels { for channel in dma_channels.iter() { let mut row = Vec::new(); row.push(name.clone()); row.push(bi.module.clone()); row.push(bi.block.clone()); - row.push(event.clone()); - row.push(channel.channel.clone()); - row.push(core.dma_channels[&channel.channel].dma.clone()); - row.push(core.dma_channels[&channel.channel].channel.to_string()); + row.push(request.clone()); + if let Some(channel) = &channel.channel { + row.push(format!("{{channel: {}}}", channel)); + } else if let Some(dmamux) = &channel.dmamux { + row.push(format!("{{dmamux: {}}}", dmamux)); + } else { + unreachable!(); + } if let Some(request) = channel.request { row.push(request.to_string()); } else { @@ -399,15 +379,6 @@ pub fn gen(options: Options) { ]); } } - "dma" => { - let dma_num = if name == "DMA" { - 0 - } else { - let dma_letter = name.chars().skip(3).next().unwrap(); - dma_letter as u32 - '1' as u32 - }; - assert_eq!(p.address, dma_base + dma_stride * dma_num); - } _ => {} } @@ -507,21 +478,25 @@ pub fn gen(options: Options) { for (id, channel_info) in &core.dma_channels { let mut row = Vec::new(); - let dma_peri = core.peripherals.get(&channel_info.dma); + let dma_peri = core.peripherals.get(&channel_info.dma).unwrap(); + let bi = BlockInfo::parse(dma_peri.block.as_ref().unwrap()); + row.push(id.clone()); row.push(channel_info.dma.clone()); + row.push(bi.module.clone()); row.push(channel_info.channel.to_string()); - if let Some(dma_peri) = dma_peri { - if let Some(ref block) = dma_peri.block { - let bi = BlockInfo::parse(block); - if bi.module == "bdma" { - bdma_channels_table.push(row); - } else { - dma_channels_table.push(row); - } - } + if let Some(dmamux) = &channel_info.dmamux { + let dmamux_channel = channel_info.dmamux_channel.unwrap(); + row.push(format!( + "{{dmamux: {}, dmamux_channel: {}}}", + dmamux, dmamux_channel + )); + } else { + row.push("{}".to_string()); } + dma_channels_table.push(row); + let dma_peri_name = channel_info.dma.clone(); dma_channel_counts.insert( dma_peri_name.clone(), @@ -548,7 +523,8 @@ pub fn gen(options: Options) { } } - if name.starts_with("BDMA_") || name.starts_with("BDMA1_") || name.starts_with("BDMA2_") { + if name.starts_with("BDMA_") || name.starts_with("BDMA1_") || name.starts_with("BDMA2_") + { interrupt_table.push(vec!["BDMA".to_string(), name.clone()]); } @@ -583,8 +559,6 @@ pub fn gen(options: Options) { ); make_table(&mut extra, "peripheral_rcc", &peripheral_rcc_table); make_table(&mut extra, "dma_channels", &dma_channels_table); - make_table(&mut extra, "bdma_channels", &bdma_channels_table); - make_table(&mut extra, "dma_requests", &dma_requests_table); make_peripheral_counts(&mut extra, &peripheral_counts); make_dma_channel_counts(&mut extra, &dma_channel_counts);