Merge #501
501: stm32-metapac cleanups r=Dirbaio a=Dirbaio Co-authored-by: Dario Nieuwenhuis <dirbaio@dirbaio.net>
This commit is contained in:
commit
8fea6c94f6
11
.github/workflows/rust.yml
vendored
11
.github/workflows/rust.yml
vendored
@ -12,7 +12,7 @@ env:
|
|||||||
jobs:
|
jobs:
|
||||||
all:
|
all:
|
||||||
runs-on: ubuntu-20.04
|
runs-on: ubuntu-20.04
|
||||||
needs: [build, test, metapac_gen]
|
needs: [build, test]
|
||||||
steps:
|
steps:
|
||||||
- name: Done
|
- name: Done
|
||||||
run: exit 0
|
run: exit 0
|
||||||
@ -45,12 +45,3 @@ jobs:
|
|||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- name: Test
|
- name: Test
|
||||||
run: cd embassy && cargo test
|
run: cd embassy && cargo test
|
||||||
|
|
||||||
metapac_gen:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v2
|
|
||||||
with:
|
|
||||||
submodules: true
|
|
||||||
- name: Generate pregenerated metapac
|
|
||||||
run: cd stm32-metapac-gen; cargo run --release
|
|
||||||
|
9
ci.sh
9
ci.sh
@ -7,6 +7,13 @@ export RUSTFLAGS=-Dwarnings
|
|||||||
|
|
||||||
find -name '*.rs' -not -path '*target*' -not -path '*stm32-metapac-gen/out/*' | xargs rustfmt --check --skip-children --unstable-features --edition 2018
|
find -name '*.rs' -not -path '*target*' -not -path '*stm32-metapac-gen/out/*' | xargs rustfmt --check --skip-children --unstable-features --edition 2018
|
||||||
|
|
||||||
|
# Generate stm32-metapac
|
||||||
|
# for some reason Cargo stomps the cache if we don't specify --target.
|
||||||
|
# This happens with vanilla Cargo, not just cargo-batch. Bug?
|
||||||
|
(cd stm32-metapac-gen; cargo run --release --target x86_64-unknown-linux-gnu)
|
||||||
|
rm -rf stm32-metapac
|
||||||
|
mv stm32-metapac-gen/out stm32-metapac
|
||||||
|
|
||||||
cargo batch \
|
cargo batch \
|
||||||
--- build --release --manifest-path embassy/Cargo.toml --target thumbv7em-none-eabi \
|
--- build --release --manifest-path embassy/Cargo.toml --target thumbv7em-none-eabi \
|
||||||
--- build --release --manifest-path embassy/Cargo.toml --target thumbv7em-none-eabi --features log,executor-agnostic \
|
--- build --release --manifest-path embassy/Cargo.toml --target thumbv7em-none-eabi --features log,executor-agnostic \
|
||||||
@ -28,7 +35,7 @@ cargo batch \
|
|||||||
--- build --release --manifest-path embassy-nrf/Cargo.toml --target thumbv7em-none-eabi --features nrf52840,defmt \
|
--- build --release --manifest-path embassy-nrf/Cargo.toml --target thumbv7em-none-eabi --features nrf52840,defmt \
|
||||||
--- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f411ce,defmt \
|
--- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f411ce,defmt \
|
||||||
--- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f429zi,log \
|
--- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f429zi,log \
|
||||||
--- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32h755zi_cm7,defmt \
|
--- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32h755zi-cm7,defmt \
|
||||||
--- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32l476vg,defmt \
|
--- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32l476vg,defmt \
|
||||||
--- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv6m-none-eabi --features stm32l072cz,defmt \
|
--- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv6m-none-eabi --features stm32l072cz,defmt \
|
||||||
--- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features stm32l151cb-a,defmt \
|
--- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features stm32l151cb-a,defmt \
|
||||||
|
@ -34,8 +34,6 @@ cfg-if = "1.0.0"
|
|||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
stm32-metapac = { version = "0.1.0", path = "../stm32-metapac", default-features = false }
|
stm32-metapac = { version = "0.1.0", path = "../stm32-metapac", default-features = false }
|
||||||
serde = { version = "1.0.130", features = [ "derive" ] }
|
|
||||||
serde_yaml = "0.8.21"
|
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
sdmmc-rs = ["embedded-sdmmc"]
|
sdmmc-rs = ["embedded-sdmmc"]
|
||||||
@ -615,40 +613,40 @@ stm32h743xg = [ "stm32-metapac/stm32h743xg" ]
|
|||||||
stm32h743xi = [ "stm32-metapac/stm32h743xi" ]
|
stm32h743xi = [ "stm32-metapac/stm32h743xi" ]
|
||||||
stm32h743zg = [ "stm32-metapac/stm32h743zg" ]
|
stm32h743zg = [ "stm32-metapac/stm32h743zg" ]
|
||||||
stm32h743zi = [ "stm32-metapac/stm32h743zi" ]
|
stm32h743zi = [ "stm32-metapac/stm32h743zi" ]
|
||||||
stm32h745bg_cm7 = [ "stm32-metapac/stm32h745bg_cm7" ]
|
stm32h745bg-cm7 = [ "stm32-metapac/stm32h745bg-cm7" ]
|
||||||
stm32h745bg_cm4 = [ "stm32-metapac/stm32h745bg_cm4" ]
|
stm32h745bg-cm4 = [ "stm32-metapac/stm32h745bg-cm4" ]
|
||||||
stm32h745bi_cm7 = [ "stm32-metapac/stm32h745bi_cm7" ]
|
stm32h745bi-cm7 = [ "stm32-metapac/stm32h745bi-cm7" ]
|
||||||
stm32h745bi_cm4 = [ "stm32-metapac/stm32h745bi_cm4" ]
|
stm32h745bi-cm4 = [ "stm32-metapac/stm32h745bi-cm4" ]
|
||||||
stm32h745ig_cm7 = [ "stm32-metapac/stm32h745ig_cm7" ]
|
stm32h745ig-cm7 = [ "stm32-metapac/stm32h745ig-cm7" ]
|
||||||
stm32h745ig_cm4 = [ "stm32-metapac/stm32h745ig_cm4" ]
|
stm32h745ig-cm4 = [ "stm32-metapac/stm32h745ig-cm4" ]
|
||||||
stm32h745ii_cm7 = [ "stm32-metapac/stm32h745ii_cm7" ]
|
stm32h745ii-cm7 = [ "stm32-metapac/stm32h745ii-cm7" ]
|
||||||
stm32h745ii_cm4 = [ "stm32-metapac/stm32h745ii_cm4" ]
|
stm32h745ii-cm4 = [ "stm32-metapac/stm32h745ii-cm4" ]
|
||||||
stm32h745xg_cm7 = [ "stm32-metapac/stm32h745xg_cm7" ]
|
stm32h745xg-cm7 = [ "stm32-metapac/stm32h745xg-cm7" ]
|
||||||
stm32h745xg_cm4 = [ "stm32-metapac/stm32h745xg_cm4" ]
|
stm32h745xg-cm4 = [ "stm32-metapac/stm32h745xg-cm4" ]
|
||||||
stm32h745xi_cm7 = [ "stm32-metapac/stm32h745xi_cm7" ]
|
stm32h745xi-cm7 = [ "stm32-metapac/stm32h745xi-cm7" ]
|
||||||
stm32h745xi_cm4 = [ "stm32-metapac/stm32h745xi_cm4" ]
|
stm32h745xi-cm4 = [ "stm32-metapac/stm32h745xi-cm4" ]
|
||||||
stm32h745zg_cm7 = [ "stm32-metapac/stm32h745zg_cm7" ]
|
stm32h745zg-cm7 = [ "stm32-metapac/stm32h745zg-cm7" ]
|
||||||
stm32h745zg_cm4 = [ "stm32-metapac/stm32h745zg_cm4" ]
|
stm32h745zg-cm4 = [ "stm32-metapac/stm32h745zg-cm4" ]
|
||||||
stm32h745zi_cm7 = [ "stm32-metapac/stm32h745zi_cm7" ]
|
stm32h745zi-cm7 = [ "stm32-metapac/stm32h745zi-cm7" ]
|
||||||
stm32h745zi_cm4 = [ "stm32-metapac/stm32h745zi_cm4" ]
|
stm32h745zi-cm4 = [ "stm32-metapac/stm32h745zi-cm4" ]
|
||||||
stm32h747ag_cm7 = [ "stm32-metapac/stm32h747ag_cm7" ]
|
stm32h747ag-cm7 = [ "stm32-metapac/stm32h747ag-cm7" ]
|
||||||
stm32h747ag_cm4 = [ "stm32-metapac/stm32h747ag_cm4" ]
|
stm32h747ag-cm4 = [ "stm32-metapac/stm32h747ag-cm4" ]
|
||||||
stm32h747ai_cm7 = [ "stm32-metapac/stm32h747ai_cm7" ]
|
stm32h747ai-cm7 = [ "stm32-metapac/stm32h747ai-cm7" ]
|
||||||
stm32h747ai_cm4 = [ "stm32-metapac/stm32h747ai_cm4" ]
|
stm32h747ai-cm4 = [ "stm32-metapac/stm32h747ai-cm4" ]
|
||||||
stm32h747bg_cm7 = [ "stm32-metapac/stm32h747bg_cm7" ]
|
stm32h747bg-cm7 = [ "stm32-metapac/stm32h747bg-cm7" ]
|
||||||
stm32h747bg_cm4 = [ "stm32-metapac/stm32h747bg_cm4" ]
|
stm32h747bg-cm4 = [ "stm32-metapac/stm32h747bg-cm4" ]
|
||||||
stm32h747bi_cm7 = [ "stm32-metapac/stm32h747bi_cm7" ]
|
stm32h747bi-cm7 = [ "stm32-metapac/stm32h747bi-cm7" ]
|
||||||
stm32h747bi_cm4 = [ "stm32-metapac/stm32h747bi_cm4" ]
|
stm32h747bi-cm4 = [ "stm32-metapac/stm32h747bi-cm4" ]
|
||||||
stm32h747ig_cm7 = [ "stm32-metapac/stm32h747ig_cm7" ]
|
stm32h747ig-cm7 = [ "stm32-metapac/stm32h747ig-cm7" ]
|
||||||
stm32h747ig_cm4 = [ "stm32-metapac/stm32h747ig_cm4" ]
|
stm32h747ig-cm4 = [ "stm32-metapac/stm32h747ig-cm4" ]
|
||||||
stm32h747ii_cm7 = [ "stm32-metapac/stm32h747ii_cm7" ]
|
stm32h747ii-cm7 = [ "stm32-metapac/stm32h747ii-cm7" ]
|
||||||
stm32h747ii_cm4 = [ "stm32-metapac/stm32h747ii_cm4" ]
|
stm32h747ii-cm4 = [ "stm32-metapac/stm32h747ii-cm4" ]
|
||||||
stm32h747xg_cm7 = [ "stm32-metapac/stm32h747xg_cm7" ]
|
stm32h747xg-cm7 = [ "stm32-metapac/stm32h747xg-cm7" ]
|
||||||
stm32h747xg_cm4 = [ "stm32-metapac/stm32h747xg_cm4" ]
|
stm32h747xg-cm4 = [ "stm32-metapac/stm32h747xg-cm4" ]
|
||||||
stm32h747xi_cm7 = [ "stm32-metapac/stm32h747xi_cm7" ]
|
stm32h747xi-cm7 = [ "stm32-metapac/stm32h747xi-cm7" ]
|
||||||
stm32h747xi_cm4 = [ "stm32-metapac/stm32h747xi_cm4" ]
|
stm32h747xi-cm4 = [ "stm32-metapac/stm32h747xi-cm4" ]
|
||||||
stm32h747zi_cm7 = [ "stm32-metapac/stm32h747zi_cm7" ]
|
stm32h747zi-cm7 = [ "stm32-metapac/stm32h747zi-cm7" ]
|
||||||
stm32h747zi_cm4 = [ "stm32-metapac/stm32h747zi_cm4" ]
|
stm32h747zi-cm4 = [ "stm32-metapac/stm32h747zi-cm4" ]
|
||||||
stm32h750ib = [ "stm32-metapac/stm32h750ib" ]
|
stm32h750ib = [ "stm32-metapac/stm32h750ib" ]
|
||||||
stm32h750vb = [ "stm32-metapac/stm32h750vb" ]
|
stm32h750vb = [ "stm32-metapac/stm32h750vb" ]
|
||||||
stm32h750xb = [ "stm32-metapac/stm32h750xb" ]
|
stm32h750xb = [ "stm32-metapac/stm32h750xb" ]
|
||||||
@ -659,24 +657,24 @@ stm32h753ii = [ "stm32-metapac/stm32h753ii" ]
|
|||||||
stm32h753vi = [ "stm32-metapac/stm32h753vi" ]
|
stm32h753vi = [ "stm32-metapac/stm32h753vi" ]
|
||||||
stm32h753xi = [ "stm32-metapac/stm32h753xi" ]
|
stm32h753xi = [ "stm32-metapac/stm32h753xi" ]
|
||||||
stm32h753zi = [ "stm32-metapac/stm32h753zi" ]
|
stm32h753zi = [ "stm32-metapac/stm32h753zi" ]
|
||||||
stm32h755bi_cm7 = [ "stm32-metapac/stm32h755bi_cm7" ]
|
stm32h755bi-cm7 = [ "stm32-metapac/stm32h755bi-cm7" ]
|
||||||
stm32h755bi_cm4 = [ "stm32-metapac/stm32h755bi_cm4" ]
|
stm32h755bi-cm4 = [ "stm32-metapac/stm32h755bi-cm4" ]
|
||||||
stm32h755ii_cm7 = [ "stm32-metapac/stm32h755ii_cm7" ]
|
stm32h755ii-cm7 = [ "stm32-metapac/stm32h755ii-cm7" ]
|
||||||
stm32h755ii_cm4 = [ "stm32-metapac/stm32h755ii_cm4" ]
|
stm32h755ii-cm4 = [ "stm32-metapac/stm32h755ii-cm4" ]
|
||||||
stm32h755xi_cm7 = [ "stm32-metapac/stm32h755xi_cm7" ]
|
stm32h755xi-cm7 = [ "stm32-metapac/stm32h755xi-cm7" ]
|
||||||
stm32h755xi_cm4 = [ "stm32-metapac/stm32h755xi_cm4" ]
|
stm32h755xi-cm4 = [ "stm32-metapac/stm32h755xi-cm4" ]
|
||||||
stm32h755zi_cm7 = [ "stm32-metapac/stm32h755zi_cm7" ]
|
stm32h755zi-cm7 = [ "stm32-metapac/stm32h755zi-cm7" ]
|
||||||
stm32h755zi_cm4 = [ "stm32-metapac/stm32h755zi_cm4" ]
|
stm32h755zi-cm4 = [ "stm32-metapac/stm32h755zi-cm4" ]
|
||||||
stm32h757ai_cm7 = [ "stm32-metapac/stm32h757ai_cm7" ]
|
stm32h757ai-cm7 = [ "stm32-metapac/stm32h757ai-cm7" ]
|
||||||
stm32h757ai_cm4 = [ "stm32-metapac/stm32h757ai_cm4" ]
|
stm32h757ai-cm4 = [ "stm32-metapac/stm32h757ai-cm4" ]
|
||||||
stm32h757bi_cm7 = [ "stm32-metapac/stm32h757bi_cm7" ]
|
stm32h757bi-cm7 = [ "stm32-metapac/stm32h757bi-cm7" ]
|
||||||
stm32h757bi_cm4 = [ "stm32-metapac/stm32h757bi_cm4" ]
|
stm32h757bi-cm4 = [ "stm32-metapac/stm32h757bi-cm4" ]
|
||||||
stm32h757ii_cm7 = [ "stm32-metapac/stm32h757ii_cm7" ]
|
stm32h757ii-cm7 = [ "stm32-metapac/stm32h757ii-cm7" ]
|
||||||
stm32h757ii_cm4 = [ "stm32-metapac/stm32h757ii_cm4" ]
|
stm32h757ii-cm4 = [ "stm32-metapac/stm32h757ii-cm4" ]
|
||||||
stm32h757xi_cm7 = [ "stm32-metapac/stm32h757xi_cm7" ]
|
stm32h757xi-cm7 = [ "stm32-metapac/stm32h757xi-cm7" ]
|
||||||
stm32h757xi_cm4 = [ "stm32-metapac/stm32h757xi_cm4" ]
|
stm32h757xi-cm4 = [ "stm32-metapac/stm32h757xi-cm4" ]
|
||||||
stm32h757zi_cm7 = [ "stm32-metapac/stm32h757zi_cm7" ]
|
stm32h757zi-cm7 = [ "stm32-metapac/stm32h757zi-cm7" ]
|
||||||
stm32h757zi_cm4 = [ "stm32-metapac/stm32h757zi_cm4" ]
|
stm32h757zi-cm4 = [ "stm32-metapac/stm32h757zi-cm4" ]
|
||||||
stm32h7a3ag = [ "stm32-metapac/stm32h7a3ag" ]
|
stm32h7a3ag = [ "stm32-metapac/stm32h7a3ag" ]
|
||||||
stm32h7a3ai = [ "stm32-metapac/stm32h7a3ai" ]
|
stm32h7a3ai = [ "stm32-metapac/stm32h7a3ai" ]
|
||||||
stm32h7a3ig = [ "stm32-metapac/stm32h7a3ig" ]
|
stm32h7a3ig = [ "stm32-metapac/stm32h7a3ig" ]
|
||||||
@ -1066,10 +1064,10 @@ stm32wb55vc = [ "stm32-metapac/stm32wb55vc" ]
|
|||||||
stm32wb55ve = [ "stm32-metapac/stm32wb55ve" ]
|
stm32wb55ve = [ "stm32-metapac/stm32wb55ve" ]
|
||||||
stm32wb55vg = [ "stm32-metapac/stm32wb55vg" ]
|
stm32wb55vg = [ "stm32-metapac/stm32wb55vg" ]
|
||||||
stm32wb55vy = [ "stm32-metapac/stm32wb55vy" ]
|
stm32wb55vy = [ "stm32-metapac/stm32wb55vy" ]
|
||||||
stm32wl55cc_cm4 = [ "stm32-metapac/stm32wl55cc_cm4" ]
|
stm32wl55cc-cm4 = [ "stm32-metapac/stm32wl55cc-cm4" ]
|
||||||
stm32wl55cc_cm0p = [ "stm32-metapac/stm32wl55cc_cm0p" ]
|
stm32wl55cc-cm0p = [ "stm32-metapac/stm32wl55cc-cm0p" ]
|
||||||
stm32wl55jc_cm4 = [ "stm32-metapac/stm32wl55jc_cm4" ]
|
stm32wl55jc-cm4 = [ "stm32-metapac/stm32wl55jc-cm4" ]
|
||||||
stm32wl55jc_cm0p = [ "stm32-metapac/stm32wl55jc_cm0p" ]
|
stm32wl55jc-cm0p = [ "stm32-metapac/stm32wl55jc-cm0p" ]
|
||||||
stm32wl55uc_cm4 = [ "stm32-metapac/stm32wl55uc_cm4" ]
|
stm32wl55uc-cm4 = [ "stm32-metapac/stm32wl55uc-cm4" ]
|
||||||
stm32wl55uc_cm0p = [ "stm32-metapac/stm32wl55uc_cm0p" ]
|
stm32wl55uc-cm0p = [ "stm32-metapac/stm32wl55uc-cm0p" ]
|
||||||
# END GENERATED FEATURES
|
# END GENERATED FEATURES
|
||||||
|
@ -8,7 +8,7 @@ resolver = "2"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt"] }
|
embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt"] }
|
||||||
embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] }
|
embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] }
|
||||||
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "stm32wl55jc_cm4", "time-driver-tim2", "memory-x", "subghz", "unstable-pac"] }
|
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "stm32wl55jc-cm4", "time-driver-tim2", "memory-x", "subghz", "unstable-pac"] }
|
||||||
embassy-hal-common = {version = "0.1.0", path = "../../embassy-hal-common" }
|
embassy-hal-common = {version = "0.1.0", path = "../../embassy-hal-common" }
|
||||||
embassy-lora = { version = "0.1.0", path = "../../embassy-lora", features = ["stm32wl", "time"] }
|
embassy-lora = { version = "0.1.0", path = "../../embassy-lora", features = ["stm32wl", "time"] }
|
||||||
|
|
||||||
|
@ -123,7 +123,7 @@ pub fn stm32_metapac_needed_data(names_and_cores: &[(String, Vec<String>)]) -> S
|
|||||||
for (chip_name, cores) in names_and_cores {
|
for (chip_name, cores) in names_and_cores {
|
||||||
if cores.len() > 1 {
|
if cores.len() > 1 {
|
||||||
for core_name in cores {
|
for core_name in cores {
|
||||||
result += &format!("{}_{} = []\n", chip_name, core_name);
|
result += &format!("{}-{} = []\n", chip_name, core_name);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
result += &format!("{} = []\n", chip_name);
|
result += &format!("{} = []\n", chip_name);
|
||||||
|
@ -1,30 +1,30 @@
|
|||||||
use std::env;
|
use std::env;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let _chip_name = env::vars_os()
|
let crate_dir = PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").unwrap());
|
||||||
|
|
||||||
|
let chip_core_name = env::vars_os()
|
||||||
.map(|(a, _)| a.to_string_lossy().to_string())
|
.map(|(a, _)| a.to_string_lossy().to_string())
|
||||||
.find(|x| x.starts_with("CARGO_FEATURE_STM32"))
|
.find(|x| x.starts_with("CARGO_FEATURE_STM32"))
|
||||||
.expect("No stm32xx Cargo feature enabled")
|
.expect("No stm32xx Cargo feature enabled")
|
||||||
.strip_prefix("CARGO_FEATURE_")
|
.strip_prefix("CARGO_FEATURE_")
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.to_ascii_lowercase();
|
.to_ascii_lowercase()
|
||||||
|
.replace('_', "-");
|
||||||
|
|
||||||
let mut s = chip_name.split('_');
|
println!(
|
||||||
let mut chip_name: String = s.next().unwrap().to_string();
|
"cargo:rustc-link-search={}/src/chips/{}",
|
||||||
if let Some(c) = s.next() {
|
crate_dir.display(),
|
||||||
if !c.starts_with("CM") {
|
chip_core_name,
|
||||||
chip_name.push('-');
|
);
|
||||||
} else {
|
|
||||||
chip_name.push('_');
|
|
||||||
}
|
|
||||||
chip_name.push_str(c);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "memory-x")]
|
#[cfg(feature = "memory-x")]
|
||||||
println!("cargo:rustc-link-search=src/chips/{}/memory_x/", _chip_name);
|
println!(
|
||||||
|
"cargo:rustc-link-search={}/src/chips/{}/memory_x/",
|
||||||
#[cfg(feature = "rt")]
|
crate_dir.display(),
|
||||||
println!("cargo:rustc-link-search=src/chips/{}", _chip_name);
|
chip_core_name,
|
||||||
|
);
|
||||||
|
|
||||||
println!("cargo:rerun-if-changed=build.rs");
|
println!("cargo:rerun-if-changed=build.rs");
|
||||||
}
|
}
|
||||||
|
105
stm32-metapac-gen/src/data.rs
Normal file
105
stm32-metapac-gen/src/data.rs
Normal file
@ -0,0 +1,105 @@
|
|||||||
|
use serde::Deserialize;
|
||||||
|
use std::collections::{BTreeMap, HashMap};
|
||||||
|
|
||||||
|
#[derive(Debug, Eq, PartialEq, Clone, Deserialize)]
|
||||||
|
pub struct Chip {
|
||||||
|
pub name: String,
|
||||||
|
pub family: String,
|
||||||
|
pub line: String,
|
||||||
|
pub cores: Vec<Core>,
|
||||||
|
pub flash: Memory,
|
||||||
|
pub ram: Memory,
|
||||||
|
pub packages: Vec<Package>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Eq, PartialEq, Clone, Deserialize)]
|
||||||
|
pub struct Memory {
|
||||||
|
pub bytes: u32,
|
||||||
|
pub regions: HashMap<String, MemoryRegion>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Eq, PartialEq, Clone, Deserialize)]
|
||||||
|
pub struct MemoryRegion {
|
||||||
|
pub base: u32,
|
||||||
|
pub bytes: Option<u32>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Eq, PartialEq, Clone, Deserialize)]
|
||||||
|
pub struct Core {
|
||||||
|
pub name: String,
|
||||||
|
pub peripherals: BTreeMap<String, Peripheral>,
|
||||||
|
pub interrupts: BTreeMap<String, u32>,
|
||||||
|
pub dma_channels: BTreeMap<String, DmaChannel>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Eq, PartialEq, Clone, Deserialize)]
|
||||||
|
pub struct Package {
|
||||||
|
pub name: String,
|
||||||
|
pub package: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Eq, PartialEq, Clone, Deserialize)]
|
||||||
|
pub struct Peripheral {
|
||||||
|
pub address: u64,
|
||||||
|
#[serde(default)]
|
||||||
|
pub kind: Option<String>,
|
||||||
|
#[serde(default)]
|
||||||
|
pub block: Option<String>,
|
||||||
|
#[serde(default)]
|
||||||
|
pub clock: Option<String>,
|
||||||
|
#[serde(default)]
|
||||||
|
pub pins: Vec<Pin>,
|
||||||
|
#[serde(default)]
|
||||||
|
pub dma_channels: BTreeMap<String, Vec<PeripheralDmaChannel>>,
|
||||||
|
#[serde(default)]
|
||||||
|
pub interrupts: BTreeMap<String, String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Eq, PartialEq, Clone, Deserialize)]
|
||||||
|
pub struct Pin {
|
||||||
|
pub pin: String,
|
||||||
|
pub signal: String,
|
||||||
|
pub af: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Eq, PartialEq, Clone, Deserialize)]
|
||||||
|
pub struct DmaChannel {
|
||||||
|
pub dma: String,
|
||||||
|
pub channel: u32,
|
||||||
|
pub dmamux: Option<String>,
|
||||||
|
pub dmamux_channel: Option<u32>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Hash)]
|
||||||
|
pub struct PeripheralDmaChannel {
|
||||||
|
pub channel: Option<String>,
|
||||||
|
pub dmamux: Option<String>,
|
||||||
|
pub request: Option<u32>,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct BlockInfo {
|
||||||
|
/// usart_v1/USART -> usart
|
||||||
|
pub module: String,
|
||||||
|
/// usart_v1/USART -> v1
|
||||||
|
pub version: String,
|
||||||
|
/// usart_v1/USART -> USART
|
||||||
|
pub block: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl BlockInfo {
|
||||||
|
pub fn parse(s: &str) -> Self {
|
||||||
|
let mut s = s.split('/');
|
||||||
|
let module = s.next().unwrap();
|
||||||
|
let block = s.next().unwrap();
|
||||||
|
assert!(s.next().is_none());
|
||||||
|
let mut s = module.split('_');
|
||||||
|
let module = s.next().unwrap();
|
||||||
|
let version = s.next().unwrap();
|
||||||
|
assert!(s.next().is_none());
|
||||||
|
Self {
|
||||||
|
module: module.to_string(),
|
||||||
|
version: version.to_string(),
|
||||||
|
block: block.to_string(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,121 +1,21 @@
|
|||||||
use chiptool::generate::CommonModule;
|
use chiptool::generate::CommonModule;
|
||||||
use chiptool::ir::IR;
|
use chiptool::ir::IR;
|
||||||
|
use proc_macro2::TokenStream;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use serde::Deserialize;
|
|
||||||
use std::collections::{BTreeMap, HashMap, HashSet};
|
use std::collections::{BTreeMap, HashMap, HashSet};
|
||||||
use std::env;
|
|
||||||
use std::fmt::Write as _;
|
use std::fmt::Write as _;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
use chiptool::util::ToSanitizedSnakeCase;
|
use chiptool::util::ToSanitizedSnakeCase;
|
||||||
use chiptool::{generate, ir, transform};
|
use chiptool::{generate, ir, transform};
|
||||||
|
|
||||||
#[derive(Debug, Eq, PartialEq, Clone, Deserialize)]
|
mod data;
|
||||||
pub struct Chip {
|
use data::*;
|
||||||
pub name: String,
|
|
||||||
pub family: String,
|
|
||||||
pub line: String,
|
|
||||||
pub cores: Vec<Core>,
|
|
||||||
pub flash: Memory,
|
|
||||||
pub ram: Memory,
|
|
||||||
pub packages: Vec<Package>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Eq, PartialEq, Clone, Deserialize)]
|
|
||||||
pub struct Memory {
|
|
||||||
pub bytes: u32,
|
|
||||||
pub regions: HashMap<String, MemoryRegion>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Eq, PartialEq, Clone, Deserialize)]
|
|
||||||
pub struct MemoryRegion {
|
|
||||||
pub base: u32,
|
|
||||||
pub bytes: Option<u32>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Eq, PartialEq, Clone, Deserialize)]
|
|
||||||
pub struct Core {
|
|
||||||
pub name: String,
|
|
||||||
pub peripherals: BTreeMap<String, Peripheral>,
|
|
||||||
pub interrupts: BTreeMap<String, u32>,
|
|
||||||
pub dma_channels: BTreeMap<String, DmaChannel>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Eq, PartialEq, Clone, Deserialize)]
|
|
||||||
pub struct Package {
|
|
||||||
pub name: String,
|
|
||||||
pub package: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Eq, PartialEq, Clone, Deserialize)]
|
|
||||||
pub struct Peripheral {
|
|
||||||
pub address: u64,
|
|
||||||
#[serde(default)]
|
|
||||||
pub kind: Option<String>,
|
|
||||||
#[serde(default)]
|
|
||||||
pub block: Option<String>,
|
|
||||||
#[serde(default)]
|
|
||||||
pub clock: Option<String>,
|
|
||||||
#[serde(default)]
|
|
||||||
pub pins: Vec<Pin>,
|
|
||||||
#[serde(default)]
|
|
||||||
pub dma_channels: BTreeMap<String, Vec<PeripheralDmaChannel>>,
|
|
||||||
#[serde(default)]
|
|
||||||
pub interrupts: BTreeMap<String, String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Eq, PartialEq, Clone, Deserialize)]
|
|
||||||
pub struct Pin {
|
|
||||||
pub pin: String,
|
|
||||||
pub signal: String,
|
|
||||||
pub af: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Eq, PartialEq, Clone, Deserialize)]
|
|
||||||
pub struct DmaChannel {
|
|
||||||
pub dma: String,
|
|
||||||
pub channel: u32,
|
|
||||||
pub dmamux: Option<String>,
|
|
||||||
pub dmamux_channel: Option<u32>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Hash)]
|
|
||||||
pub struct PeripheralDmaChannel {
|
|
||||||
pub channel: Option<String>,
|
|
||||||
pub dmamux: Option<String>,
|
|
||||||
pub request: Option<u32>,
|
|
||||||
}
|
|
||||||
|
|
||||||
struct BlockInfo {
|
|
||||||
/// usart_v1/USART -> usart
|
|
||||||
module: String,
|
|
||||||
/// usart_v1/USART -> v1
|
|
||||||
version: String,
|
|
||||||
/// usart_v1/USART -> USART
|
|
||||||
block: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl BlockInfo {
|
|
||||||
fn parse(s: &str) -> Self {
|
|
||||||
let mut s = s.split("/");
|
|
||||||
let module = s.next().unwrap();
|
|
||||||
let block = s.next().unwrap();
|
|
||||||
assert!(s.next().is_none());
|
|
||||||
let mut s = module.split("_");
|
|
||||||
let module = s.next().unwrap();
|
|
||||||
let version = s.next().unwrap();
|
|
||||||
assert!(s.next().is_none());
|
|
||||||
Self {
|
|
||||||
module: module.to_string(),
|
|
||||||
version: version.to_string(),
|
|
||||||
block: block.to_string(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn find_reg<'c>(rcc: &'c ir::IR, reg_regex: &str, field_name: &str) -> Option<(&'c str, &'c str)> {
|
fn find_reg<'c>(rcc: &'c ir::IR, reg_regex: &str, field_name: &str) -> Option<(&'c str, &'c str)> {
|
||||||
let reg_regex = Regex::new(reg_regex).unwrap();
|
let reg_regex = Regex::new(reg_regex).unwrap();
|
||||||
@ -199,69 +99,14 @@ pub struct Options {
|
|||||||
pub data_dir: PathBuf,
|
pub data_dir: PathBuf,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn gen(options: Options) {
|
pub fn gen_chip(
|
||||||
let generate_opts = generate::Options {
|
options: &Options,
|
||||||
common_module: CommonModule::Builtin,
|
chip_core_name: &str,
|
||||||
};
|
chip: &Chip,
|
||||||
|
core: &Core,
|
||||||
let out_dir = options.out_dir;
|
core_index: usize,
|
||||||
let data_dir = options.data_dir;
|
all_peripheral_versions: &mut HashSet<(String, String)>,
|
||||||
|
) {
|
||||||
fs::create_dir_all(out_dir.join("src/peripherals")).unwrap();
|
|
||||||
fs::create_dir_all(out_dir.join("src/chips")).unwrap();
|
|
||||||
|
|
||||||
println!("cwd: {:?}", env::current_dir());
|
|
||||||
|
|
||||||
let mut all_peripheral_versions: HashSet<(String, String)> = HashSet::new();
|
|
||||||
let mut chip_cores: BTreeMap<String, Option<String>> = BTreeMap::new();
|
|
||||||
|
|
||||||
for chip_name in &options.chips {
|
|
||||||
let mut s = chip_name.split('_');
|
|
||||||
let mut chip_name: String = s.next().unwrap().to_string();
|
|
||||||
let core_name: Option<&str> = if let Some(c) = s.next() {
|
|
||||||
if !c.starts_with("CM") {
|
|
||||||
println!("Core not detected, adding as variant");
|
|
||||||
chip_name.push('-');
|
|
||||||
chip_name.push_str(c);
|
|
||||||
None
|
|
||||||
} else {
|
|
||||||
println!("Detected core {}", c);
|
|
||||||
Some(c)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
};
|
|
||||||
|
|
||||||
chip_cores.insert(
|
|
||||||
chip_name.to_string(),
|
|
||||||
core_name.map(|s| s.to_ascii_lowercase().to_string()),
|
|
||||||
);
|
|
||||||
|
|
||||||
let chip_path = data_dir.join("chips").join(&format!("{}.yaml", chip_name));
|
|
||||||
println!("chip_path: {:?}", chip_path);
|
|
||||||
let chip = fs::read(chip_path).unwrap();
|
|
||||||
let chip: Chip = serde_yaml::from_slice(&chip).unwrap();
|
|
||||||
|
|
||||||
println!("looking for core {:?}", core_name);
|
|
||||||
let core: Option<(&Core, usize)> = if let Some(core_name) = core_name {
|
|
||||||
let core_name = core_name.to_ascii_lowercase();
|
|
||||||
let mut c = None;
|
|
||||||
let mut idx = 0;
|
|
||||||
for (i, core) in chip.cores.iter().enumerate() {
|
|
||||||
if core.name == core_name {
|
|
||||||
c = Some(core);
|
|
||||||
idx = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
c.map(|c| (c, idx))
|
|
||||||
} else {
|
|
||||||
Some((&chip.cores[0], 0))
|
|
||||||
};
|
|
||||||
|
|
||||||
let (core, core_index) = core.unwrap();
|
|
||||||
let core_name = &core.name;
|
|
||||||
|
|
||||||
let mut ir = ir::IR::new();
|
let mut ir = ir::IR::new();
|
||||||
|
|
||||||
let mut dev = ir::Device {
|
let mut dev = ir::Device {
|
||||||
@ -274,7 +119,8 @@ pub fn gen(options: Options) {
|
|||||||
if name == "DBGMCU" {
|
if name == "DBGMCU" {
|
||||||
p.block.as_ref().map(|block| {
|
p.block.as_ref().map(|block| {
|
||||||
let bi = BlockInfo::parse(block);
|
let bi = BlockInfo::parse(block);
|
||||||
let dbgmcu_reg_path = data_dir
|
let dbgmcu_reg_path = options
|
||||||
|
.data_dir
|
||||||
.join("registers")
|
.join("registers")
|
||||||
.join(&format!("{}_{}.yaml", bi.module, bi.version));
|
.join(&format!("{}_{}.yaml", bi.module, bi.version));
|
||||||
serde_yaml::from_reader(File::open(dbgmcu_reg_path).unwrap()).unwrap()
|
serde_yaml::from_reader(File::open(dbgmcu_reg_path).unwrap()).unwrap()
|
||||||
@ -293,7 +139,8 @@ pub fn gen(options: Options) {
|
|||||||
|
|
||||||
let rcc_block = rcc.block.as_ref().expect("RCC peripheral has no block");
|
let rcc_block = rcc.block.as_ref().expect("RCC peripheral has no block");
|
||||||
let bi = BlockInfo::parse(&rcc_block);
|
let bi = BlockInfo::parse(&rcc_block);
|
||||||
let rcc_reg_path = data_dir
|
let rcc_reg_path = options
|
||||||
|
.data_dir
|
||||||
.join("registers")
|
.join("registers")
|
||||||
.join(&format!("{}_{}.yaml", bi.module, bi.version));
|
.join(&format!("{}_{}.yaml", bi.module, bi.version));
|
||||||
let rcc: IR = serde_yaml::from_reader(File::open(rcc_reg_path).unwrap()).unwrap();
|
let rcc: IR = serde_yaml::from_reader(File::open(rcc_reg_path).unwrap()).unwrap();
|
||||||
@ -578,29 +425,7 @@ pub fn gen(options: Options) {
|
|||||||
gpio_base, gpio_stride,
|
gpio_base, gpio_stride,
|
||||||
);
|
);
|
||||||
|
|
||||||
let peripheral_version_table = peripheral_versions
|
for (module, version) in &peripheral_versions {
|
||||||
.iter()
|
|
||||||
.map(|(kind, version)| vec![kind.clone(), version.clone()])
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
make_table(&mut extra, "pins", &pin_table);
|
|
||||||
make_table(&mut extra, "interrupts", &interrupt_table);
|
|
||||||
make_table(&mut extra, "peripherals", &peripherals_table);
|
|
||||||
make_table(&mut extra, "peripheral_versions", &peripheral_version_table);
|
|
||||||
make_table(&mut extra, "peripheral_pins", &peripheral_pins_table);
|
|
||||||
make_table(
|
|
||||||
&mut extra,
|
|
||||||
"peripheral_dma_channels",
|
|
||||||
&peripheral_dma_channels_table,
|
|
||||||
);
|
|
||||||
make_table(&mut extra, "peripheral_rcc", &peripheral_rcc_table);
|
|
||||||
make_table(&mut extra, "gpio_rcc", &gpio_rcc_table);
|
|
||||||
make_table(&mut extra, "dma_channels", &dma_channels_table);
|
|
||||||
make_table(&mut extra, "dbgmcu", &dbgmcu_table);
|
|
||||||
make_peripheral_counts(&mut extra, &peripheral_counts);
|
|
||||||
make_dma_channel_counts(&mut extra, &dma_channel_counts);
|
|
||||||
|
|
||||||
for (module, version) in peripheral_versions {
|
|
||||||
all_peripheral_versions.insert((module.clone(), version.clone()));
|
all_peripheral_versions.insert((module.clone(), version.clone()));
|
||||||
write!(
|
write!(
|
||||||
&mut extra,
|
&mut extra,
|
||||||
@ -620,26 +445,25 @@ pub fn gen(options: Options) {
|
|||||||
transform::sort::Sort {}.run(&mut ir).unwrap();
|
transform::sort::Sort {}.run(&mut ir).unwrap();
|
||||||
transform::Sanitize {}.run(&mut ir).unwrap();
|
transform::Sanitize {}.run(&mut ir).unwrap();
|
||||||
|
|
||||||
let chip_dir = if chip.cores.len() > 1 {
|
// ==============================
|
||||||
out_dir.join("src/chips").join(format!(
|
// Setup chip dir
|
||||||
"{}_{}",
|
|
||||||
chip_name.to_ascii_lowercase(),
|
let chip_dir = options
|
||||||
core_name.to_ascii_lowercase()
|
.out_dir
|
||||||
))
|
|
||||||
} else {
|
|
||||||
out_dir
|
|
||||||
.join("src/chips")
|
.join("src/chips")
|
||||||
.join(chip_name.to_ascii_lowercase())
|
.join(chip_core_name.to_ascii_lowercase());
|
||||||
};
|
|
||||||
fs::create_dir_all(&chip_dir).unwrap();
|
fs::create_dir_all(&chip_dir).unwrap();
|
||||||
|
|
||||||
let items = generate::render(&ir, &generate_opts).unwrap();
|
// ==============================
|
||||||
let mut file = File::create(chip_dir.join("pac.rs")).unwrap();
|
// generate pac.rs
|
||||||
let data = items.to_string().replace("] ", "]\n");
|
|
||||||
|
let data = generate::render(&ir, &gen_opts()).unwrap().to_string();
|
||||||
|
let data = data.replace("] ", "]\n");
|
||||||
|
|
||||||
// Remove inner attributes like #![no_std]
|
// Remove inner attributes like #![no_std]
|
||||||
let re = Regex::new("# *! *\\[.*\\]").unwrap();
|
let data = Regex::new("# *! *\\[.*\\]").unwrap().replace_all(&data, "");
|
||||||
let data = re.replace_all(&data, "");
|
|
||||||
|
let mut file = File::create(chip_dir.join("pac.rs")).unwrap();
|
||||||
file.write_all(data.as_bytes()).unwrap();
|
file.write_all(data.as_bytes()).unwrap();
|
||||||
file.write_all(extra.as_bytes()).unwrap();
|
file.write_all(extra.as_bytes()).unwrap();
|
||||||
|
|
||||||
@ -654,19 +478,98 @@ pub fn gen(options: Options) {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ==============================
|
||||||
|
// generate mod.rs
|
||||||
|
|
||||||
|
let mut data = String::new();
|
||||||
|
|
||||||
|
write!(&mut data, "#[cfg(feature=\"pac\")] mod pac;").unwrap();
|
||||||
|
write!(&mut data, "#[cfg(feature=\"pac\")] pub use pac::*; ").unwrap();
|
||||||
|
|
||||||
|
let peripheral_version_table = peripheral_versions
|
||||||
|
.iter()
|
||||||
|
.map(|(kind, version)| vec![kind.clone(), version.clone()])
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
make_table(&mut data, "pins", &pin_table);
|
||||||
|
make_table(&mut data, "interrupts", &interrupt_table);
|
||||||
|
make_table(&mut data, "peripherals", &peripherals_table);
|
||||||
|
make_table(&mut data, "peripheral_versions", &peripheral_version_table);
|
||||||
|
make_table(&mut data, "peripheral_pins", &peripheral_pins_table);
|
||||||
|
make_table(
|
||||||
|
&mut data,
|
||||||
|
"peripheral_dma_channels",
|
||||||
|
&peripheral_dma_channels_table,
|
||||||
|
);
|
||||||
|
make_table(&mut data, "peripheral_rcc", &peripheral_rcc_table);
|
||||||
|
make_table(&mut data, "gpio_rcc", &gpio_rcc_table);
|
||||||
|
make_table(&mut data, "dma_channels", &dma_channels_table);
|
||||||
|
make_table(&mut data, "dbgmcu", &dbgmcu_table);
|
||||||
|
make_peripheral_counts(&mut data, &peripheral_counts);
|
||||||
|
make_dma_channel_counts(&mut data, &dma_channel_counts);
|
||||||
|
|
||||||
|
let mut file = File::create(chip_dir.join("mod.rs")).unwrap();
|
||||||
|
file.write_all(data.as_bytes()).unwrap();
|
||||||
|
|
||||||
|
// ==============================
|
||||||
|
// generate device.x
|
||||||
|
|
||||||
File::create(chip_dir.join("device.x"))
|
File::create(chip_dir.join("device.x"))
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.write_all(device_x.as_bytes())
|
.write_all(device_x.as_bytes())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
// ==============================
|
||||||
// generate default memory.x
|
// generate default memory.x
|
||||||
gen_memory_x(&chip_dir, &chip);
|
gen_memory_x(&chip_dir, &chip);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn load_chip(options: &Options, name: &str) -> Chip {
|
||||||
|
let chip_path = options
|
||||||
|
.data_dir
|
||||||
|
.join("chips")
|
||||||
|
.join(&format!("{}.yaml", name));
|
||||||
|
let chip = fs::read(chip_path).expect(&format!("Could not load chip {}", name));
|
||||||
|
serde_yaml::from_slice(&chip).unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn gen_opts() -> generate::Options {
|
||||||
|
generate::Options {
|
||||||
|
common_module: CommonModule::External(TokenStream::from_str("crate::common").unwrap()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn gen(options: Options) {
|
||||||
|
fs::create_dir_all(options.out_dir.join("src/peripherals")).unwrap();
|
||||||
|
fs::create_dir_all(options.out_dir.join("src/chips")).unwrap();
|
||||||
|
|
||||||
|
let mut all_peripheral_versions: HashSet<(String, String)> = HashSet::new();
|
||||||
|
let mut chip_core_names: Vec<String> = Vec::new();
|
||||||
|
|
||||||
|
for chip_name in &options.chips {
|
||||||
|
let chip = load_chip(&options, chip_name);
|
||||||
|
for (core_index, core) in chip.cores.iter().enumerate() {
|
||||||
|
let chip_core_name = match chip.cores.len() {
|
||||||
|
1 => chip_name.clone(),
|
||||||
|
_ => format!("{}-{}", chip_name, core.name),
|
||||||
|
};
|
||||||
|
|
||||||
|
chip_core_names.push(chip_core_name.clone());
|
||||||
|
gen_chip(
|
||||||
|
&options,
|
||||||
|
&chip_core_name,
|
||||||
|
&chip,
|
||||||
|
core,
|
||||||
|
core_index,
|
||||||
|
&mut all_peripheral_versions,
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (module, version) in all_peripheral_versions {
|
for (module, version) in all_peripheral_versions {
|
||||||
println!("loading {} {}", module, version);
|
println!("loading {} {}", module, version);
|
||||||
|
|
||||||
let regs_path = Path::new(&data_dir)
|
let regs_path = Path::new(&options.data_dir)
|
||||||
.join("registers")
|
.join("registers")
|
||||||
.join(&format!("{}_{}.yaml", module, version));
|
.join(&format!("{}_{}.yaml", module, version));
|
||||||
|
|
||||||
@ -686,9 +589,10 @@ pub fn gen(options: Options) {
|
|||||||
transform::sort::Sort {}.run(&mut ir).unwrap();
|
transform::sort::Sort {}.run(&mut ir).unwrap();
|
||||||
transform::Sanitize {}.run(&mut ir).unwrap();
|
transform::Sanitize {}.run(&mut ir).unwrap();
|
||||||
|
|
||||||
let items = generate::render(&ir, &generate_opts).unwrap();
|
let items = generate::render(&ir, &gen_opts()).unwrap();
|
||||||
let mut file = File::create(
|
let mut file = File::create(
|
||||||
out_dir
|
options
|
||||||
|
.out_dir
|
||||||
.join("src/peripherals")
|
.join("src/peripherals")
|
||||||
.join(format!("{}_{}.rs", module, version)),
|
.join(format!("{}_{}.rs", module, version)),
|
||||||
)
|
)
|
||||||
@ -707,29 +611,20 @@ pub fn gen(options: Options) {
|
|||||||
let i = bytes_find(librs, PATHS_MARKER).unwrap();
|
let i = bytes_find(librs, PATHS_MARKER).unwrap();
|
||||||
let mut paths = String::new();
|
let mut paths = String::new();
|
||||||
|
|
||||||
for (chip, cores) in chip_cores.iter() {
|
for name in chip_core_names {
|
||||||
let x = chip.to_ascii_lowercase();
|
let x = name.to_ascii_lowercase();
|
||||||
if let Some(c) = cores {
|
|
||||||
write!(
|
write!(
|
||||||
&mut paths,
|
&mut paths,
|
||||||
"#[cfg_attr(feature=\"{}_{}\", path = \"chips/{}_{}/pac.rs\")]",
|
"#[cfg_attr(feature=\"{}\", path = \"chips/{}/mod.rs\")]",
|
||||||
x, c, x, c
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
} else {
|
|
||||||
write!(
|
|
||||||
&mut paths,
|
|
||||||
"#[cfg_attr(feature=\"{}\", path = \"chips/{}/pac.rs\")]",
|
|
||||||
x, x
|
x, x
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
let mut contents: Vec<u8> = Vec::new();
|
let mut contents: Vec<u8> = Vec::new();
|
||||||
contents.extend(&librs[..i]);
|
contents.extend(&librs[..i]);
|
||||||
contents.extend(paths.as_bytes());
|
contents.extend(paths.as_bytes());
|
||||||
contents.extend(&librs[i + PATHS_MARKER.len()..]);
|
contents.extend(&librs[i + PATHS_MARKER.len()..]);
|
||||||
fs::write(out_dir.join("src").join("lib_inner.rs"), &contents).unwrap();
|
fs::write(options.out_dir.join("src").join("lib_inner.rs"), &contents).unwrap();
|
||||||
|
|
||||||
// Generate src/lib.rs
|
// Generate src/lib.rs
|
||||||
const CUT_MARKER: &[u8] = b"// GEN CUT HERE";
|
const CUT_MARKER: &[u8] = b"// GEN CUT HERE";
|
||||||
@ -738,11 +633,11 @@ pub fn gen(options: Options) {
|
|||||||
let mut contents: Vec<u8> = Vec::new();
|
let mut contents: Vec<u8> = Vec::new();
|
||||||
contents.extend(&librs[..i]);
|
contents.extend(&librs[..i]);
|
||||||
contents.extend(b"include!(\"lib_inner.rs\");\n");
|
contents.extend(b"include!(\"lib_inner.rs\");\n");
|
||||||
fs::write(out_dir.join("src").join("lib.rs"), contents).unwrap();
|
fs::write(options.out_dir.join("src").join("lib.rs"), contents).unwrap();
|
||||||
|
|
||||||
// Generate src/common.rs
|
// Generate src/common.rs
|
||||||
fs::write(
|
fs::write(
|
||||||
out_dir.join("src").join("common.rs"),
|
options.out_dir.join("src").join("common.rs"),
|
||||||
generate::COMMON_MODULE,
|
generate::COMMON_MODULE,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
@ -755,10 +650,14 @@ pub fn gen(options: Options) {
|
|||||||
let begin = bytes_find(&contents, BUILDDEP_BEGIN).unwrap();
|
let begin = bytes_find(&contents, BUILDDEP_BEGIN).unwrap();
|
||||||
let end = bytes_find(&contents, BUILDDEP_END).unwrap() + BUILDDEP_END.len();
|
let end = bytes_find(&contents, BUILDDEP_END).unwrap() + BUILDDEP_END.len();
|
||||||
contents.drain(begin..end);
|
contents.drain(begin..end);
|
||||||
fs::write(out_dir.join("Cargo.toml"), contents).unwrap();
|
fs::write(options.out_dir.join("Cargo.toml"), contents).unwrap();
|
||||||
|
|
||||||
// Generate build.rs
|
// Generate build.rs
|
||||||
fs::write(out_dir.join("build.rs"), include_bytes!("assets/build.rs")).unwrap();
|
fs::write(
|
||||||
|
options.out_dir.join("build.rs"),
|
||||||
|
include_bytes!("assets/build.rs"),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn bytes_find(haystack: &[u8], needle: &[u8]) -> Option<usize> {
|
fn bytes_find(haystack: &[u8], needle: &[u8]) -> Option<usize> {
|
||||||
|
@ -17,7 +17,6 @@ fn main() {
|
|||||||
.unwrap()
|
.unwrap()
|
||||||
.filter_map(|res| res.unwrap().file_name().to_str().map(|s| s.to_string()))
|
.filter_map(|res| res.unwrap().file_name().to_str().map(|s| s.to_string()))
|
||||||
.filter(|s| s.ends_with(".yaml"))
|
.filter(|s| s.ends_with(".yaml"))
|
||||||
.filter(|s| !s.starts_with("STM32L1")) // cursed gpio stride
|
|
||||||
.filter(|s| !s.starts_with("STM32GBK")) // cursed weird STM32G4
|
.filter(|s| !s.starts_with("STM32GBK")) // cursed weird STM32G4
|
||||||
.map(|s| s.strip_suffix(".yaml").unwrap().to_string())
|
.map(|s| s.strip_suffix(".yaml").unwrap().to_string())
|
||||||
.collect()
|
.collect()
|
||||||
|
@ -16,6 +16,13 @@ regex = "1.5.4"
|
|||||||
# END BUILD DEPENDENCIES
|
# END BUILD DEPENDENCIES
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
|
default = ["pac"]
|
||||||
|
|
||||||
|
# Build the actual PAC. Set by default.
|
||||||
|
# If not set, only the macrotables will be generated. You may want to not set it
|
||||||
|
# if you're using stm32-metapac from a build.rs script to use the macros.
|
||||||
|
pac = []
|
||||||
|
|
||||||
rt = ["cortex-m-rt/device"]
|
rt = ["cortex-m-rt/device"]
|
||||||
memory-x = []
|
memory-x = []
|
||||||
|
|
||||||
@ -780,40 +787,40 @@ stm32h743xg = []
|
|||||||
stm32h743xi = []
|
stm32h743xi = []
|
||||||
stm32h743zg = []
|
stm32h743zg = []
|
||||||
stm32h743zi = []
|
stm32h743zi = []
|
||||||
stm32h745bg_cm7 = []
|
stm32h745bg-cm7 = []
|
||||||
stm32h745bg_cm4 = []
|
stm32h745bg-cm4 = []
|
||||||
stm32h745bi_cm7 = []
|
stm32h745bi-cm7 = []
|
||||||
stm32h745bi_cm4 = []
|
stm32h745bi-cm4 = []
|
||||||
stm32h745ig_cm7 = []
|
stm32h745ig-cm7 = []
|
||||||
stm32h745ig_cm4 = []
|
stm32h745ig-cm4 = []
|
||||||
stm32h745ii_cm7 = []
|
stm32h745ii-cm7 = []
|
||||||
stm32h745ii_cm4 = []
|
stm32h745ii-cm4 = []
|
||||||
stm32h745xg_cm7 = []
|
stm32h745xg-cm7 = []
|
||||||
stm32h745xg_cm4 = []
|
stm32h745xg-cm4 = []
|
||||||
stm32h745xi_cm7 = []
|
stm32h745xi-cm7 = []
|
||||||
stm32h745xi_cm4 = []
|
stm32h745xi-cm4 = []
|
||||||
stm32h745zg_cm7 = []
|
stm32h745zg-cm7 = []
|
||||||
stm32h745zg_cm4 = []
|
stm32h745zg-cm4 = []
|
||||||
stm32h745zi_cm7 = []
|
stm32h745zi-cm7 = []
|
||||||
stm32h745zi_cm4 = []
|
stm32h745zi-cm4 = []
|
||||||
stm32h747ag_cm7 = []
|
stm32h747ag-cm7 = []
|
||||||
stm32h747ag_cm4 = []
|
stm32h747ag-cm4 = []
|
||||||
stm32h747ai_cm7 = []
|
stm32h747ai-cm7 = []
|
||||||
stm32h747ai_cm4 = []
|
stm32h747ai-cm4 = []
|
||||||
stm32h747bg_cm7 = []
|
stm32h747bg-cm7 = []
|
||||||
stm32h747bg_cm4 = []
|
stm32h747bg-cm4 = []
|
||||||
stm32h747bi_cm7 = []
|
stm32h747bi-cm7 = []
|
||||||
stm32h747bi_cm4 = []
|
stm32h747bi-cm4 = []
|
||||||
stm32h747ig_cm7 = []
|
stm32h747ig-cm7 = []
|
||||||
stm32h747ig_cm4 = []
|
stm32h747ig-cm4 = []
|
||||||
stm32h747ii_cm7 = []
|
stm32h747ii-cm7 = []
|
||||||
stm32h747ii_cm4 = []
|
stm32h747ii-cm4 = []
|
||||||
stm32h747xg_cm7 = []
|
stm32h747xg-cm7 = []
|
||||||
stm32h747xg_cm4 = []
|
stm32h747xg-cm4 = []
|
||||||
stm32h747xi_cm7 = []
|
stm32h747xi-cm7 = []
|
||||||
stm32h747xi_cm4 = []
|
stm32h747xi-cm4 = []
|
||||||
stm32h747zi_cm7 = []
|
stm32h747zi-cm7 = []
|
||||||
stm32h747zi_cm4 = []
|
stm32h747zi-cm4 = []
|
||||||
stm32h750ib = []
|
stm32h750ib = []
|
||||||
stm32h750vb = []
|
stm32h750vb = []
|
||||||
stm32h750xb = []
|
stm32h750xb = []
|
||||||
@ -824,24 +831,24 @@ stm32h753ii = []
|
|||||||
stm32h753vi = []
|
stm32h753vi = []
|
||||||
stm32h753xi = []
|
stm32h753xi = []
|
||||||
stm32h753zi = []
|
stm32h753zi = []
|
||||||
stm32h755bi_cm7 = []
|
stm32h755bi-cm7 = []
|
||||||
stm32h755bi_cm4 = []
|
stm32h755bi-cm4 = []
|
||||||
stm32h755ii_cm7 = []
|
stm32h755ii-cm7 = []
|
||||||
stm32h755ii_cm4 = []
|
stm32h755ii-cm4 = []
|
||||||
stm32h755xi_cm7 = []
|
stm32h755xi-cm7 = []
|
||||||
stm32h755xi_cm4 = []
|
stm32h755xi-cm4 = []
|
||||||
stm32h755zi_cm7 = []
|
stm32h755zi-cm7 = []
|
||||||
stm32h755zi_cm4 = []
|
stm32h755zi-cm4 = []
|
||||||
stm32h757ai_cm7 = []
|
stm32h757ai-cm7 = []
|
||||||
stm32h757ai_cm4 = []
|
stm32h757ai-cm4 = []
|
||||||
stm32h757bi_cm7 = []
|
stm32h757bi-cm7 = []
|
||||||
stm32h757bi_cm4 = []
|
stm32h757bi-cm4 = []
|
||||||
stm32h757ii_cm7 = []
|
stm32h757ii-cm7 = []
|
||||||
stm32h757ii_cm4 = []
|
stm32h757ii-cm4 = []
|
||||||
stm32h757xi_cm7 = []
|
stm32h757xi-cm7 = []
|
||||||
stm32h757xi_cm4 = []
|
stm32h757xi-cm4 = []
|
||||||
stm32h757zi_cm7 = []
|
stm32h757zi-cm7 = []
|
||||||
stm32h757zi_cm4 = []
|
stm32h757zi-cm4 = []
|
||||||
stm32h7a3ag = []
|
stm32h7a3ag = []
|
||||||
stm32h7a3ai = []
|
stm32h7a3ai = []
|
||||||
stm32h7a3ig = []
|
stm32h7a3ig = []
|
||||||
@ -1255,16 +1262,16 @@ stm32wb55ve = []
|
|||||||
stm32wb55vg = []
|
stm32wb55vg = []
|
||||||
stm32wb55vy = []
|
stm32wb55vy = []
|
||||||
stm32wb5mmg = []
|
stm32wb5mmg = []
|
||||||
stm32wl54cc_cm4 = []
|
stm32wl54cc-cm4 = []
|
||||||
stm32wl54cc_cm0p = []
|
stm32wl54cc-cm0p = []
|
||||||
stm32wl54jc_cm4 = []
|
stm32wl54jc-cm4 = []
|
||||||
stm32wl54jc_cm0p = []
|
stm32wl54jc-cm0p = []
|
||||||
stm32wl55cc_cm4 = []
|
stm32wl55cc-cm4 = []
|
||||||
stm32wl55cc_cm0p = []
|
stm32wl55cc-cm0p = []
|
||||||
stm32wl55jc_cm4 = []
|
stm32wl55jc-cm4 = []
|
||||||
stm32wl55jc_cm0p = []
|
stm32wl55jc-cm0p = []
|
||||||
stm32wl55uc_cm4 = []
|
stm32wl55uc-cm4 = []
|
||||||
stm32wl55uc_cm0p = []
|
stm32wl55uc-cm0p = []
|
||||||
stm32wle4c8 = []
|
stm32wle4c8 = []
|
||||||
stm32wle4cb = []
|
stm32wle4cb = []
|
||||||
stm32wle4cc = []
|
stm32wle4cc = []
|
||||||
|
@ -2,48 +2,52 @@ use std::env;
|
|||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use stm32_metapac_gen::*;
|
use stm32_metapac_gen::*;
|
||||||
|
|
||||||
|
fn parse_chip_core(chip_and_core: &str) -> (String, Option<String>) {
|
||||||
|
let mut s = chip_and_core.split('-');
|
||||||
|
let chip_name: String = s.next().unwrap().to_string();
|
||||||
|
if let Some(c) = s.next() {
|
||||||
|
if c.starts_with("CM") {
|
||||||
|
return (chip_name, Some(c.to_ascii_lowercase()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
(chip_and_core.to_string(), None)
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let out_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap());
|
let out_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap());
|
||||||
let data_dir = PathBuf::from("../stm32-data/data");
|
let data_dir = PathBuf::from("../stm32-data/data");
|
||||||
|
|
||||||
println!("cwd: {:?}", env::current_dir());
|
println!("cwd: {:?}", env::current_dir());
|
||||||
|
|
||||||
let chip_name = env::vars_os()
|
let chip_core_name = env::vars_os()
|
||||||
.map(|(a, _)| a.to_string_lossy().to_string())
|
.map(|(a, _)| a.to_string_lossy().to_string())
|
||||||
.find(|x| x.starts_with("CARGO_FEATURE_STM32"))
|
.find(|x| x.starts_with("CARGO_FEATURE_STM32"))
|
||||||
.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_uppercase()
|
||||||
|
.replace('_', "-");
|
||||||
|
|
||||||
|
let (chip_name, _) = parse_chip_core(&chip_core_name);
|
||||||
|
|
||||||
gen(Options {
|
gen(Options {
|
||||||
out_dir: out_dir.clone(),
|
out_dir: out_dir.clone(),
|
||||||
data_dir: data_dir.clone(),
|
data_dir: data_dir.clone(),
|
||||||
chips: vec![chip_name.clone()],
|
chips: vec![chip_name],
|
||||||
});
|
});
|
||||||
|
|
||||||
let mut s = chip_name.split('_');
|
|
||||||
let mut chip_name: String = s.next().unwrap().to_string();
|
|
||||||
if let Some(c) = s.next() {
|
|
||||||
if !c.starts_with("CM") {
|
|
||||||
chip_name.push('-');
|
|
||||||
} else {
|
|
||||||
chip_name.push('_');
|
|
||||||
}
|
|
||||||
chip_name.push_str(c);
|
|
||||||
}
|
|
||||||
|
|
||||||
println!(
|
println!(
|
||||||
"cargo:rustc-link-search={}/src/chips/{}",
|
"cargo:rustc-link-search={}/src/chips/{}",
|
||||||
out_dir.display(),
|
out_dir.display(),
|
||||||
chip_name.to_ascii_lowercase()
|
chip_core_name.to_ascii_lowercase()
|
||||||
);
|
);
|
||||||
|
|
||||||
#[cfg(feature = "memory-x")]
|
#[cfg(feature = "memory-x")]
|
||||||
println!(
|
println!(
|
||||||
"cargo:rustc-link-search={}/src/chips/{}/memory_x/",
|
"cargo:rustc-link-search={}/src/chips/{}/memory_x/",
|
||||||
out_dir.display(),
|
out_dir.display(),
|
||||||
chip_name.to_ascii_lowercase()
|
chip_core_name.to_ascii_lowercase()
|
||||||
);
|
);
|
||||||
|
|
||||||
println!("cargo:rerun-if-changed=build.rs");
|
println!("cargo:rerun-if-changed=build.rs");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user