aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuliDi <[email protected]>2023-09-13 21:16:27 +0200
committerJuliDi <[email protected]>2023-10-01 12:30:34 +0200
commit5924cc8b49e683c94873523ae97daf7d5ef5a5d5 (patch)
tree248217f626a1bd704d90fe12a1f0c0fbd30d0955
parent7bc57ca3f79b4b40ea11b11d34d82d933b198fba (diff)
handle _C pins
-rw-r--r--embassy-stm32/Cargo.toml16
-rw-r--r--embassy-stm32/build.rs61
-rw-r--r--embassy-stm32/src/lib.rs12
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"]
134time-driver-tim15 = ["_time-driver"] 134time-driver-tim15 = ["_time-driver"]
135 135
136 136
137#! ## Analog Switch Pins (Pxy_C) on STM32H7 series
138#! Get `PXY` and `PXY_C` singletons. Digital impls are on `PXY`, Analog impls are on `PXY_C`
139#! If disabled, you get only the `PXY` singleton. It has both digital and analog impls.
140
141## Split PA0
142split-pa0 = ["_split-pins-enabled"]
143## Split PA1
144split-pa1 = ["_split-pins-enabled"]
145## Split PC2
146split-pc2 = ["_split-pins-enabled"]
147## Split PC3
148split-pc3 = ["_split-pins-enabled"]
149
150## internal use only
151_split-pins-enabled = []
152
137#! ## Chip-selection features 153#! ## Chip-selection features
138#! Select your chip by specifying the model as a feature, e.g. `stm32c011d6`. 154#! Select your chip by specifying the model as a feature, e.g. `stm32c011d6`.
139#! Check the `Cargo.toml` for the latest list of supported chips. 155#! 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() {
81 singletons.push(c.name.to_string()); 81 singletons.push(c.name.to_string());
82 } 82 }
83 83
84 // Extra analog switch pins available on most H7 chips
85 #[cfg(feature = "split-pa0")]
86 singletons.push("PA0_C".into());
87 #[cfg(feature = "split-pa1")]
88 singletons.push("PA1_C".into());
89 #[cfg(feature = "split-pc2")]
90 singletons.push("PC2_C".into());
91 #[cfg(feature = "split-pc3")]
92 singletons.push("PC3_C".into());
93
84 // ======== 94 // ========
85 // Handle time-driver-XXXX features. 95 // Handle time-driver-XXXX features.
86 96
@@ -679,7 +689,31 @@ fn main() {
679 let key = (regs.kind, pin.signal); 689 let key = (regs.kind, pin.signal);
680 if let Some(tr) = signals.get(&key) { 690 if let Some(tr) = signals.get(&key) {
681 let mut peri = format_ident!("{}", p.name); 691 let mut peri = format_ident!("{}", p.name);
682 let pin_name = format_ident!("{}", pin.pin); 692 let pin_name = {
693 #[allow(unused_mut)]
694 let mut pin_name = pin.pin;
695
696 #[cfg(not(feature = "split-pa0"))]
697 if pin.pin == "PA0_C" {
698 pin_name = "PA0";
699 }
700 #[cfg(not(feature = "split-pa1"))]
701 if pin.pin == "PA1_C" {
702 pin_name = "PA1";
703 }
704
705 #[cfg(not(feature = "split-pc2"))]
706 if pin.pin == "PC2_C" {
707 pin_name = "PC2";
708 }
709 #[cfg(not(feature = "split-pc3"))]
710 if pin.pin == "PC3_C" {
711 pin_name = "PC3";
712 }
713
714 format_ident!("{}", pin_name)
715 };
716
683 let af = pin.af.unwrap_or(0); 717 let af = pin.af.unwrap_or(0);
684 718
685 // MCO is special 719 // MCO is special
@@ -716,7 +750,30 @@ fn main() {
716 } 750 }
717 751
718 let peri = format_ident!("{}", p.name); 752 let peri = format_ident!("{}", p.name);
719 let pin_name = format_ident!("{}", pin.pin); 753 let pin_name = {
754 #[allow(unused_mut)]
755 let mut pin_name = pin.pin;
756
757 #[cfg(not(feature = "split-pa0"))]
758 if pin.pin == "PA0_C" {
759 pin_name = "PA0";
760 }
761 #[cfg(not(feature = "split-pa1"))]
762 if pin.pin == "PA1_C" {
763 pin_name = "PA1";
764 }
765
766 #[cfg(not(feature = "split-pc2"))]
767 if pin.pin == "PC2_C" {
768 pin_name = "PC2";
769 }
770 #[cfg(not(feature = "split-pc3"))]
771 if pin.pin == "PC3_C" {
772 pin_name = "PC3";
773 }
774
775 format_ident!("{}", pin_name)
776 };
720 777
721 // H7 has differential voltage measurements 778 // H7 has differential voltage measurements
722 let ch: Option<u8> = if pin.signal.starts_with("INP") { 779 let ch: Option<u8> = 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 {
191 peripherals::FLASH::enable(); 191 peripherals::FLASH::enable();
192 192
193 unsafe { 193 unsafe {
194 #[cfg(feature = "_split-pins-enabled")]
195 crate::pac::SYSCFG.pmcr().modify(|pmcr| {
196 #[cfg(feature = "split-pa0")]
197 pmcr.set_pa0so(true);
198 #[cfg(feature = "split-pa1")]
199 pmcr.set_pa1so(true);
200 #[cfg(feature = "split-pc2")]
201 pmcr.set_pc2so(true);
202 #[cfg(feature = "split-pc3")]
203 pmcr.set_pc3so(true);
204 });
205
194 gpio::init(); 206 gpio::init();
195 dma::init( 207 dma::init(
196 #[cfg(bdma)] 208 #[cfg(bdma)]