stm32: Use build.rs to generate a more coarse feature

This commit is contained in:
Thales Fragoso 2021-07-31 02:20:37 -03:00
parent 16d5294817
commit 21e3acaa00
4 changed files with 17 additions and 255 deletions

View File

@ -9,7 +9,7 @@ fn main() {
.expect("No stm32xx Cargo feature enabled") .expect("No stm32xx Cargo feature enabled")
.strip_prefix("CARGO_FEATURE_") .strip_prefix("CARGO_FEATURE_")
.unwrap() .unwrap()
.to_ascii_uppercase(); .to_ascii_lowercase();
let out_dir = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); let out_dir = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
let out_file = out_dir.join("generated.rs").to_string_lossy().to_string(); 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=build.rs");
println!("cargo:rerun-if-changed=gen.py"); println!("cargo:rerun-if-changed=gen.py");
} }

View File

@ -1,5 +1,5 @@
#[cfg_attr(any(pwr_h7, pwr_h7smps), path = "h7.rs")] #[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; mod _version;
pub use _version::*; pub use _version::*;

View File

@ -1,268 +1,21 @@
#[cfg(any( #[cfg(stm32f401)]
feature = "stm32f401cb",
feature = "stm32f401cc",
feature = "stm32f401cd",
feature = "stm32f401ce",
feature = "stm32f401rb",
feature = "stm32f401rc",
feature = "stm32f401rd",
feature = "stm32f401re",
feature = "stm32f401vb",
feature = "stm32f401vc",
feature = "stm32f401vd",
feature = "stm32f401ve",
))]
pub(crate) const SYSCLK_MAX: u32 = 84_000_000; pub(crate) const SYSCLK_MAX: u32 = 84_000_000;
#[cfg(any( #[cfg(any(stm32f405, stm32f407, stm32f415, stm32f417,))]
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",
))]
pub(crate) const SYSCLK_MAX: u32 = 168_000_000; pub(crate) const SYSCLK_MAX: u32 = 168_000_000;
#[cfg(any( #[cfg(any(stm32f410, stm32f411, stm32f412, stm32f413, stm32f423,))]
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",
))]
pub(crate) const SYSCLK_MAX: u32 = 100_000_000; pub(crate) const SYSCLK_MAX: u32 = 100_000_000;
#[cfg(any( #[cfg(any(
feature = "stm32f427ag", stm32f427, stm32f429, stm32f437, stm32f439, stm32f446, stm32f469, stm32f479,
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",
))] ))]
pub(crate) const SYSCLK_MAX: u32 = 180_000_000; pub(crate) const SYSCLK_MAX: u32 = 180_000_000;
#[cfg(any( #[cfg(any(stm32f401, stm32f410, stm32f411, stm32f412, stm32f413, stm32f423,))]
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",
))]
pub(crate) const PCLK2_MAX: u32 = SYSCLK_MAX; pub(crate) const PCLK2_MAX: u32 = SYSCLK_MAX;
#[cfg(not(any( #[cfg(not(any(stm32f401, stm32f410, stm32f411, stm32f412, stm32f413, stm32f423,)))]
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",
)))]
pub(crate) const PCLK2_MAX: u32 = SYSCLK_MAX / 2; pub(crate) const PCLK2_MAX: u32 = SYSCLK_MAX / 2;
pub(crate) const PCLK1_MAX: u32 = PCLK2_MAX / 2; pub(crate) const PCLK1_MAX: u32 = PCLK2_MAX / 2;