From 21e3acaa00f405397811c3abf71dbb26ea932896 Mon Sep 17 00:00:00 2001 From: Thales Fragoso Date: Sat, 31 Jul 2021 02:20:37 -0300 Subject: [PATCH] stm32: Use build.rs to generate a more coarse feature --- embassy-stm32/build.rs | 11 +- embassy-stm32/src/pwr/{none.rs => f4.rs} | 0 embassy-stm32/src/pwr/mod.rs | 2 +- embassy-stm32/src/rcc/f4/max.rs | 259 +---------------------- 4 files changed, 17 insertions(+), 255 deletions(-) rename embassy-stm32/src/pwr/{none.rs => f4.rs} (100%) diff --git a/embassy-stm32/build.rs b/embassy-stm32/build.rs index df8af660..a6434a7e 100644 --- a/embassy-stm32/build.rs +++ b/embassy-stm32/build.rs @@ -9,7 +9,7 @@ fn main() { .expect("No stm32xx Cargo feature enabled") .strip_prefix("CARGO_FEATURE_") .unwrap() - .to_ascii_uppercase(); + .to_ascii_lowercase(); let out_dir = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); let out_file = out_dir.join("generated.rs").to_string_lossy().to_string(); @@ -30,6 +30,15 @@ fn main() { }; ); + let mut chip_and_core = chip_name.split('_'); + let chip = chip_and_core.next().expect("Unexpected stm32xx feature"); + + if let Some(core) = chip_and_core.next() { + println!("cargo:rustc-cfg={}_{}", &chip[..(chip.len() - 2)], core); + } else { + println!("cargo:rustc-cfg={}", &chip[..(chip.len() - 2)]); + } + println!("cargo:rerun-if-changed=build.rs"); println!("cargo:rerun-if-changed=gen.py"); } diff --git a/embassy-stm32/src/pwr/none.rs b/embassy-stm32/src/pwr/f4.rs similarity index 100% rename from embassy-stm32/src/pwr/none.rs rename to embassy-stm32/src/pwr/f4.rs diff --git a/embassy-stm32/src/pwr/mod.rs b/embassy-stm32/src/pwr/mod.rs index f0d47ca8..1bb104bd 100644 --- a/embassy-stm32/src/pwr/mod.rs +++ b/embassy-stm32/src/pwr/mod.rs @@ -1,5 +1,5 @@ #[cfg_attr(any(pwr_h7, pwr_h7smps), path = "h7.rs")] -#[cfg_attr(not(any(pwr_h7, pwr_h7smps)), path = "none.rs")] +#[cfg_attr(pwr_f4, path = "f4.rs")] mod _version; pub use _version::*; diff --git a/embassy-stm32/src/rcc/f4/max.rs b/embassy-stm32/src/rcc/f4/max.rs index 03e1e983..dd8de3da 100644 --- a/embassy-stm32/src/rcc/f4/max.rs +++ b/embassy-stm32/src/rcc/f4/max.rs @@ -1,268 +1,21 @@ -#[cfg(any( - feature = "stm32f401cb", - feature = "stm32f401cc", - feature = "stm32f401cd", - feature = "stm32f401ce", - feature = "stm32f401rb", - feature = "stm32f401rc", - feature = "stm32f401rd", - feature = "stm32f401re", - feature = "stm32f401vb", - feature = "stm32f401vc", - feature = "stm32f401vd", - feature = "stm32f401ve", -))] +#[cfg(stm32f401)] pub(crate) const SYSCLK_MAX: u32 = 84_000_000; -#[cfg(any( - feature = "stm32f405oe", - feature = "stm32f405og", - feature = "stm32f405rg", - feature = "stm32f405vg", - feature = "stm32f405zg", - feature = "stm32f407ie", - feature = "stm32f407ig", - feature = "stm32f407ve", - feature = "stm32f407vg", - feature = "stm32f407ze", - feature = "stm32f407zg", - feature = "stm32f415og", - feature = "stm32f415rg", - feature = "stm32f415vg", - feature = "stm32f415zg", - feature = "stm32f417ie", - feature = "stm32f417ig", - feature = "stm32f417ve", - feature = "stm32f417vg", - feature = "stm32f417ze", - feature = "stm32f417zg", -))] +#[cfg(any(stm32f405, stm32f407, stm32f415, stm32f417,))] pub(crate) const SYSCLK_MAX: u32 = 168_000_000; -#[cfg(any( - feature = "stm32f410c8", - feature = "stm32f410cb", - feature = "stm32f410r8", - feature = "stm32f410rb", - feature = "stm32f410t8", - feature = "stm32f410tb", - feature = "stm32f411cc", - feature = "stm32f411ce", - feature = "stm32f411rc", - feature = "stm32f411re", - feature = "stm32f411vc", - feature = "stm32f411ve", - feature = "stm32f412ce", - feature = "stm32f412cg", - feature = "stm32f412re", - feature = "stm32f412rg", - feature = "stm32f412ve", - feature = "stm32f412vg", - feature = "stm32f412ze", - feature = "stm32f412zg", - feature = "stm32f413cg", - feature = "stm32f413ch", - feature = "stm32f413mg", - feature = "stm32f413mh", - feature = "stm32f413rg", - feature = "stm32f413rh", - feature = "stm32f413vg", - feature = "stm32f413vh", - feature = "stm32f413zg", - feature = "stm32f413zh", - feature = "stm32f423ch", - feature = "stm32f423mh", - feature = "stm32f423rh", - feature = "stm32f423vh", - feature = "stm32f423zh", -))] +#[cfg(any(stm32f410, stm32f411, stm32f412, stm32f413, stm32f423,))] pub(crate) const SYSCLK_MAX: u32 = 100_000_000; #[cfg(any( - feature = "stm32f427ag", - feature = "stm32f427ai", - feature = "stm32f427ig", - feature = "stm32f427ii", - feature = "stm32f427vg", - feature = "stm32f427vi", - feature = "stm32f427zg", - feature = "stm32f427zi", - feature = "stm32f429ag", - feature = "stm32f429ai", - feature = "stm32f429be", - feature = "stm32f429bg", - feature = "stm32f429bi", - feature = "stm32f429ie", - feature = "stm32f429ig", - feature = "stm32f429ii", - feature = "stm32f429ne", - feature = "stm32f429ng", - feature = "stm32f429ni", - feature = "stm32f429ve", - feature = "stm32f429vg", - feature = "stm32f429vi", - feature = "stm32f429ze", - feature = "stm32f429zg", - feature = "stm32f429zi", - feature = "stm32f437ai", - feature = "stm32f437ig", - feature = "stm32f437ii", - feature = "stm32f437vg", - feature = "stm32f437vi", - feature = "stm32f437zg", - feature = "stm32f437zi", - feature = "stm32f439ai", - feature = "stm32f439bg", - feature = "stm32f439bi", - feature = "stm32f439ig", - feature = "stm32f439ii", - feature = "stm32f439ng", - feature = "stm32f439ni", - feature = "stm32f439vg", - feature = "stm32f439vi", - feature = "stm32f439zg", - feature = "stm32f439zi", - feature = "stm32f446mc", - feature = "stm32f446me", - feature = "stm32f446rc", - feature = "stm32f446re", - feature = "stm32f446vc", - feature = "stm32f446ve", - feature = "stm32f446zc", - feature = "stm32f446ze", - feature = "stm32f469ae", - feature = "stm32f469ag", - feature = "stm32f469ai", - feature = "stm32f469be", - feature = "stm32f469bg", - feature = "stm32f469bi", - feature = "stm32f469ie", - feature = "stm32f469ig", - feature = "stm32f469ii", - feature = "stm32f469ne", - feature = "stm32f469ng", - feature = "stm32f469ni", - feature = "stm32f469ve", - feature = "stm32f469vg", - feature = "stm32f469vi", - feature = "stm32f469ze", - feature = "stm32f469zg", - feature = "stm32f469zi", - feature = "stm32f479ag", - feature = "stm32f479ai", - feature = "stm32f479bg", - feature = "stm32f479bi", - feature = "stm32f479ig", - feature = "stm32f479ii", - feature = "stm32f479ng", - feature = "stm32f479ni", - feature = "stm32f479vg", - feature = "stm32f479vi", - feature = "stm32f479zg", - feature = "stm32f479zi", + stm32f427, stm32f429, stm32f437, stm32f439, stm32f446, stm32f469, stm32f479, ))] pub(crate) const SYSCLK_MAX: u32 = 180_000_000; -#[cfg(any( - feature = "stm32f401cb", - feature = "stm32f401cc", - feature = "stm32f401cd", - feature = "stm32f401ce", - feature = "stm32f401rb", - feature = "stm32f401rc", - feature = "stm32f401rd", - feature = "stm32f401re", - feature = "stm32f401vb", - feature = "stm32f401vc", - feature = "stm32f401vd", - feature = "stm32f401ve", - feature = "stm32f410c8", - feature = "stm32f410cb", - feature = "stm32f410r8", - feature = "stm32f410rb", - feature = "stm32f410t8", - feature = "stm32f410tb", - feature = "stm32f411cc", - feature = "stm32f411ce", - feature = "stm32f411rc", - feature = "stm32f411re", - feature = "stm32f411vc", - feature = "stm32f411ve", - feature = "stm32f412ce", - feature = "stm32f412cg", - feature = "stm32f412re", - feature = "stm32f412rg", - feature = "stm32f412ve", - feature = "stm32f412vg", - feature = "stm32f412ze", - feature = "stm32f412zg", - feature = "stm32f413cg", - feature = "stm32f413ch", - feature = "stm32f413mg", - feature = "stm32f413mh", - feature = "stm32f413rg", - feature = "stm32f413rh", - feature = "stm32f413vg", - feature = "stm32f413vh", - feature = "stm32f413zg", - feature = "stm32f413zh", - feature = "stm32f423ch", - feature = "stm32f423mh", - feature = "stm32f423rh", - feature = "stm32f423vh", - feature = "stm32f423zh", -))] +#[cfg(any(stm32f401, stm32f410, stm32f411, stm32f412, stm32f413, stm32f423,))] pub(crate) const PCLK2_MAX: u32 = SYSCLK_MAX; -#[cfg(not(any( - feature = "stm32f401cb", - feature = "stm32f401cc", - feature = "stm32f401cd", - feature = "stm32f401ce", - feature = "stm32f401rb", - feature = "stm32f401rc", - feature = "stm32f401rd", - feature = "stm32f401re", - feature = "stm32f401vb", - feature = "stm32f401vc", - feature = "stm32f401vd", - feature = "stm32f401ve", - feature = "stm32f410c8", - feature = "stm32f410cb", - feature = "stm32f410r8", - feature = "stm32f410rb", - feature = "stm32f410t8", - feature = "stm32f410tb", - feature = "stm32f411cc", - feature = "stm32f411ce", - feature = "stm32f411rc", - feature = "stm32f411re", - feature = "stm32f411vc", - feature = "stm32f411ve", - feature = "stm32f412ce", - feature = "stm32f412cg", - feature = "stm32f412re", - feature = "stm32f412rg", - feature = "stm32f412ve", - feature = "stm32f412vg", - feature = "stm32f412ze", - feature = "stm32f412zg", - feature = "stm32f413cg", - feature = "stm32f413ch", - feature = "stm32f413mg", - feature = "stm32f413mh", - feature = "stm32f413rg", - feature = "stm32f413rh", - feature = "stm32f413vg", - feature = "stm32f413vh", - feature = "stm32f413zg", - feature = "stm32f413zh", - feature = "stm32f423ch", - feature = "stm32f423mh", - feature = "stm32f423rh", - feature = "stm32f423vh", - feature = "stm32f423zh", -)))] +#[cfg(not(any(stm32f401, stm32f410, stm32f411, stm32f412, stm32f413, stm32f423,)))] pub(crate) const PCLK2_MAX: u32 = SYSCLK_MAX / 2; pub(crate) const PCLK1_MAX: u32 = PCLK2_MAX / 2;