From 5924cc8b49e683c94873523ae97daf7d5ef5a5d5 Mon Sep 17 00:00:00 2001 From: JuliDi <20155974+JuliDi@users.noreply.github.com> Date: Wed, 13 Sep 2023 21:16:27 +0200 Subject: [PATCH] handle _C pins --- embassy-stm32/Cargo.toml | 16 +++++++++++ embassy-stm32/build.rs | 61 ++++++++++++++++++++++++++++++++++++++-- embassy-stm32/src/lib.rs | 12 ++++++++ 3 files changed, 87 insertions(+), 2 deletions(-) diff --git a/embassy-stm32/Cargo.toml b/embassy-stm32/Cargo.toml index 1ef92430f..474ca6cd1 100644 --- a/embassy-stm32/Cargo.toml +++ b/embassy-stm32/Cargo.toml @@ -134,6 +134,22 @@ time-driver-tim12 = ["_time-driver"] time-driver-tim15 = ["_time-driver"] +#! ## Analog Switch Pins (Pxy_C) on STM32H7 series +#! Get `PXY` and `PXY_C` singletons. Digital impls are on `PXY`, Analog impls are on `PXY_C` +#! If disabled, you get only the `PXY` singleton. It has both digital and analog impls. + +## Split PA0 +split-pa0 = ["_split-pins-enabled"] +## Split PA1 +split-pa1 = ["_split-pins-enabled"] +## Split PC2 +split-pc2 = ["_split-pins-enabled"] +## Split PC3 +split-pc3 = ["_split-pins-enabled"] + +## internal use only +_split-pins-enabled = [] + #! ## Chip-selection features #! Select your chip by specifying the model as a feature, e.g. `stm32c011d6`. #! Check the `Cargo.toml` for the latest list of supported chips. diff --git a/embassy-stm32/build.rs b/embassy-stm32/build.rs index ccc9210df..2795f2597 100644 --- a/embassy-stm32/build.rs +++ b/embassy-stm32/build.rs @@ -81,6 +81,16 @@ fn main() { singletons.push(c.name.to_string()); } + // Extra analog switch pins available on most H7 chips + #[cfg(feature = "split-pa0")] + singletons.push("PA0_C".into()); + #[cfg(feature = "split-pa1")] + singletons.push("PA1_C".into()); + #[cfg(feature = "split-pc2")] + singletons.push("PC2_C".into()); + #[cfg(feature = "split-pc3")] + singletons.push("PC3_C".into()); + // ======== // Handle time-driver-XXXX features. @@ -679,7 +689,31 @@ fn main() { let key = (regs.kind, pin.signal); if let Some(tr) = signals.get(&key) { let mut peri = format_ident!("{}", p.name); - let pin_name = format_ident!("{}", pin.pin); + let pin_name = { + #[allow(unused_mut)] + let mut pin_name = pin.pin; + + #[cfg(not(feature = "split-pa0"))] + if pin.pin == "PA0_C" { + pin_name = "PA0"; + } + #[cfg(not(feature = "split-pa1"))] + if pin.pin == "PA1_C" { + pin_name = "PA1"; + } + + #[cfg(not(feature = "split-pc2"))] + if pin.pin == "PC2_C" { + pin_name = "PC2"; + } + #[cfg(not(feature = "split-pc3"))] + if pin.pin == "PC3_C" { + pin_name = "PC3"; + } + + format_ident!("{}", pin_name) + }; + let af = pin.af.unwrap_or(0); // MCO is special @@ -716,7 +750,30 @@ fn main() { } let peri = format_ident!("{}", p.name); - let pin_name = format_ident!("{}", pin.pin); + let pin_name = { + #[allow(unused_mut)] + let mut pin_name = pin.pin; + + #[cfg(not(feature = "split-pa0"))] + if pin.pin == "PA0_C" { + pin_name = "PA0"; + } + #[cfg(not(feature = "split-pa1"))] + if pin.pin == "PA1_C" { + pin_name = "PA1"; + } + + #[cfg(not(feature = "split-pc2"))] + if pin.pin == "PC2_C" { + pin_name = "PC2"; + } + #[cfg(not(feature = "split-pc3"))] + if pin.pin == "PC3_C" { + pin_name = "PC3"; + } + + format_ident!("{}", pin_name) + }; // H7 has differential voltage measurements let ch: Option = if pin.signal.starts_with("INP") { diff --git a/embassy-stm32/src/lib.rs b/embassy-stm32/src/lib.rs index 2718c96da..9dd2f6163 100644 --- a/embassy-stm32/src/lib.rs +++ b/embassy-stm32/src/lib.rs @@ -191,6 +191,18 @@ pub fn init(config: Config) -> Peripherals { peripherals::FLASH::enable(); unsafe { + #[cfg(feature = "_split-pins-enabled")] + crate::pac::SYSCFG.pmcr().modify(|pmcr| { + #[cfg(feature = "split-pa0")] + pmcr.set_pa0so(true); + #[cfg(feature = "split-pa1")] + pmcr.set_pa1so(true); + #[cfg(feature = "split-pc2")] + pmcr.set_pc2so(true); + #[cfg(feature = "split-pc3")] + pmcr.set_pc3so(true); + }); + gpio::init(); dma::init( #[cfg(bdma)]