Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[STM32] Handle STM32H7 "_C" pins #1895

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/ci/build-stable.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ export RUSTUP_HOME=/ci/cache/rustup
export CARGO_HOME=/ci/cache/cargo
export CARGO_TARGET_DIR=/ci/cache/target

# needed for "dumb HTTP" transport support
# used when pointing stm32-metapac to a CI-built one.
export CARGO_NET_GIT_FETCH_WITH_CLI=true

hashtime restore /ci/cache/filetime.json || true
hashtime save /ci/cache/filetime.json

Expand Down
4 changes: 4 additions & 0 deletions .github/ci/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ if [ -f /ci/secrets/teleprobe-token.txt ]; then
export TELEPROBE_CACHE=/ci/cache/teleprobe_cache.json
fi

# needed for "dumb HTTP" transport support
# used when pointing stm32-metapac to a CI-built one.
export CARGO_NET_GIT_FETCH_WITH_CLI=true

hashtime restore /ci/cache/filetime.json || true
hashtime save /ci/cache/filetime.json

Expand Down
4 changes: 4 additions & 0 deletions .github/ci/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ export RUSTUP_HOME=/ci/cache/rustup
export CARGO_HOME=/ci/cache/cargo
export CARGO_TARGET_DIR=/ci/cache/target

# needed for "dumb HTTP" transport support
# used when pointing stm32-metapac to a CI-built one.
export CARGO_NET_GIT_FETCH_WITH_CLI=true

hashtime restore /ci/cache/filetime.json || true
hashtime save /ci/cache/filetime.json

Expand Down
20 changes: 18 additions & 2 deletions embassy-stm32/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ sdio-host = "0.5.0"
embedded-sdmmc = { git = "https://github.com/embassy-rs/embedded-sdmmc-rs", rev = "a4f293d3a6f72158385f79c98634cb8a14d0d2fc", optional = true }
critical-section = "1.1"
atomic-polyfill = "1.0.1"
stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-4e6a74f69c4bc5d2d4872ba50d805e75bfe55cad" }
stm32-metapac = { git = "https://ci.embassy.dev/jobs/fc52d4c63842/artifacts/generated.git" }
vcell = "0.1.3"
bxcan = "0.7.0"
nb = "1.0.0"
Expand All @@ -77,7 +77,7 @@ critical-section = { version = "1.1", features = ["std"] }
[build-dependencies]
proc-macro2 = "1.0.36"
quote = "1.0.15"
stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-4e6a74f69c4bc5d2d4872ba50d805e75bfe55cad", default-features = false, features = ["metadata"]}
stm32-metapac = { git = "https://ci.embassy.dev/jobs/fc52d4c63842/artifacts/generated.git", default-features = false, features = ["metadata"]}

[features]
default = ["rt"]
Expand Down Expand Up @@ -133,6 +133,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.
Expand Down
92 changes: 89 additions & 3 deletions embassy-stm32/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,59 @@ fn main() {
singletons.push(c.name.to_string());
}

let mut pin_set = std::collections::HashSet::new();
for p in METADATA.peripherals {
for pin in p.pins {
pin_set.insert(pin.pin);
}
}

struct SplitFeature {
feature_name: String,
pin_name_with_c: String,
pin_name_without_c: String,
}

// Extra analog switch pins available on most H7 chips
JuliDi marked this conversation as resolved.
Show resolved Hide resolved
let split_features: Vec<SplitFeature> = vec![
#[cfg(feature = "split-pa0")]
SplitFeature {
feature_name: "split-pa0".to_string(),
pin_name_with_c: "PA0_C".to_string(),
pin_name_without_c: "PA0".to_string(),
},
#[cfg(feature = "split-pa1")]
SplitFeature {
feature_name: "split-pa1".to_string(),
pin_name_with_c: "PA1_C".to_string(),
pin_name_without_c: "PA1".to_string(),
},
#[cfg(feature = "split-pc2")]
SplitFeature {
feature_name: "split-pc2".to_string(),
pin_name_with_c: "PC2_C".to_string(),
pin_name_without_c: "PC2".to_string(),
},
#[cfg(feature = "split-pc3")]
SplitFeature {
feature_name: "split-pc3".to_string(),
pin_name_with_c: "PC3_C".to_string(),
pin_name_without_c: "PC3".to_string(),
},
];

for split_feature in &split_features {
if pin_set.contains(split_feature.pin_name_with_c.as_str()) {
singletons.push(split_feature.pin_name_with_c.clone());
} else {
panic!(
"'{}' feature invalid for this chip! No pin '{}' found.\n
Found pins: {:#?}",
split_feature.feature_name, split_feature.pin_name_with_c, pin_set
)
}
}

// ========
// Handle time-driver-XXXX features.

Expand Down Expand Up @@ -670,7 +723,16 @@ 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 = {
// If we encounter a _C pin but the split_feature for this pin is not enabled, skip it
if pin.pin.ends_with("_C") && !split_features.iter().any(|x| x.pin_name_with_c == pin.pin) {
continue;
}

format_ident!("{}", pin.pin)
};

let af = pin.af.unwrap_or(0);

// MCO is special
Expand Down Expand Up @@ -707,7 +769,13 @@ fn main() {
}

let peri = format_ident!("{}", p.name);
let pin_name = format_ident!("{}", pin.pin);
let pin_name = {
// If we encounter a _C pin but the split_feature for this pin is not enabled, skip it
if pin.pin.ends_with("_C") && !split_features.iter().any(|x| x.pin_name_with_c == pin.pin) {
continue;
}
format_ident!("{}", pin.pin)
};

// H7 has differential voltage measurements
let ch: Option<u8> = if pin.signal.starts_with("INP") {
Expand Down Expand Up @@ -844,13 +912,31 @@ fn main() {

for pin_num in 0u32..16 {
let pin_name = format!("P{}{}", port_letter, pin_num);

pins_table.push(vec![
pin_name,
pin_name.clone(),
p.name.to_string(),
port_num.to_string(),
pin_num.to_string(),
format!("EXTI{}", pin_num),
]);

// If we have the split pins, we need to do a little extra work:
// Add the "_C" variant to the table. The solution is not optimal, though.
// Adding them only when the corresponding GPIOx also appears.
// This should avoid unintended side-effects as much as possible.
#[cfg(feature = "_split-pins-enabled")]
for split_feature in &split_features {
if split_feature.pin_name_without_c == pin_name {
pins_table.push(vec![
split_feature.pin_name_with_c.to_string(),
p.name.to_string(),
port_num.to_string(),
pin_num.to_string(),
format!("EXTI{}", pin_num),
]);
}
}
}
}

Expand Down
12 changes: 12 additions & 0 deletions embassy-stm32/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,18 @@ pub fn init(config: Config) -> Peripherals {
}

unsafe {
#[cfg(feature = "_split-pins-enabled")]
JuliDi marked this conversation as resolved.
Show resolved Hide resolved
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)]
Expand Down