diff --git a/embassy-stm32/build.rs b/embassy-stm32/build.rs index cefd7434a..ff91f93de 100644 --- a/embassy-stm32/build.rs +++ b/embassy-stm32/build.rs @@ -1,5 +1,6 @@ use std::collections::HashMap; use std::env; +use std::fmt::Write; use std::fs; use std::path::PathBuf; @@ -43,6 +44,9 @@ fn main() { }; ); + // ======== + // Generate singletons + let mut singletons: Vec = Vec::new(); for p in peripherals { match p.kind.as_str() { @@ -90,17 +94,66 @@ fn main() { }; } - let out_dir = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); - let out_file = out_dir.join("generated.rs").to_string_lossy().to_string(); - fs::write( - out_file, - format!( - "embassy_hal_common::peripherals!({});", - singletons.join(",") - ), + let mut generated = String::new(); + write!( + &mut generated, + "embassy_hal_common::peripherals!({});\n", + singletons.join(",") ) .unwrap(); + // ======== + // Generate DMA IRQs. + // This can't be done with macrotables alone because in many chips, one irq is shared between many + // channels, so we have to deduplicate them. + + #[allow(unused_mut)] + let mut dma_irqs: Vec = Vec::new(); + #[allow(unused_mut)] + let mut bdma_irqs: Vec = Vec::new(); + + stm32_metapac::interrupts! { + ($peri:ident, dma, $block:ident, $signal_name:ident, $irq:ident) => { + dma_irqs.push(stringify!($irq).to_string()); + }; + ($peri:ident, bdma, $block:ident, $signal_name:ident, $irq:ident) => { + bdma_irqs.push(stringify!($irq).to_string()); + }; + } + + dma_irqs.sort(); + dma_irqs.dedup(); + bdma_irqs.sort(); + bdma_irqs.dedup(); + + for irq in dma_irqs { + write!( + &mut generated, + "#[crate::interrupt] unsafe fn {} () {{ crate::dma::dma::on_irq(); }}\n", + irq + ) + .unwrap(); + } + + for irq in bdma_irqs { + write!( + &mut generated, + "#[crate::interrupt] unsafe fn {} () {{ crate::dma::bdma::on_irq(); }}\n", + irq + ) + .unwrap(); + } + + // ======== + // Write generated.rs + + let out_dir = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); + let out_file = out_dir.join("generated.rs").to_string_lossy().to_string(); + fs::write(out_file, &generated).unwrap(); + + // ======== + // Multicore + let mut s = chip_name.split('_'); let mut chip_name: String = s.next().unwrap().to_string(); let core_name = if let Some(c) = s.next() { @@ -125,6 +178,9 @@ fn main() { println!("cargo:rustc-cfg={}", &chip_name[..chip_name.len() - 2]); } + // ======== + // stm32f3 wildcard features used in RCC + if chip_name.starts_with("stm32f3") { println!("cargo:rustc-cfg={}x{}", &chip_name[..9], &chip_name[10..11]); } diff --git a/embassy-stm32/src/dma/bdma.rs b/embassy-stm32/src/dma/bdma.rs index e06ce8c36..ebb0467dc 100644 --- a/embassy-stm32/src/dma/bdma.rs +++ b/embassy-stm32/src/dma/bdma.rs @@ -7,7 +7,6 @@ use embassy::interrupt::{Interrupt, InterruptExt}; use embassy::waitqueue::AtomicWaker; use crate::dma::Request; -use crate::interrupt; use crate::pac; use crate::pac::bdma::vals; use crate::rcc::sealed::RccPeripheral; @@ -53,7 +52,7 @@ macro_rules! dma_num { }; } -unsafe fn on_irq() { +pub(crate) unsafe fn on_irq() { pac::peripherals! { (bdma, $dma:ident) => { let isr = pac::$dma.isr().read(); @@ -170,15 +169,6 @@ pac::dma_channels! { }; } -pac::interrupts! { - ($peri:ident, bdma, $block:ident, $signal_name:ident, $irq:ident) => { - #[crate::interrupt] - unsafe fn $irq () { - on_irq() - } - }; -} - mod low_level_api { use super::*; diff --git a/embassy-stm32/src/dma/dma.rs b/embassy-stm32/src/dma/dma.rs index 8e48bb26f..21623b90c 100644 --- a/embassy-stm32/src/dma/dma.rs +++ b/embassy-stm32/src/dma/dma.rs @@ -47,7 +47,7 @@ macro_rules! dma_num { }; } -unsafe fn on_irq() { +pub(crate) unsafe fn on_irq() { pac::peripherals! { (dma, $dma:ident) => { for isrn in 0..2 { @@ -162,15 +162,6 @@ pac::dma_channels! { }; } -pac::interrupts! { - ($peri:ident, dma, $block:ident, $signal_name:ident, $irq:ident) => { - #[crate::interrupt] - unsafe fn $irq () { - on_irq() - } - }; -} - mod low_level_api { use super::*; diff --git a/embassy-stm32/src/dma/mod.rs b/embassy-stm32/src/dma/mod.rs index 3b22faca7..1c9661561 100644 --- a/embassy-stm32/src/dma/mod.rs +++ b/embassy-stm32/src/dma/mod.rs @@ -1,7 +1,7 @@ #[cfg(bdma)] -mod bdma; +pub(crate) mod bdma; #[cfg(dma)] -mod dma; +pub(crate) mod dma; #[cfg(dmamux)] mod dmamux;