From c6799c2921780254319d293d37f33161f5fd1832 Mon Sep 17 00:00:00 2001 From: i509VCB Date: Thu, 2 Oct 2025 17:02:20 -0500 Subject: mspm0: add mspm0h321x support This also changes selection of GPIO interrupt type to be calculated by the buildscript. H321x is yet another exception with GPIOB being a physical interrupt rather than part of an interrupt group. H3215/6 are true 5V parts. I wonder if that is a first for an embassy hal --- embassy-mspm0/CHANGELOG.md | 3 ++- embassy-mspm0/Cargo.toml | 17 +++++++++------- embassy-mspm0/build.rs | 50 ++++++++++++++++++++++++++++++++++++++-------- embassy-mspm0/src/gpio.rs | 17 ++++++++++------ embassy-mspm0/src/i2c.rs | 4 ++-- 5 files changed, 67 insertions(+), 24 deletions(-) diff --git a/embassy-mspm0/CHANGELOG.md b/embassy-mspm0/CHANGELOG.md index 40abca38b..948f0205d 100644 --- a/embassy-mspm0/CHANGELOG.md +++ b/embassy-mspm0/CHANGELOG.md @@ -14,4 +14,5 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - feat: Add MSPM0C1105/C1106 support - feat: Add adc implementation (#4646) - fix: gpio OutputOpenDrain config (#4735) -- fix: add MSPM0C1106 to build test matrix \ No newline at end of file +- fix: add MSPM0C1106 to build test matrix +- feat: add MSPM0H3216 support diff --git a/embassy-mspm0/Cargo.toml b/embassy-mspm0/Cargo.toml index 7245cd100..df6176ff6 100644 --- a/embassy-mspm0/Cargo.toml +++ b/embassy-mspm0/Cargo.toml @@ -16,17 +16,18 @@ publish = false build = [ {target = "thumbv6m-none-eabi", features = ["defmt", "mspm0c1104dgs20", "time-driver-any"]}, {target = "thumbv6m-none-eabi", features = ["defmt", "mspm0c1106rgz", "time-driver-any"]}, + {target = "thumbv6m-none-eabi", features = ["defmt", "mspm0g1107ycj", "time-driver-any"]}, + {target = "thumbv6m-none-eabi", features = ["defmt", "mspm0g1505pt", "time-driver-any"]}, + {target = "thumbv6m-none-eabi", features = ["defmt", "mspm0g1519rhb", "time-driver-any"]}, + {target = "thumbv6m-none-eabi", features = ["defmt", "mspm0g3105rhb", "time-driver-any"]}, {target = "thumbv6m-none-eabi", features = ["defmt", "mspm0g3507pm", "time-driver-any"]}, {target = "thumbv6m-none-eabi", features = ["defmt", "mspm0g3519pz", "time-driver-any"]}, + {target = "thumbv6m-none-eabi", features = ["defmt", "mspm0h3216pt", "time-driver-any"]}, {target = "thumbv6m-none-eabi", features = ["defmt", "mspm0l1306rhb", "time-driver-any"]}, {target = "thumbv6m-none-eabi", features = ["defmt", "mspm0l2228pn", "time-driver-any"]}, {target = "thumbv6m-none-eabi", features = ["defmt", "mspm0l1345dgs28", "time-driver-any"]}, {target = "thumbv6m-none-eabi", features = ["defmt", "mspm0l1106dgs28", "time-driver-any"]}, - {target = "thumbv6m-none-eabi", features = ["defmt", "mspm0l1228pm", "time-driver-any"]}, - {target = "thumbv6m-none-eabi", features = ["defmt", "mspm0g1107ycj", "time-driver-any"]}, - {target = "thumbv6m-none-eabi", features = ["defmt", "mspm0g3105rhb", "time-driver-any"]}, - {target = "thumbv6m-none-eabi", features = ["defmt", "mspm0g1505pt", "time-driver-any"]}, - {target = "thumbv6m-none-eabi", features = ["defmt", "mspm0g1519rhb", "time-driver-any"]}, + {target = "thumbv6m-none-eabi", features = ["defmt", "mspm0l1228pt", "time-driver-any"]}, ] [package.metadata.embassy_docs] @@ -38,6 +39,7 @@ flavors = [ { regex_feature = "mspm0c.*", target = "thumbv6m-none-eabi" }, { regex_feature = "mspm0l.*", target = "thumbv6m-none-eabi" }, { regex_feature = "mspm0g.*", target = "thumbv6m-none-eabi" }, + { regex_feature = "mspm0h.*", target = "thumbv6m-none-eabi" }, ] [package.metadata.docs.rs] @@ -70,7 +72,7 @@ cortex-m = "0.7.6" critical-section = "1.2.0" # mspm0-metapac = { version = "" } -mspm0-metapac = { git = "https://github.com/mspm0-rs/mspm0-data-generated/", tag = "mspm0-data-d7bf3d01ac0780e716a45b0474234d39443dc5cf" } +mspm0-metapac = { git = "https://github.com/mspm0-rs/mspm0-data-generated/", tag = "mspm0-data-e7de4103a0713772695ffcad52c3c2f07414dc29" } [build-dependencies] proc-macro2 = "1.0.94" @@ -78,7 +80,7 @@ quote = "1.0.40" cfg_aliases = "0.2.1" # mspm0-metapac = { version = "", default-features = false, features = ["metadata"] } -mspm0-metapac = { git = "https://github.com/mspm0-rs/mspm0-data-generated/", tag = "mspm0-data-d7bf3d01ac0780e716a45b0474234d39443dc5cf", default-features = false, features = ["metadata"] } +mspm0-metapac = { git = "https://github.com/mspm0-rs/mspm0-data-generated/", tag = "mspm0-data-e7de4103a0713772695ffcad52c3c2f07414dc29", default-features = false, features = ["metadata"] } [features] default = ["rt"] @@ -244,6 +246,7 @@ mspm0g3519pn = ["mspm0-metapac/mspm0g3519pn"] mspm0g3519pz = ["mspm0-metapac/mspm0g3519pz"] mspm0g3519rgz = ["mspm0-metapac/mspm0g3519rgz"] mspm0g3519rhb = ["mspm0-metapac/mspm0g3519rhb"] +mspm0h3216pt = ["mspm0-metapac/mspm0h3216pt"] mspm0l1105dgs20 = ["mspm0-metapac/mspm0l1105dgs20"] mspm0l1105dgs28 = ["mspm0-metapac/mspm0l1105dgs28"] mspm0l1105dyy = ["mspm0-metapac/mspm0l1105dyy"] diff --git a/embassy-mspm0/build.rs b/embassy-mspm0/build.rs index 93ea81ac3..1d118ad66 100644 --- a/embassy-mspm0/build.rs +++ b/embassy-mspm0/build.rs @@ -16,14 +16,15 @@ use quote::{format_ident, quote}; mod common; fn main() { - generate_code(); - interrupt_group_linker_magic(); -} - -fn generate_code() { let mut cfgs = common::CfgSet::new(); common::set_target_cfgs(&mut cfgs); + generate_code(&mut cfgs); + select_gpio_features(&mut cfgs); + interrupt_group_linker_magic(); +} + +fn generate_code(cfgs: &mut CfgSet) { #[cfg(any(feature = "rt"))] println!( "cargo:rustc-link-search={}", @@ -53,9 +54,9 @@ fn generate_code() { cfgs.declare_all(&get_chip_cfgs(&chip)); } - let mut singletons = get_singletons(&mut cfgs); + let mut singletons = get_singletons(cfgs); - time_driver(&mut singletons, &mut cfgs); + time_driver(&mut singletons, cfgs); let mut g = TokenStream::new(); @@ -68,7 +69,7 @@ fn generate_code() { g.extend(generate_pin_trait_impls()); g.extend(generate_groups()); g.extend(generate_dma_channel_count()); - g.extend(generate_adc_constants(&mut cfgs)); + g.extend(generate_adc_constants(cfgs)); let out_dir = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); let out_file = out_dir.join("_generated.rs").to_string_lossy().to_string(); @@ -115,6 +116,10 @@ fn get_chip_cfgs(chip_name: &str) -> Vec { cfgs.push("mspm0g351x".to_string()); } + if chip_name.starts_with("mspm0h321") { + cfgs.push("mspm0h321x".to_string()); + } + if chip_name.starts_with("mspm0l110") { cfgs.push("mspm0l110x".to_string()); } @@ -646,6 +651,35 @@ fn generate_pin_trait_impls() -> TokenStream { } } +fn select_gpio_features(cfgs: &mut CfgSet) { + cfgs.declare_all(&[ + "gpioa_interrupt", + "gpioa_group", + "gpiob_interrupt", + "gpiob_group", + "gpioc_group", + ]); + + for interrupt in METADATA.interrupts.iter() { + match interrupt.name { + "GPIOA" => cfgs.enable("gpioa_interrupt"), + "GPIOB" => cfgs.enable("gpiob_interrupt"), + _ => (), + } + } + + for group in METADATA.interrupt_groups.iter() { + for interrupt in group.interrupts { + match interrupt.name { + "GPIOA" => cfgs.enable("gpioa_group"), + "GPIOB" => cfgs.enable("gpiob_group"), + "GPIOC" => cfgs.enable("gpioc_group"), + _ => (), + } + } + } +} + /// rustfmt a given path. /// Failures are logged to stderr and ignored. fn rustfmt(path: impl AsRef) { diff --git a/embassy-mspm0/src/gpio.rs b/embassy-mspm0/src/gpio.rs index 13da4f30b..d8eb42dc2 100644 --- a/embassy-mspm0/src/gpio.rs +++ b/embassy-mspm0/src/gpio.rs @@ -10,7 +10,7 @@ use embassy_sync::waitqueue::AtomicWaker; use crate::pac::gpio::vals::*; use crate::pac::gpio::{self}; -#[cfg(all(feature = "rt", any(mspm0c110x, mspm0c1105_c1106, mspm0l110x)))] +#[cfg(all(feature = "rt", any(gpioa_interrupt, gpiob_interrupt)))] use crate::pac::interrupt; use crate::pac::{self}; @@ -1110,16 +1110,21 @@ fn irq_handler(gpio: gpio::Gpio, wakers: &[AtomicWaker; 32]) { } } +#[cfg(all(gpioa_interrupt, gpioa_group))] +compile_error!("gpioa_interrupt and gpioa_group are mutually exclusive cfgs"); +#[cfg(all(gpiob_interrupt, gpiob_group))] +compile_error!("gpiob_interrupt and gpiob_group are mutually exclusive cfgs"); + // C110x and L110x have a dedicated interrupts just for GPIOA. // // These chips do not have a GROUP1 interrupt. -#[cfg(all(feature = "rt", any(mspm0c110x, mspm0c1105_c1106, mspm0l110x)))] +#[cfg(all(feature = "rt", gpioa_interrupt))] #[interrupt] fn GPIOA() { irq_handler(pac::GPIOA, &PORTA_WAKERS); } -#[cfg(all(feature = "rt", mspm0c1105_c1106))] +#[cfg(all(feature = "rt", gpiob_interrupt))] #[interrupt] fn GPIOB() { irq_handler(pac::GPIOB, &PORTB_WAKERS); @@ -1129,21 +1134,21 @@ fn GPIOB() { // // Defining these as no_mangle is required so that the linker will pick these over the default handler. -#[cfg(all(feature = "rt", not(any(mspm0c110x, mspm0c1105_c1106, mspm0l110x))))] +#[cfg(all(feature = "rt", gpioa_group))] #[unsafe(no_mangle)] #[allow(non_snake_case)] fn GPIOA() { irq_handler(pac::GPIOA, &PORTA_WAKERS); } -#[cfg(all(feature = "rt", gpio_pb, not(mspm0c1105_c1106)))] +#[cfg(all(feature = "rt", gpiob_group))] #[unsafe(no_mangle)] #[allow(non_snake_case)] fn GPIOB() { irq_handler(pac::GPIOB, &PORTB_WAKERS); } -#[cfg(all(feature = "rt", gpio_pc))] +#[cfg(all(feature = "rt", gpioc_group))] #[allow(non_snake_case)] #[unsafe(no_mangle)] fn GPIOC() { diff --git a/embassy-mspm0/src/i2c.rs b/embassy-mspm0/src/i2c.rs index a12b4b4a2..192527dd2 100644 --- a/embassy-mspm0/src/i2c.rs +++ b/embassy-mspm0/src/i2c.rs @@ -206,8 +206,8 @@ impl Config { } #[cfg(any( - mspm0g110x, mspm0g150x, mspm0g151x, mspm0g310x, mspm0g350x, mspm0g351x, mspm0l110x, mspm0l122x, mspm0l130x, - mspm0l134x, mspm0l222x + mspm0g110x, mspm0g150x, mspm0g151x, mspm0g310x, mspm0g350x, mspm0g351x, mspm0h321x, mspm0l110x, mspm0l122x, + mspm0l130x, mspm0l134x, mspm0l222x ))] fn calculate_clock_source(&self) -> u32 { // Assume that BusClk has default value. -- cgit