diff --git a/embassy-stm32/src/bdma/mod.rs b/embassy-stm32/src/bdma/mod.rs index b4da79285..d62feb5b9 100644 --- a/embassy-stm32/src/bdma/mod.rs +++ b/embassy-stm32/src/bdma/mod.rs @@ -152,7 +152,7 @@ unsafe fn on_irq() { pac::$dma.ifcr().write_value(isr); let dman = ::num() as usize; - for chn in 0..7 { + for chn in 0..crate::pac::dma_channels_count!($dma) { let n = dman * 8 + chn; if isr.teif(chn) { STATE.ch_status[n].store(CH_STATUS_ERROR, Ordering::Relaxed); diff --git a/stm32-metapac-gen/src/lib.rs b/stm32-metapac-gen/src/lib.rs index 640d746e1..e7e3382f9 100644 --- a/stm32-metapac-gen/src/lib.rs +++ b/stm32-metapac-gen/src/lib.rs @@ -141,6 +141,21 @@ macro_rules! peripheral_count {{ write!(out, " }}\n").unwrap(); } +fn make_dma_channel_counts(out: &mut String, data: &HashMap) { + write!(out, + "#[macro_export] +macro_rules! dma_channels_count {{ + ").unwrap(); + for (name, count) in data { + write!(out, + "({}) => ({});\n", + name, count, + ).unwrap(); + } + write!(out, + " }}\n").unwrap(); +} + fn make_table(out: &mut String, name: &str, data: &Vec>) { write!( out, @@ -256,6 +271,7 @@ pub fn gen(options: Options) { 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 @@ -267,8 +283,6 @@ pub fn gen(options: Options) { let gpio_base = core.peripherals.get(&"GPIOA".to_string()).unwrap().address; let gpio_stride = 0x400; - - let number_suffix_re = Regex::new("^(.*?)[0-9]*$").unwrap(); for (name, p) in &core.peripherals { @@ -460,6 +474,12 @@ pub fn gen(options: Options) { } } } + + let dma_peri_name = channel_info.dma.clone(); + dma_channel_counts.insert( + dma_peri_name.clone(), + dma_channel_counts.get(&dma_peri_name).map_or(1, |v| v + 1), + ); } for (name, &num) in &core.interrupts { @@ -511,6 +531,7 @@ pub fn gen(options: Options) { 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); for (module, version) in peripheral_versions { all_peripheral_versions.insert((module.clone(), version.clone()));