stm32: use stm32-metapac from crates.io, remove stm32-data submodule.
This commit is contained in:
parent
b6663a013f
commit
0b49b588a2
25 changed files with 34 additions and 2636 deletions
1
.github/workflows/doc.yml
vendored
1
.github/workflows/doc.yml
vendored
|
@ -54,7 +54,6 @@ jobs:
|
||||||
run: |
|
run: |
|
||||||
mkdir crates
|
mkdir crates
|
||||||
builder ./embassy-stm32 crates/embassy-stm32/git.zup
|
builder ./embassy-stm32 crates/embassy-stm32/git.zup
|
||||||
builder ./stm32-metapac crates/stm32-metapac/git.zup
|
|
||||||
|
|
||||||
- name: build-rest
|
- name: build-rest
|
||||||
if: ${{ matrix.crates=='rest' }}
|
if: ${{ matrix.crates=='rest' }}
|
||||||
|
|
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -4,8 +4,4 @@ target_ci_stable
|
||||||
Cargo.lock
|
Cargo.lock
|
||||||
third_party
|
third_party
|
||||||
/Cargo.toml
|
/Cargo.toml
|
||||||
stm32-metapac-gen/out/
|
|
||||||
stm32-metapac-backup
|
|
||||||
stm32-metapac/src/chips
|
|
||||||
stm32-metapac/src/peripherals
|
|
||||||
out/
|
out/
|
||||||
|
|
3
.gitmodules
vendored
3
.gitmodules
vendored
|
@ -1,3 +0,0 @@
|
||||||
[submodule "stm32-data"]
|
|
||||||
path = stm32-data
|
|
||||||
url = https://github.com/embassy-rs/stm32-data.git
|
|
20
ci.sh
20
ci.sh
|
@ -8,28 +8,12 @@ export DEFMT_LOG=trace
|
||||||
|
|
||||||
TARGET=$(rustc -vV | sed -n 's|host: ||p')
|
TARGET=$(rustc -vV | sed -n 's|host: ||p')
|
||||||
|
|
||||||
|
BUILD_EXTRA=""
|
||||||
if [ $TARGET = "x86_64-unknown-linux-gnu" ]; then
|
if [ $TARGET = "x86_64-unknown-linux-gnu" ]; then
|
||||||
BUILD_EXTRA="--- build --release --manifest-path examples/std/Cargo.toml --target $TARGET --out-dir out/examples/std"
|
BUILD_EXTRA="--- build --release --manifest-path examples/std/Cargo.toml --target $TARGET --out-dir out/examples/std"
|
||||||
else
|
|
||||||
BUILD_EXTRA=""
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
find . -name '*.rs' -not -path '*target*' -not -path '*stm32-metapac-gen/out/*' -not -path '*stm32-metapac/src/*' | xargs rustfmt --check --skip-children --unstable-features --edition 2018
|
find . -name '*.rs' -not -path '*target*' | xargs rustfmt --check --skip-children --unstable-features --edition 2018
|
||||||
|
|
||||||
# Generate stm32-metapac
|
|
||||||
if [ ! -d "stm32-metapac-backup" ]
|
|
||||||
then
|
|
||||||
cp -r stm32-metapac stm32-metapac-backup
|
|
||||||
fi
|
|
||||||
|
|
||||||
rm -rf stm32-metapac
|
|
||||||
cp -r stm32-metapac-backup 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 $TARGET)
|
|
||||||
rm -rf stm32-metapac
|
|
||||||
mv stm32-metapac-gen/out stm32-metapac
|
|
||||||
|
|
||||||
cargo batch \
|
cargo batch \
|
||||||
--- build --release --manifest-path embassy-executor/Cargo.toml --target thumbv7em-none-eabi --features nightly \
|
--- build --release --manifest-path embassy-executor/Cargo.toml --target thumbv7em-none-eabi --features nightly \
|
||||||
|
|
|
@ -10,7 +10,6 @@ members = [
|
||||||
[patch.crates-io]
|
[patch.crates-io]
|
||||||
embassy-executor = { path = "../../../../../embassy-executor" }
|
embassy-executor = { path = "../../../../../embassy-executor" }
|
||||||
embassy-stm32 = { path = "../../../../../embassy-stm32" }
|
embassy-stm32 = { path = "../../../../../embassy-stm32" }
|
||||||
stm32-metapac = { path = "../../../../../stm32-metapac" }
|
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
codegen-units = 1
|
codegen-units = 1
|
||||||
|
|
|
@ -7,7 +7,7 @@ license = "MIT OR Apache-2.0"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
cortex-m = "0.7"
|
cortex-m = "0.7"
|
||||||
cortex-m-rt = "0.7"
|
cortex-m-rt = "0.7"
|
||||||
stm32-metapac = { version = "0.1.0", features = ["stm32l475vg", "memory-x"] }
|
stm32-metapac = { version = "1", features = ["stm32l475vg", "memory-x"] }
|
||||||
|
|
||||||
defmt = "0.3.0"
|
defmt = "0.3.0"
|
||||||
defmt-rtt = "0.3.0"
|
defmt-rtt = "0.3.0"
|
||||||
|
|
|
@ -60,7 +60,7 @@ sdio-host = "0.5.0"
|
||||||
embedded-sdmmc = { git = "https://github.com/embassy-rs/embedded-sdmmc-rs", rev = "46d1b1c2ff13e31e282ec1e352421721694f126a", optional = true }
|
embedded-sdmmc = { git = "https://github.com/embassy-rs/embedded-sdmmc-rs", rev = "46d1b1c2ff13e31e282ec1e352421721694f126a", optional = true }
|
||||||
critical-section = "1.1"
|
critical-section = "1.1"
|
||||||
atomic-polyfill = "1.0.1"
|
atomic-polyfill = "1.0.1"
|
||||||
stm32-metapac = { version = "0.1.0", path = "../stm32-metapac", features = ["rt"] }
|
stm32-metapac = { version = "1", features = ["rt"] }
|
||||||
vcell = "0.1.3"
|
vcell = "0.1.3"
|
||||||
bxcan = "0.7.0"
|
bxcan = "0.7.0"
|
||||||
nb = "1.0.0"
|
nb = "1.0.0"
|
||||||
|
@ -72,7 +72,7 @@ embedded-io = { version = "0.4.0", features = ["async"], optional = true }
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
proc-macro2 = "1.0.36"
|
proc-macro2 = "1.0.36"
|
||||||
quote = "1.0.15"
|
quote = "1.0.15"
|
||||||
stm32-metapac = { version = "0.1.0", path = "../stm32-metapac", default-features = false, features = ["metadata"]}
|
stm32-metapac = { version = "1", default-features = false, features = ["metadata"]}
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
defmt = ["dep:defmt", "bxcan/unstable-defmt", "embassy-sync/defmt", "embassy-executor/defmt", "embassy-embedded-hal/defmt", "embassy-hal-common/defmt", "embedded-io?/defmt", "embassy-usb-driver?/defmt", "embassy-net-driver/defmt"]
|
defmt = ["dep:defmt", "bxcan/unstable-defmt", "embassy-sync/defmt", "embassy-executor/defmt", "embassy-embedded-hal/defmt", "embassy-hal-common/defmt", "embedded-io?/defmt", "embassy-usb-driver?/defmt", "embassy-net-driver/defmt"]
|
||||||
|
@ -107,8 +107,7 @@ unstable-pac = []
|
||||||
# Implement embedded-hal-async traits if `nightly` is set as well.
|
# Implement embedded-hal-async traits if `nightly` is set as well.
|
||||||
unstable-traits = ["embedded-hal-1", "dep:embedded-hal-nb"]
|
unstable-traits = ["embedded-hal-1", "dep:embedded-hal-nb"]
|
||||||
|
|
||||||
# BEGIN GENERATED FEATURES
|
# Chip-selection features
|
||||||
# Generated by stm32-gen-features. DO NOT EDIT.
|
|
||||||
stm32c011d6 = [ "stm32-metapac/stm32c011d6" ]
|
stm32c011d6 = [ "stm32-metapac/stm32c011d6" ]
|
||||||
stm32c011f4 = [ "stm32-metapac/stm32c011f4" ]
|
stm32c011f4 = [ "stm32-metapac/stm32c011f4" ]
|
||||||
stm32c011f6 = [ "stm32-metapac/stm32c011f6" ]
|
stm32c011f6 = [ "stm32-metapac/stm32c011f6" ]
|
||||||
|
@ -1070,89 +1069,89 @@ stm32l083rz = [ "stm32-metapac/stm32l083rz" ]
|
||||||
stm32l083v8 = [ "stm32-metapac/stm32l083v8" ]
|
stm32l083v8 = [ "stm32-metapac/stm32l083v8" ]
|
||||||
stm32l083vb = [ "stm32-metapac/stm32l083vb" ]
|
stm32l083vb = [ "stm32-metapac/stm32l083vb" ]
|
||||||
stm32l083vz = [ "stm32-metapac/stm32l083vz" ]
|
stm32l083vz = [ "stm32-metapac/stm32l083vz" ]
|
||||||
stm32l100c6-a = [ "stm32-metapac/stm32l100c6-a" ]
|
|
||||||
stm32l100c6 = [ "stm32-metapac/stm32l100c6" ]
|
stm32l100c6 = [ "stm32-metapac/stm32l100c6" ]
|
||||||
stm32l100r8-a = [ "stm32-metapac/stm32l100r8-a" ]
|
stm32l100c6-a = [ "stm32-metapac/stm32l100c6-a" ]
|
||||||
stm32l100r8 = [ "stm32-metapac/stm32l100r8" ]
|
stm32l100r8 = [ "stm32-metapac/stm32l100r8" ]
|
||||||
stm32l100rb-a = [ "stm32-metapac/stm32l100rb-a" ]
|
stm32l100r8-a = [ "stm32-metapac/stm32l100r8-a" ]
|
||||||
stm32l100rb = [ "stm32-metapac/stm32l100rb" ]
|
stm32l100rb = [ "stm32-metapac/stm32l100rb" ]
|
||||||
|
stm32l100rb-a = [ "stm32-metapac/stm32l100rb-a" ]
|
||||||
stm32l100rc = [ "stm32-metapac/stm32l100rc" ]
|
stm32l100rc = [ "stm32-metapac/stm32l100rc" ]
|
||||||
stm32l151c6-a = [ "stm32-metapac/stm32l151c6-a" ]
|
|
||||||
stm32l151c6 = [ "stm32-metapac/stm32l151c6" ]
|
stm32l151c6 = [ "stm32-metapac/stm32l151c6" ]
|
||||||
stm32l151c8-a = [ "stm32-metapac/stm32l151c8-a" ]
|
stm32l151c6-a = [ "stm32-metapac/stm32l151c6-a" ]
|
||||||
stm32l151c8 = [ "stm32-metapac/stm32l151c8" ]
|
stm32l151c8 = [ "stm32-metapac/stm32l151c8" ]
|
||||||
stm32l151cb-a = [ "stm32-metapac/stm32l151cb-a" ]
|
stm32l151c8-a = [ "stm32-metapac/stm32l151c8-a" ]
|
||||||
stm32l151cb = [ "stm32-metapac/stm32l151cb" ]
|
stm32l151cb = [ "stm32-metapac/stm32l151cb" ]
|
||||||
|
stm32l151cb-a = [ "stm32-metapac/stm32l151cb-a" ]
|
||||||
stm32l151cc = [ "stm32-metapac/stm32l151cc" ]
|
stm32l151cc = [ "stm32-metapac/stm32l151cc" ]
|
||||||
stm32l151qc = [ "stm32-metapac/stm32l151qc" ]
|
stm32l151qc = [ "stm32-metapac/stm32l151qc" ]
|
||||||
stm32l151qd = [ "stm32-metapac/stm32l151qd" ]
|
stm32l151qd = [ "stm32-metapac/stm32l151qd" ]
|
||||||
stm32l151qe = [ "stm32-metapac/stm32l151qe" ]
|
stm32l151qe = [ "stm32-metapac/stm32l151qe" ]
|
||||||
stm32l151r6-a = [ "stm32-metapac/stm32l151r6-a" ]
|
|
||||||
stm32l151r6 = [ "stm32-metapac/stm32l151r6" ]
|
stm32l151r6 = [ "stm32-metapac/stm32l151r6" ]
|
||||||
stm32l151r8-a = [ "stm32-metapac/stm32l151r8-a" ]
|
stm32l151r6-a = [ "stm32-metapac/stm32l151r6-a" ]
|
||||||
stm32l151r8 = [ "stm32-metapac/stm32l151r8" ]
|
stm32l151r8 = [ "stm32-metapac/stm32l151r8" ]
|
||||||
stm32l151rb-a = [ "stm32-metapac/stm32l151rb-a" ]
|
stm32l151r8-a = [ "stm32-metapac/stm32l151r8-a" ]
|
||||||
stm32l151rb = [ "stm32-metapac/stm32l151rb" ]
|
stm32l151rb = [ "stm32-metapac/stm32l151rb" ]
|
||||||
stm32l151rc-a = [ "stm32-metapac/stm32l151rc-a" ]
|
stm32l151rb-a = [ "stm32-metapac/stm32l151rb-a" ]
|
||||||
stm32l151rc = [ "stm32-metapac/stm32l151rc" ]
|
stm32l151rc = [ "stm32-metapac/stm32l151rc" ]
|
||||||
|
stm32l151rc-a = [ "stm32-metapac/stm32l151rc-a" ]
|
||||||
stm32l151rd = [ "stm32-metapac/stm32l151rd" ]
|
stm32l151rd = [ "stm32-metapac/stm32l151rd" ]
|
||||||
stm32l151re = [ "stm32-metapac/stm32l151re" ]
|
stm32l151re = [ "stm32-metapac/stm32l151re" ]
|
||||||
stm32l151uc = [ "stm32-metapac/stm32l151uc" ]
|
stm32l151uc = [ "stm32-metapac/stm32l151uc" ]
|
||||||
stm32l151v8-a = [ "stm32-metapac/stm32l151v8-a" ]
|
|
||||||
stm32l151v8 = [ "stm32-metapac/stm32l151v8" ]
|
stm32l151v8 = [ "stm32-metapac/stm32l151v8" ]
|
||||||
stm32l151vb-a = [ "stm32-metapac/stm32l151vb-a" ]
|
stm32l151v8-a = [ "stm32-metapac/stm32l151v8-a" ]
|
||||||
stm32l151vb = [ "stm32-metapac/stm32l151vb" ]
|
stm32l151vb = [ "stm32-metapac/stm32l151vb" ]
|
||||||
stm32l151vc-a = [ "stm32-metapac/stm32l151vc-a" ]
|
stm32l151vb-a = [ "stm32-metapac/stm32l151vb-a" ]
|
||||||
stm32l151vc = [ "stm32-metapac/stm32l151vc" ]
|
stm32l151vc = [ "stm32-metapac/stm32l151vc" ]
|
||||||
stm32l151vd-x = [ "stm32-metapac/stm32l151vd-x" ]
|
stm32l151vc-a = [ "stm32-metapac/stm32l151vc-a" ]
|
||||||
stm32l151vd = [ "stm32-metapac/stm32l151vd" ]
|
stm32l151vd = [ "stm32-metapac/stm32l151vd" ]
|
||||||
|
stm32l151vd-x = [ "stm32-metapac/stm32l151vd-x" ]
|
||||||
stm32l151ve = [ "stm32-metapac/stm32l151ve" ]
|
stm32l151ve = [ "stm32-metapac/stm32l151ve" ]
|
||||||
stm32l151zc = [ "stm32-metapac/stm32l151zc" ]
|
stm32l151zc = [ "stm32-metapac/stm32l151zc" ]
|
||||||
stm32l151zd = [ "stm32-metapac/stm32l151zd" ]
|
stm32l151zd = [ "stm32-metapac/stm32l151zd" ]
|
||||||
stm32l151ze = [ "stm32-metapac/stm32l151ze" ]
|
stm32l151ze = [ "stm32-metapac/stm32l151ze" ]
|
||||||
stm32l152c6-a = [ "stm32-metapac/stm32l152c6-a" ]
|
|
||||||
stm32l152c6 = [ "stm32-metapac/stm32l152c6" ]
|
stm32l152c6 = [ "stm32-metapac/stm32l152c6" ]
|
||||||
stm32l152c8-a = [ "stm32-metapac/stm32l152c8-a" ]
|
stm32l152c6-a = [ "stm32-metapac/stm32l152c6-a" ]
|
||||||
stm32l152c8 = [ "stm32-metapac/stm32l152c8" ]
|
stm32l152c8 = [ "stm32-metapac/stm32l152c8" ]
|
||||||
stm32l152cb-a = [ "stm32-metapac/stm32l152cb-a" ]
|
stm32l152c8-a = [ "stm32-metapac/stm32l152c8-a" ]
|
||||||
stm32l152cb = [ "stm32-metapac/stm32l152cb" ]
|
stm32l152cb = [ "stm32-metapac/stm32l152cb" ]
|
||||||
|
stm32l152cb-a = [ "stm32-metapac/stm32l152cb-a" ]
|
||||||
stm32l152cc = [ "stm32-metapac/stm32l152cc" ]
|
stm32l152cc = [ "stm32-metapac/stm32l152cc" ]
|
||||||
stm32l152qc = [ "stm32-metapac/stm32l152qc" ]
|
stm32l152qc = [ "stm32-metapac/stm32l152qc" ]
|
||||||
stm32l152qd = [ "stm32-metapac/stm32l152qd" ]
|
stm32l152qd = [ "stm32-metapac/stm32l152qd" ]
|
||||||
stm32l152qe = [ "stm32-metapac/stm32l152qe" ]
|
stm32l152qe = [ "stm32-metapac/stm32l152qe" ]
|
||||||
stm32l152r6-a = [ "stm32-metapac/stm32l152r6-a" ]
|
|
||||||
stm32l152r6 = [ "stm32-metapac/stm32l152r6" ]
|
stm32l152r6 = [ "stm32-metapac/stm32l152r6" ]
|
||||||
stm32l152r8-a = [ "stm32-metapac/stm32l152r8-a" ]
|
stm32l152r6-a = [ "stm32-metapac/stm32l152r6-a" ]
|
||||||
stm32l152r8 = [ "stm32-metapac/stm32l152r8" ]
|
stm32l152r8 = [ "stm32-metapac/stm32l152r8" ]
|
||||||
stm32l152rb-a = [ "stm32-metapac/stm32l152rb-a" ]
|
stm32l152r8-a = [ "stm32-metapac/stm32l152r8-a" ]
|
||||||
stm32l152rb = [ "stm32-metapac/stm32l152rb" ]
|
stm32l152rb = [ "stm32-metapac/stm32l152rb" ]
|
||||||
stm32l152rc-a = [ "stm32-metapac/stm32l152rc-a" ]
|
stm32l152rb-a = [ "stm32-metapac/stm32l152rb-a" ]
|
||||||
stm32l152rc = [ "stm32-metapac/stm32l152rc" ]
|
stm32l152rc = [ "stm32-metapac/stm32l152rc" ]
|
||||||
|
stm32l152rc-a = [ "stm32-metapac/stm32l152rc-a" ]
|
||||||
stm32l152rd = [ "stm32-metapac/stm32l152rd" ]
|
stm32l152rd = [ "stm32-metapac/stm32l152rd" ]
|
||||||
stm32l152re = [ "stm32-metapac/stm32l152re" ]
|
stm32l152re = [ "stm32-metapac/stm32l152re" ]
|
||||||
stm32l152uc = [ "stm32-metapac/stm32l152uc" ]
|
stm32l152uc = [ "stm32-metapac/stm32l152uc" ]
|
||||||
stm32l152v8-a = [ "stm32-metapac/stm32l152v8-a" ]
|
|
||||||
stm32l152v8 = [ "stm32-metapac/stm32l152v8" ]
|
stm32l152v8 = [ "stm32-metapac/stm32l152v8" ]
|
||||||
stm32l152vb-a = [ "stm32-metapac/stm32l152vb-a" ]
|
stm32l152v8-a = [ "stm32-metapac/stm32l152v8-a" ]
|
||||||
stm32l152vb = [ "stm32-metapac/stm32l152vb" ]
|
stm32l152vb = [ "stm32-metapac/stm32l152vb" ]
|
||||||
stm32l152vc-a = [ "stm32-metapac/stm32l152vc-a" ]
|
stm32l152vb-a = [ "stm32-metapac/stm32l152vb-a" ]
|
||||||
stm32l152vc = [ "stm32-metapac/stm32l152vc" ]
|
stm32l152vc = [ "stm32-metapac/stm32l152vc" ]
|
||||||
stm32l152vd-x = [ "stm32-metapac/stm32l152vd-x" ]
|
stm32l152vc-a = [ "stm32-metapac/stm32l152vc-a" ]
|
||||||
stm32l152vd = [ "stm32-metapac/stm32l152vd" ]
|
stm32l152vd = [ "stm32-metapac/stm32l152vd" ]
|
||||||
|
stm32l152vd-x = [ "stm32-metapac/stm32l152vd-x" ]
|
||||||
stm32l152ve = [ "stm32-metapac/stm32l152ve" ]
|
stm32l152ve = [ "stm32-metapac/stm32l152ve" ]
|
||||||
stm32l152zc = [ "stm32-metapac/stm32l152zc" ]
|
stm32l152zc = [ "stm32-metapac/stm32l152zc" ]
|
||||||
stm32l152zd = [ "stm32-metapac/stm32l152zd" ]
|
stm32l152zd = [ "stm32-metapac/stm32l152zd" ]
|
||||||
stm32l152ze = [ "stm32-metapac/stm32l152ze" ]
|
stm32l152ze = [ "stm32-metapac/stm32l152ze" ]
|
||||||
stm32l162qc = [ "stm32-metapac/stm32l162qc" ]
|
stm32l162qc = [ "stm32-metapac/stm32l162qc" ]
|
||||||
stm32l162qd = [ "stm32-metapac/stm32l162qd" ]
|
stm32l162qd = [ "stm32-metapac/stm32l162qd" ]
|
||||||
stm32l162rc-a = [ "stm32-metapac/stm32l162rc-a" ]
|
|
||||||
stm32l162rc = [ "stm32-metapac/stm32l162rc" ]
|
stm32l162rc = [ "stm32-metapac/stm32l162rc" ]
|
||||||
|
stm32l162rc-a = [ "stm32-metapac/stm32l162rc-a" ]
|
||||||
stm32l162rd = [ "stm32-metapac/stm32l162rd" ]
|
stm32l162rd = [ "stm32-metapac/stm32l162rd" ]
|
||||||
stm32l162re = [ "stm32-metapac/stm32l162re" ]
|
stm32l162re = [ "stm32-metapac/stm32l162re" ]
|
||||||
stm32l162vc-a = [ "stm32-metapac/stm32l162vc-a" ]
|
|
||||||
stm32l162vc = [ "stm32-metapac/stm32l162vc" ]
|
stm32l162vc = [ "stm32-metapac/stm32l162vc" ]
|
||||||
stm32l162vd-x = [ "stm32-metapac/stm32l162vd-x" ]
|
stm32l162vc-a = [ "stm32-metapac/stm32l162vc-a" ]
|
||||||
stm32l162vd = [ "stm32-metapac/stm32l162vd" ]
|
stm32l162vd = [ "stm32-metapac/stm32l162vd" ]
|
||||||
|
stm32l162vd-x = [ "stm32-metapac/stm32l162vd-x" ]
|
||||||
stm32l162ve = [ "stm32-metapac/stm32l162ve" ]
|
stm32l162ve = [ "stm32-metapac/stm32l162ve" ]
|
||||||
stm32l162zc = [ "stm32-metapac/stm32l162zc" ]
|
stm32l162zc = [ "stm32-metapac/stm32l162zc" ]
|
||||||
stm32l162zd = [ "stm32-metapac/stm32l162zd" ]
|
stm32l162zd = [ "stm32-metapac/stm32l162zd" ]
|
||||||
|
@ -1370,4 +1369,3 @@ stm32wle5cc = [ "stm32-metapac/stm32wle5cc" ]
|
||||||
stm32wle5j8 = [ "stm32-metapac/stm32wle5j8" ]
|
stm32wle5j8 = [ "stm32-metapac/stm32wle5j8" ]
|
||||||
stm32wle5jb = [ "stm32-metapac/stm32wle5jb" ]
|
stm32wle5jb = [ "stm32-metapac/stm32wle5jb" ]
|
||||||
stm32wle5jc = [ "stm32-metapac/stm32wle5jc" ]
|
stm32wle5jc = [ "stm32-metapac/stm32wle5jc" ]
|
||||||
# END GENERATED FEATURES
|
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
Subproject commit 66252982939014e94fc4a1b7423c30c3d108ae0b
|
|
|
@ -1,3 +0,0 @@
|
||||||
[profile.dev]
|
|
||||||
opt-level = 3
|
|
||||||
lto = false
|
|
1
stm32-gen-features/.gitignore
vendored
1
stm32-gen-features/.gitignore
vendored
|
@ -1 +0,0 @@
|
||||||
/target
|
|
|
@ -1,11 +0,0 @@
|
||||||
[package]
|
|
||||||
name = "gen_features"
|
|
||||||
version = "0.1.0"
|
|
||||||
edition = "2021"
|
|
||||||
license = "MIT OR Apache-2.0"
|
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
glob = "0.3.0"
|
|
||||||
yaml-rust = "0.4.5"
|
|
|
@ -1,169 +0,0 @@
|
||||||
//! FIXME discuss about which errors to print and when to panic
|
|
||||||
|
|
||||||
use std::path::Path;
|
|
||||||
|
|
||||||
const SEPARATOR_START: &str = "# BEGIN GENERATED FEATURES\n";
|
|
||||||
const SEPARATOR_END: &str = "# END GENERATED FEATURES\n";
|
|
||||||
const HELP: &str = "# Generated by stm32-gen-features. DO NOT EDIT.\n";
|
|
||||||
|
|
||||||
/// Get the list of all the chips and their supported cores
|
|
||||||
///
|
|
||||||
/// Print errors to `stderr` when something is returned by the glob but is not in the returned
|
|
||||||
/// [`Vec`]
|
|
||||||
///
|
|
||||||
/// This function is slow because all the yaml files are parsed.
|
|
||||||
pub fn chip_names_and_cores() -> Vec<(String, Vec<String>)> {
|
|
||||||
glob::glob("../stm32-data/data/chips/*.json")
|
|
||||||
.unwrap()
|
|
||||||
.filter_map(|entry| entry.map_err(|e| eprintln!("{:?}", e)).ok())
|
|
||||||
.filter_map(|entry| {
|
|
||||||
if let Some(name) = entry.file_stem().and_then(|stem| stem.to_str()) {
|
|
||||||
Some((name.to_lowercase(), chip_cores(&entry)))
|
|
||||||
} else {
|
|
||||||
eprintln!("{:?} is not a regular file", entry);
|
|
||||||
None
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.collect()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get the list of the cores of a chip by its associated file
|
|
||||||
///
|
|
||||||
/// # Panic
|
|
||||||
/// Panics if the file does not exist or if it contains yaml syntax errors.
|
|
||||||
/// Panics if "cores" is not an array.
|
|
||||||
fn chip_cores(path: &Path) -> Vec<String> {
|
|
||||||
let file_contents = std::fs::read_to_string(path).unwrap();
|
|
||||||
let doc = &yaml_rust::YamlLoader::load_from_str(&file_contents).unwrap()[0];
|
|
||||||
doc["cores"]
|
|
||||||
.as_vec()
|
|
||||||
.unwrap_or_else(|| panic!("{:?}:[cores] is not an array", path))
|
|
||||||
.iter()
|
|
||||||
.enumerate()
|
|
||||||
.map(|(i, core)| {
|
|
||||||
core["name"]
|
|
||||||
.as_str()
|
|
||||||
.unwrap_or_else(|| panic!("{:?}:[cores][{}][name] is not a string", path, i))
|
|
||||||
.to_owned()
|
|
||||||
})
|
|
||||||
.collect()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Generate data needed in `../embassy-stm32/Cargo.toml`
|
|
||||||
///
|
|
||||||
/// Print errors to `stderr` when something is returned by the glob but is not in the returned
|
|
||||||
/// [`Vec`]
|
|
||||||
///
|
|
||||||
/// # Panic
|
|
||||||
/// Panics if a file contains yaml syntax errors or if a value does not have a consistent type
|
|
||||||
pub fn embassy_stm32_needed_data(names_and_cores: &[(String, Vec<String>)]) -> String {
|
|
||||||
let mut result = String::new();
|
|
||||||
for (chip_name, cores) in names_and_cores {
|
|
||||||
if cores.len() > 1 {
|
|
||||||
for core_name in cores.iter() {
|
|
||||||
result += &format!(
|
|
||||||
"{chip}-{core} = [ \"stm32-metapac/{chip}-{core}\" ]\n",
|
|
||||||
chip = chip_name,
|
|
||||||
core = core_name
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
result += &format!("{chip} = [ \"stm32-metapac/{chip}\" ]\n", chip = chip_name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
result
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Generate data needed in `../stm32-metapac/Cargo.toml`
|
|
||||||
///
|
|
||||||
/// Print errors to `stderr` when something is returned by the glob but is not in the returned
|
|
||||||
/// [`Vec`]
|
|
||||||
///
|
|
||||||
/// # Panic
|
|
||||||
/// Panics if a file contains yaml syntax errors or if a value does not have a consistent type
|
|
||||||
pub fn stm32_metapac_needed_data(names_and_cores: &[(String, Vec<String>)]) -> String {
|
|
||||||
let mut result = String::new();
|
|
||||||
for (chip_name, cores) in names_and_cores {
|
|
||||||
if cores.len() > 1 {
|
|
||||||
for core_name in cores {
|
|
||||||
result += &format!("{}-{} = []\n", chip_name, core_name);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
result += &format!("{} = []\n", chip_name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
result
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get contents before and after generated contents
|
|
||||||
///
|
|
||||||
/// # Panic
|
|
||||||
/// Panics when a separator cound not be not found
|
|
||||||
fn split_cargo_toml_contents(contents: &str) -> (&str, &str) {
|
|
||||||
let (before, remainder) = contents
|
|
||||||
.split_once(SEPARATOR_START)
|
|
||||||
.unwrap_or_else(|| panic!("missing \"{}\" tag", SEPARATOR_START));
|
|
||||||
let (_, after) = remainder
|
|
||||||
.split_once(SEPARATOR_END)
|
|
||||||
.unwrap_or_else(|| panic!("missing \"{}\" tag", SEPARATOR_END));
|
|
||||||
|
|
||||||
(before, after)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Generates new contents for Cargo.toml
|
|
||||||
///
|
|
||||||
/// # Panic
|
|
||||||
/// Panics when a separator cound not be not found
|
|
||||||
pub fn generate_cargo_toml_file(previous_text: &str, new_contents: &str) -> String {
|
|
||||||
let (before, after) = split_cargo_toml_contents(previous_text);
|
|
||||||
before.to_owned() + SEPARATOR_START + HELP + new_contents + SEPARATOR_END + after
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
#[ignore]
|
|
||||||
fn stm32f407vg_yaml_file_exists() {
|
|
||||||
assert!(chip_names_and_cores()
|
|
||||||
.as_slice()
|
|
||||||
.into_iter()
|
|
||||||
.any(|(name, _)| { name == "stm32f407vg" }))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn keeps_text_around_separators() {
|
|
||||||
let initial = "\
|
|
||||||
before
|
|
||||||
# BEGIN GENERATED FEATURES
|
|
||||||
# END GENERATED FEATURES
|
|
||||||
after
|
|
||||||
";
|
|
||||||
|
|
||||||
let expected = "\
|
|
||||||
before
|
|
||||||
# BEGIN GENERATED FEATURES
|
|
||||||
# Generated by stm32-gen-features. DO NOT EDIT.
|
|
||||||
a = [\"b\"]
|
|
||||||
# END GENERATED FEATURES
|
|
||||||
after
|
|
||||||
";
|
|
||||||
|
|
||||||
let new_contents = String::from("a = [\"b\"]\n");
|
|
||||||
assert_eq!(generate_cargo_toml_file(initial, &new_contents), expected);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
#[should_panic]
|
|
||||||
fn does_not_generate_if_separators_are_missing() {
|
|
||||||
let initial = "\
|
|
||||||
before
|
|
||||||
# END GENERATED FEATURES
|
|
||||||
after
|
|
||||||
";
|
|
||||||
|
|
||||||
let new_contents = String::from("a = [\"b\"]\n");
|
|
||||||
generate_cargo_toml_file(initial, &new_contents);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,25 +0,0 @@
|
||||||
use gen_features::{
|
|
||||||
chip_names_and_cores, embassy_stm32_needed_data, generate_cargo_toml_file, stm32_metapac_needed_data,
|
|
||||||
};
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
let names_and_cores = chip_names_and_cores();
|
|
||||||
update_cargo_file(
|
|
||||||
"../embassy-stm32/Cargo.toml",
|
|
||||||
&embassy_stm32_needed_data(&names_and_cores),
|
|
||||||
);
|
|
||||||
update_cargo_file(
|
|
||||||
"../stm32-metapac/Cargo.toml",
|
|
||||||
&stm32_metapac_needed_data(&names_and_cores),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Update a Cargo.toml file
|
|
||||||
///
|
|
||||||
/// Update the content between "# BEGIN GENERATED FEATURES" and "# END GENERATED FEATURES"
|
|
||||||
/// with the given content
|
|
||||||
fn update_cargo_file(path: &str, new_contents: &str) {
|
|
||||||
let previous_text = std::fs::read_to_string(path).unwrap();
|
|
||||||
let new_text = generate_cargo_toml_file(&previous_text, new_contents);
|
|
||||||
std::fs::write(path, new_text).unwrap();
|
|
||||||
}
|
|
|
@ -1,15 +0,0 @@
|
||||||
[package]
|
|
||||||
name = "stm32-metapac-gen"
|
|
||||||
version = "0.1.0"
|
|
||||||
edition = "2021"
|
|
||||||
license = "MIT OR Apache-2.0"
|
|
||||||
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
regex = "1.5.4"
|
|
||||||
chiptool = { git = "https://github.com/embassy-rs/chiptool", rev = "1d9e0a39a6acc291e50cabc4ed617a87f06d5e89" }
|
|
||||||
serde = { version = "1.0.130", features = [ "derive" ] }
|
|
||||||
serde_json = "1.0.87"
|
|
||||||
serde_yaml = "0.8.21"
|
|
||||||
proc-macro2 = "1.0.29"
|
|
||||||
|
|
|
@ -1,124 +0,0 @@
|
||||||
use serde::Deserialize;
|
|
||||||
|
|
||||||
#[derive(Debug, Eq, PartialEq, Clone, Deserialize)]
|
|
||||||
pub struct Chip {
|
|
||||||
pub name: String,
|
|
||||||
pub family: String,
|
|
||||||
pub line: String,
|
|
||||||
pub cores: Vec<Core>,
|
|
||||||
pub memory: Vec<MemoryRegion>,
|
|
||||||
pub packages: Vec<Package>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Eq, PartialEq, Clone, Deserialize)]
|
|
||||||
pub struct MemoryRegion {
|
|
||||||
pub name: String,
|
|
||||||
pub kind: MemoryRegionKind,
|
|
||||||
pub address: u32,
|
|
||||||
pub size: u32,
|
|
||||||
pub settings: Option<FlashSettings>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Eq, PartialEq, Clone, Deserialize)]
|
|
||||||
pub struct FlashSettings {
|
|
||||||
pub erase_size: u32,
|
|
||||||
pub write_size: u32,
|
|
||||||
pub erase_value: u8,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Eq, PartialEq, Clone, Deserialize)]
|
|
||||||
pub enum MemoryRegionKind {
|
|
||||||
#[serde(rename = "flash")]
|
|
||||||
Flash,
|
|
||||||
#[serde(rename = "ram")]
|
|
||||||
Ram,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Eq, PartialEq, Clone, Deserialize)]
|
|
||||||
pub struct Core {
|
|
||||||
pub name: String,
|
|
||||||
pub peripherals: Vec<Peripheral>,
|
|
||||||
pub interrupts: Vec<Interrupt>,
|
|
||||||
pub dma_channels: Vec<DmaChannel>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Eq, PartialEq, Clone, Deserialize)]
|
|
||||||
pub struct Interrupt {
|
|
||||||
pub name: String,
|
|
||||||
pub number: u32,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[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 name: String,
|
|
||||||
pub address: u64,
|
|
||||||
#[serde(default)]
|
|
||||||
pub registers: Option<PeripheralRegisters>,
|
|
||||||
#[serde(default)]
|
|
||||||
pub rcc: Option<PeripheralRcc>,
|
|
||||||
#[serde(default)]
|
|
||||||
pub pins: Vec<PeripheralPin>,
|
|
||||||
#[serde(default)]
|
|
||||||
pub dma_channels: Vec<PeripheralDmaChannel>,
|
|
||||||
#[serde(default)]
|
|
||||||
pub interrupts: Vec<PeripheralInterrupt>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Eq, PartialEq, Clone, Deserialize)]
|
|
||||||
pub struct PeripheralInterrupt {
|
|
||||||
pub signal: String,
|
|
||||||
pub interrupt: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Eq, PartialEq, Clone, Deserialize)]
|
|
||||||
pub struct PeripheralRcc {
|
|
||||||
pub clock: String,
|
|
||||||
#[serde(default)]
|
|
||||||
pub enable: Option<PeripheralRccRegister>,
|
|
||||||
#[serde(default)]
|
|
||||||
pub reset: Option<PeripheralRccRegister>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Eq, PartialEq, Clone, Deserialize)]
|
|
||||||
pub struct PeripheralRccRegister {
|
|
||||||
pub register: String,
|
|
||||||
pub field: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Eq, PartialEq, Clone, Deserialize)]
|
|
||||||
pub struct PeripheralPin {
|
|
||||||
pub pin: String,
|
|
||||||
pub signal: String,
|
|
||||||
pub af: Option<u8>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Eq, PartialEq, Clone, Deserialize)]
|
|
||||||
pub struct DmaChannel {
|
|
||||||
pub name: String,
|
|
||||||
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 signal: String,
|
|
||||||
pub channel: Option<String>,
|
|
||||||
pub dmamux: Option<String>,
|
|
||||||
pub dma: Option<String>,
|
|
||||||
pub request: Option<u32>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Hash)]
|
|
||||||
pub struct PeripheralRegisters {
|
|
||||||
pub kind: String,
|
|
||||||
pub version: String,
|
|
||||||
pub block: String,
|
|
||||||
}
|
|
|
@ -1,380 +0,0 @@
|
||||||
use std::collections::{BTreeMap, HashMap, HashSet};
|
|
||||||
use std::fmt::{Debug, Write as _};
|
|
||||||
use std::fs;
|
|
||||||
use std::fs::File;
|
|
||||||
use std::io::Write;
|
|
||||||
use std::path::{Path, PathBuf};
|
|
||||||
use std::str::FromStr;
|
|
||||||
|
|
||||||
use chiptool::generate::CommonModule;
|
|
||||||
use chiptool::{generate, ir, transform};
|
|
||||||
use proc_macro2::TokenStream;
|
|
||||||
use regex::Regex;
|
|
||||||
|
|
||||||
mod data;
|
|
||||||
use data::*;
|
|
||||||
|
|
||||||
#[derive(Debug, Eq, PartialEq, Clone)]
|
|
||||||
struct Metadata<'a> {
|
|
||||||
name: &'a str,
|
|
||||||
family: &'a str,
|
|
||||||
line: &'a str,
|
|
||||||
memory: &'a [MemoryRegion],
|
|
||||||
peripherals: &'a [Peripheral],
|
|
||||||
interrupts: &'a [Interrupt],
|
|
||||||
dma_channels: &'a [DmaChannel],
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct Options {
|
|
||||||
pub chips: Vec<String>,
|
|
||||||
pub out_dir: PathBuf,
|
|
||||||
pub data_dir: PathBuf,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct Gen {
|
|
||||||
opts: Options,
|
|
||||||
all_peripheral_versions: HashSet<(String, String)>,
|
|
||||||
metadata_dedup: HashMap<String, String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Gen {
|
|
||||||
pub fn new(opts: Options) -> Self {
|
|
||||||
Self {
|
|
||||||
opts,
|
|
||||||
all_peripheral_versions: HashSet::new(),
|
|
||||||
metadata_dedup: HashMap::new(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn gen_chip(&mut self, chip_core_name: &str, chip: &Chip, core: &Core, core_index: usize) {
|
|
||||||
let mut ir = ir::IR::new();
|
|
||||||
|
|
||||||
let mut dev = ir::Device {
|
|
||||||
interrupts: Vec::new(),
|
|
||||||
peripherals: Vec::new(),
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut peripheral_versions: BTreeMap<String, String> = BTreeMap::new();
|
|
||||||
|
|
||||||
let gpio_base = core.peripherals.iter().find(|p| p.name == "GPIOA").unwrap().address as u32;
|
|
||||||
let gpio_stride = 0x400;
|
|
||||||
|
|
||||||
for p in &core.peripherals {
|
|
||||||
let mut ir_peri = ir::Peripheral {
|
|
||||||
name: p.name.clone(),
|
|
||||||
array: None,
|
|
||||||
base_address: p.address,
|
|
||||||
block: None,
|
|
||||||
description: None,
|
|
||||||
interrupts: HashMap::new(),
|
|
||||||
};
|
|
||||||
|
|
||||||
if let Some(bi) = &p.registers {
|
|
||||||
if let Some(old_version) = peripheral_versions.insert(bi.kind.clone(), bi.version.clone()) {
|
|
||||||
if old_version != bi.version {
|
|
||||||
panic!(
|
|
||||||
"Peripheral {} has multiple versions: {} and {}",
|
|
||||||
bi.kind, old_version, bi.version
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ir_peri.block = Some(format!("{}::{}", bi.kind, bi.block));
|
|
||||||
|
|
||||||
if bi.kind == "gpio" {
|
|
||||||
assert_eq!(0, (p.address as u32 - gpio_base) % gpio_stride);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
dev.peripherals.push(ir_peri);
|
|
||||||
}
|
|
||||||
|
|
||||||
for irq in &core.interrupts {
|
|
||||||
dev.interrupts.push(ir::Interrupt {
|
|
||||||
name: irq.name.clone(),
|
|
||||||
description: None,
|
|
||||||
value: irq.number,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
ir.devices.insert("".to_string(), dev);
|
|
||||||
|
|
||||||
let mut extra = format!(
|
|
||||||
"pub fn GPIO(n: usize) -> gpio::Gpio {{
|
|
||||||
gpio::Gpio(({} + {}*n) as _)
|
|
||||||
}}",
|
|
||||||
gpio_base, gpio_stride,
|
|
||||||
);
|
|
||||||
|
|
||||||
for (module, version) in &peripheral_versions {
|
|
||||||
self.all_peripheral_versions.insert((module.clone(), version.clone()));
|
|
||||||
write!(
|
|
||||||
&mut extra,
|
|
||||||
"#[path=\"../../peripherals/{}_{}.rs\"] pub mod {};\n",
|
|
||||||
module, version, module
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
write!(&mut extra, "pub const CORE_INDEX: usize = {};\n", core_index).unwrap();
|
|
||||||
|
|
||||||
let flash = chip.memory.iter().find(|r| r.name == "BANK_1").unwrap();
|
|
||||||
let settings = flash.settings.as_ref().unwrap();
|
|
||||||
write!(&mut extra, "pub const FLASH_BASE: usize = {};\n", flash.address).unwrap();
|
|
||||||
write!(&mut extra, "pub const FLASH_SIZE: usize = {};\n", flash.size).unwrap();
|
|
||||||
write!(&mut extra, "pub const ERASE_SIZE: usize = {};\n", settings.erase_size).unwrap();
|
|
||||||
write!(&mut extra, "pub const WRITE_SIZE: usize = {};\n", settings.write_size).unwrap();
|
|
||||||
write!(&mut extra, "pub const ERASE_VALUE: u8 = {};\n", settings.erase_value).unwrap();
|
|
||||||
|
|
||||||
// Cleanups!
|
|
||||||
transform::sort::Sort {}.run(&mut ir).unwrap();
|
|
||||||
transform::Sanitize {}.run(&mut ir).unwrap();
|
|
||||||
|
|
||||||
// ==============================
|
|
||||||
// Setup chip dir
|
|
||||||
|
|
||||||
let chip_dir = self
|
|
||||||
.opts
|
|
||||||
.out_dir
|
|
||||||
.join("src/chips")
|
|
||||||
.join(chip_core_name.to_ascii_lowercase());
|
|
||||||
fs::create_dir_all(&chip_dir).unwrap();
|
|
||||||
|
|
||||||
// ==============================
|
|
||||||
// generate pac.rs
|
|
||||||
|
|
||||||
let data = generate::render(&ir, &gen_opts()).unwrap().to_string();
|
|
||||||
let data = data.replace("] ", "]\n");
|
|
||||||
|
|
||||||
// Remove inner attributes like #![no_std]
|
|
||||||
let data = Regex::new("# *! *\\[.*\\]").unwrap().replace_all(&data, "");
|
|
||||||
|
|
||||||
let mut file = File::create(chip_dir.join("pac.rs")).unwrap();
|
|
||||||
file.write_all(data.as_bytes()).unwrap();
|
|
||||||
file.write_all(extra.as_bytes()).unwrap();
|
|
||||||
|
|
||||||
let mut device_x = String::new();
|
|
||||||
|
|
||||||
for irq in &core.interrupts {
|
|
||||||
write!(&mut device_x, "PROVIDE({} = DefaultHandler);\n", irq.name).unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
// ==============================
|
|
||||||
// generate metadata.rs
|
|
||||||
|
|
||||||
// (peripherals, interrupts, dma_channels) are often equal across multiple chips.
|
|
||||||
// To reduce bloat, deduplicate them.
|
|
||||||
let mut data = String::new();
|
|
||||||
write!(
|
|
||||||
&mut data,
|
|
||||||
"
|
|
||||||
const PERIPHERALS: &'static [Peripheral] = {};
|
|
||||||
const INTERRUPTS: &'static [Interrupt] = {};
|
|
||||||
const DMA_CHANNELS: &'static [DmaChannel] = {};
|
|
||||||
",
|
|
||||||
stringify(&core.peripherals),
|
|
||||||
stringify(&core.interrupts),
|
|
||||||
stringify(&core.dma_channels),
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let out_dir = self.opts.out_dir.clone();
|
|
||||||
let n = self.metadata_dedup.len();
|
|
||||||
let deduped_file = self.metadata_dedup.entry(data.clone()).or_insert_with(|| {
|
|
||||||
let file = format!("metadata_{:04}.rs", n);
|
|
||||||
let path = out_dir.join("src/chips").join(&file);
|
|
||||||
fs::write(path, data).unwrap();
|
|
||||||
|
|
||||||
file
|
|
||||||
});
|
|
||||||
|
|
||||||
let data = format!(
|
|
||||||
"include!(\"../{}\");
|
|
||||||
pub const METADATA: Metadata = Metadata {{
|
|
||||||
name: {:?},
|
|
||||||
family: {:?},
|
|
||||||
line: {:?},
|
|
||||||
memory: {},
|
|
||||||
peripherals: PERIPHERALS,
|
|
||||||
interrupts: INTERRUPTS,
|
|
||||||
dma_channels: DMA_CHANNELS,
|
|
||||||
}};",
|
|
||||||
deduped_file,
|
|
||||||
&chip.name,
|
|
||||||
&chip.family,
|
|
||||||
&chip.line,
|
|
||||||
stringify(&chip.memory),
|
|
||||||
);
|
|
||||||
|
|
||||||
let mut file = File::create(chip_dir.join("metadata.rs")).unwrap();
|
|
||||||
file.write_all(data.as_bytes()).unwrap();
|
|
||||||
|
|
||||||
// ==============================
|
|
||||||
// generate device.x
|
|
||||||
|
|
||||||
File::create(chip_dir.join("device.x"))
|
|
||||||
.unwrap()
|
|
||||||
.write_all(device_x.as_bytes())
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
// ==============================
|
|
||||||
// generate default memory.x
|
|
||||||
gen_memory_x(&chip_dir, &chip);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn load_chip(&mut self, name: &str) -> Chip {
|
|
||||||
let chip_path = self.opts.data_dir.join("chips").join(&format!("{}.json", name));
|
|
||||||
let chip = fs::read(chip_path).expect(&format!("Could not load chip {}", name));
|
|
||||||
serde_json::from_slice(&chip).unwrap()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn gen(&mut self) {
|
|
||||||
fs::create_dir_all(self.opts.out_dir.join("src/peripherals")).unwrap();
|
|
||||||
fs::create_dir_all(self.opts.out_dir.join("src/chips")).unwrap();
|
|
||||||
|
|
||||||
let mut chip_core_names: Vec<String> = Vec::new();
|
|
||||||
|
|
||||||
for chip_name in &self.opts.chips.clone() {
|
|
||||||
println!("Generating {}...", chip_name);
|
|
||||||
|
|
||||||
let mut chip = self.load_chip(chip_name);
|
|
||||||
|
|
||||||
// Cleanup
|
|
||||||
for core in &mut chip.cores {
|
|
||||||
for irq in &mut core.interrupts {
|
|
||||||
irq.name = irq.name.to_ascii_uppercase();
|
|
||||||
}
|
|
||||||
for p in &mut core.peripherals {
|
|
||||||
for irq in &mut p.interrupts {
|
|
||||||
irq.interrupt = irq.interrupt.to_ascii_uppercase();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Generate
|
|
||||||
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());
|
|
||||||
self.gen_chip(&chip_core_name, &chip, core, core_index)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (module, version) in &self.all_peripheral_versions {
|
|
||||||
println!("loading {} {}", module, version);
|
|
||||||
|
|
||||||
let regs_path = Path::new(&self.opts.data_dir)
|
|
||||||
.join("registers")
|
|
||||||
.join(&format!("{}_{}.yaml", module, version));
|
|
||||||
|
|
||||||
let mut ir: ir::IR = serde_yaml::from_reader(File::open(regs_path).unwrap()).unwrap();
|
|
||||||
|
|
||||||
transform::expand_extends::ExpandExtends {}.run(&mut ir).unwrap();
|
|
||||||
|
|
||||||
transform::map_names(&mut ir, |k, s| match k {
|
|
||||||
transform::NameKind::Block => *s = format!("{}", s),
|
|
||||||
transform::NameKind::Fieldset => *s = format!("regs::{}", s),
|
|
||||||
transform::NameKind::Enum => *s = format!("vals::{}", s),
|
|
||||||
_ => {}
|
|
||||||
});
|
|
||||||
|
|
||||||
transform::sort::Sort {}.run(&mut ir).unwrap();
|
|
||||||
transform::Sanitize {}.run(&mut ir).unwrap();
|
|
||||||
|
|
||||||
let items = generate::render(&ir, &gen_opts()).unwrap();
|
|
||||||
let mut file = File::create(
|
|
||||||
self.opts
|
|
||||||
.out_dir
|
|
||||||
.join("src/peripherals")
|
|
||||||
.join(format!("{}_{}.rs", module, version)),
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
let data = items.to_string().replace("] ", "]\n");
|
|
||||||
|
|
||||||
// Remove inner attributes like #![no_std]
|
|
||||||
let re = Regex::new("# *! *\\[.*\\]").unwrap();
|
|
||||||
let data = re.replace_all(&data, "");
|
|
||||||
file.write_all(data.as_bytes()).unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Generate Cargo.toml
|
|
||||||
const BUILDDEP_BEGIN: &[u8] = b"# BEGIN BUILD DEPENDENCIES";
|
|
||||||
const BUILDDEP_END: &[u8] = b"# END BUILD DEPENDENCIES";
|
|
||||||
|
|
||||||
let mut contents = include_bytes!("../../stm32-metapac/Cargo.toml").to_vec();
|
|
||||||
let begin = bytes_find(&contents, BUILDDEP_BEGIN).unwrap();
|
|
||||||
let end = bytes_find(&contents, BUILDDEP_END).unwrap() + BUILDDEP_END.len();
|
|
||||||
contents.drain(begin..end);
|
|
||||||
fs::write(self.opts.out_dir.join("Cargo.toml"), contents).unwrap();
|
|
||||||
|
|
||||||
// copy misc files
|
|
||||||
fs::write(
|
|
||||||
self.opts.out_dir.join("build.rs"),
|
|
||||||
include_bytes!("../../stm32-metapac/build_pregenerated.rs"),
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
fs::write(
|
|
||||||
self.opts.out_dir.join("src/lib.rs"),
|
|
||||||
include_bytes!("../../stm32-metapac/src/lib.rs"),
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
fs::write(
|
|
||||||
self.opts.out_dir.join("src/common.rs"),
|
|
||||||
chiptool::generate::COMMON_MODULE,
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
fs::write(
|
|
||||||
self.opts.out_dir.join("src/metadata.rs"),
|
|
||||||
include_bytes!("../../stm32-metapac/src/metadata.rs"),
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn bytes_find(haystack: &[u8], needle: &[u8]) -> Option<usize> {
|
|
||||||
haystack.windows(needle.len()).position(|window| window == needle)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn stringify<T: Debug>(metadata: T) -> String {
|
|
||||||
let mut metadata = format!("{:?}", metadata);
|
|
||||||
if metadata.starts_with('[') {
|
|
||||||
metadata = format!("&{}", metadata);
|
|
||||||
}
|
|
||||||
metadata = metadata.replace(": [", ": &[");
|
|
||||||
metadata = metadata.replace("kind: Ram", "kind: MemoryRegionKind::Ram");
|
|
||||||
metadata = metadata.replace("kind: Flash", "kind: MemoryRegionKind::Flash");
|
|
||||||
metadata
|
|
||||||
}
|
|
||||||
|
|
||||||
fn gen_opts() -> generate::Options {
|
|
||||||
generate::Options {
|
|
||||||
common_module: CommonModule::External(TokenStream::from_str("crate::common").unwrap()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn gen_memory_x(out_dir: &PathBuf, chip: &Chip) {
|
|
||||||
let mut memory_x = String::new();
|
|
||||||
|
|
||||||
let flash = chip.memory.iter().find(|r| r.name == "BANK_1").unwrap();
|
|
||||||
let ram = chip.memory.iter().find(|r| r.name == "SRAM").unwrap();
|
|
||||||
|
|
||||||
write!(memory_x, "MEMORY\n{{\n").unwrap();
|
|
||||||
write!(
|
|
||||||
memory_x,
|
|
||||||
" FLASH : ORIGIN = 0x{:x}, LENGTH = {}\n",
|
|
||||||
flash.address, flash.size,
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
write!(
|
|
||||||
memory_x,
|
|
||||||
" RAM : ORIGIN = 0x{:x}, LENGTH = {}\n",
|
|
||||||
ram.address, ram.size,
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
write!(memory_x, "}}").unwrap();
|
|
||||||
|
|
||||||
fs::create_dir_all(out_dir.join("memory_x")).unwrap();
|
|
||||||
let mut file = File::create(out_dir.join("memory_x").join("memory.x")).unwrap();
|
|
||||||
file.write_all(memory_x.as_bytes()).unwrap();
|
|
||||||
}
|
|
|
@ -1,36 +0,0 @@
|
||||||
use std::env::args;
|
|
||||||
use std::path::PathBuf;
|
|
||||||
|
|
||||||
use stm32_metapac_gen::*;
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
let out_dir = PathBuf::from("out");
|
|
||||||
let data_dir = PathBuf::from("../stm32-data/data");
|
|
||||||
|
|
||||||
let args: Vec<String> = args().collect();
|
|
||||||
|
|
||||||
let mut chips = match &args[..] {
|
|
||||||
[_, chip] => {
|
|
||||||
vec![chip.clone()]
|
|
||||||
}
|
|
||||||
[_] => {
|
|
||||||
std::fs::read_dir(data_dir.join("chips"))
|
|
||||||
.unwrap()
|
|
||||||
.filter_map(|res| res.unwrap().file_name().to_str().map(|s| s.to_string()))
|
|
||||||
.filter(|s| s.ends_with(".json"))
|
|
||||||
.filter(|s| !s.starts_with("STM32GBK")) // cursed weird STM32G4
|
|
||||||
.map(|s| s.strip_suffix(".json").unwrap().to_string())
|
|
||||||
.collect()
|
|
||||||
}
|
|
||||||
_ => panic!("usage: stm32-metapac-gen [chip?]"),
|
|
||||||
};
|
|
||||||
|
|
||||||
chips.sort();
|
|
||||||
|
|
||||||
let opts = Options {
|
|
||||||
out_dir,
|
|
||||||
data_dir,
|
|
||||||
chips,
|
|
||||||
};
|
|
||||||
Gen::new(opts).gen();
|
|
||||||
}
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,77 +0,0 @@
|
||||||
use std::env;
|
|
||||||
use std::path::PathBuf;
|
|
||||||
|
|
||||||
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() {
|
|
||||||
let out_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap());
|
|
||||||
let data_dir = PathBuf::from("../stm32-data/data");
|
|
||||||
|
|
||||||
let chip_core_name = env::vars_os()
|
|
||||||
.map(|(a, _)| a.to_string_lossy().to_string())
|
|
||||||
.find(|x| x.starts_with("CARGO_FEATURE_STM32"))
|
|
||||||
.expect("No stm32xx Cargo feature enabled")
|
|
||||||
.strip_prefix("CARGO_FEATURE_")
|
|
||||||
.unwrap()
|
|
||||||
.to_ascii_lowercase()
|
|
||||||
.replace('_', "-");
|
|
||||||
|
|
||||||
let (chip_name, _) = parse_chip_core(&chip_core_name);
|
|
||||||
|
|
||||||
let opts = Options {
|
|
||||||
out_dir: out_dir.clone(),
|
|
||||||
data_dir: data_dir.clone(),
|
|
||||||
chips: vec![chip_name.to_ascii_uppercase()],
|
|
||||||
};
|
|
||||||
Gen::new(opts).gen();
|
|
||||||
|
|
||||||
println!(
|
|
||||||
"cargo:rustc-link-search={}/src/chips/{}",
|
|
||||||
out_dir.display(),
|
|
||||||
chip_core_name,
|
|
||||||
);
|
|
||||||
|
|
||||||
#[cfg(feature = "memory-x")]
|
|
||||||
println!(
|
|
||||||
"cargo:rustc-link-search={}/src/chips/{}/memory_x/",
|
|
||||||
out_dir.display(),
|
|
||||||
chip_core_name
|
|
||||||
);
|
|
||||||
println!(
|
|
||||||
"cargo:rustc-env=STM32_METAPAC_PAC_PATH={}/src/chips/{}/pac.rs",
|
|
||||||
out_dir.display(),
|
|
||||||
chip_core_name
|
|
||||||
);
|
|
||||||
println!(
|
|
||||||
"cargo:rustc-env=STM32_METAPAC_METADATA_PATH={}/src/chips/{}/metadata.rs",
|
|
||||||
out_dir.display(),
|
|
||||||
chip_core_name
|
|
||||||
);
|
|
||||||
println!(
|
|
||||||
"cargo:rustc-env=STM32_METAPAC_COMMON_PATH={}/src/common.rs",
|
|
||||||
out_dir.display(),
|
|
||||||
);
|
|
||||||
|
|
||||||
println!("cargo:rerun-if-changed=build.rs");
|
|
||||||
|
|
||||||
// When the stm32-data chip's JSON changes, we must rebuild
|
|
||||||
println!(
|
|
||||||
"cargo:rerun-if-changed={}/chips/{}.json",
|
|
||||||
data_dir.display(),
|
|
||||||
chip_name.to_uppercase()
|
|
||||||
);
|
|
||||||
|
|
||||||
println!("cargo:rerun-if-changed={}/registers", data_dir.display());
|
|
||||||
}
|
|
|
@ -1,39 +0,0 @@
|
||||||
use std::env;
|
|
||||||
use std::path::PathBuf;
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
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())
|
|
||||||
.find(|x| x.starts_with("CARGO_FEATURE_STM32"))
|
|
||||||
.expect("No stm32xx Cargo feature enabled")
|
|
||||||
.strip_prefix("CARGO_FEATURE_")
|
|
||||||
.unwrap()
|
|
||||||
.to_ascii_lowercase()
|
|
||||||
.replace('_', "-");
|
|
||||||
|
|
||||||
println!(
|
|
||||||
"cargo:rustc-link-search={}/src/chips/{}",
|
|
||||||
crate_dir.display(),
|
|
||||||
chip_core_name,
|
|
||||||
);
|
|
||||||
|
|
||||||
#[cfg(feature = "memory-x")]
|
|
||||||
println!(
|
|
||||||
"cargo:rustc-link-search={}/src/chips/{}/memory_x/",
|
|
||||||
crate_dir.display(),
|
|
||||||
chip_core_name
|
|
||||||
);
|
|
||||||
println!("cargo:rustc-env=STM32_METAPAC_PAC_PATH=chips/{}/pac.rs", chip_core_name);
|
|
||||||
println!(
|
|
||||||
"cargo:rustc-env=STM32_METAPAC_METADATA_PATH=chips/{}/metadata.rs",
|
|
||||||
chip_core_name
|
|
||||||
);
|
|
||||||
println!(
|
|
||||||
"cargo:rustc-env=STM32_METAPAC_COMMON_PATH={}/src/common.rs",
|
|
||||||
crate_dir.display(),
|
|
||||||
);
|
|
||||||
|
|
||||||
println!("cargo:rerun-if-changed=build.rs");
|
|
||||||
}
|
|
|
@ -1,18 +0,0 @@
|
||||||
#![no_std]
|
|
||||||
#![allow(non_snake_case)]
|
|
||||||
#![allow(unused)]
|
|
||||||
#![allow(non_camel_case_types)]
|
|
||||||
#![doc(html_no_source)]
|
|
||||||
|
|
||||||
pub mod common {
|
|
||||||
include!(env!("STM32_METAPAC_COMMON_PATH"));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "pac")]
|
|
||||||
include!(env!("STM32_METAPAC_PAC_PATH"));
|
|
||||||
|
|
||||||
#[cfg(feature = "metadata")]
|
|
||||||
pub mod metadata {
|
|
||||||
include!("metadata.rs");
|
|
||||||
include!(env!("STM32_METAPAC_METADATA_PATH"));
|
|
||||||
}
|
|
|
@ -1,106 +0,0 @@
|
||||||
#[derive(Debug, Eq, PartialEq, Clone)]
|
|
||||||
pub struct Metadata {
|
|
||||||
pub name: &'static str,
|
|
||||||
pub family: &'static str,
|
|
||||||
pub line: &'static str,
|
|
||||||
pub memory: &'static [MemoryRegion],
|
|
||||||
pub peripherals: &'static [Peripheral],
|
|
||||||
pub interrupts: &'static [Interrupt],
|
|
||||||
pub dma_channels: &'static [DmaChannel],
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Eq, PartialEq, Clone)]
|
|
||||||
pub struct MemoryRegion {
|
|
||||||
pub name: &'static str,
|
|
||||||
pub kind: MemoryRegionKind,
|
|
||||||
pub address: u32,
|
|
||||||
pub size: u32,
|
|
||||||
pub settings: Option<FlashSettings>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Eq, PartialEq, Clone)]
|
|
||||||
pub struct FlashSettings {
|
|
||||||
pub erase_size: u32,
|
|
||||||
pub write_size: u32,
|
|
||||||
pub erase_value: u8,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Eq, PartialEq, Clone)]
|
|
||||||
pub enum MemoryRegionKind {
|
|
||||||
Flash,
|
|
||||||
Ram,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Eq, PartialEq, Clone)]
|
|
||||||
pub struct Interrupt {
|
|
||||||
pub name: &'static str,
|
|
||||||
pub number: u32,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Eq, PartialEq, Clone)]
|
|
||||||
pub struct Package {
|
|
||||||
pub name: &'static str,
|
|
||||||
pub package: &'static str,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Eq, PartialEq, Clone)]
|
|
||||||
pub struct Peripheral {
|
|
||||||
pub name: &'static str,
|
|
||||||
pub address: u64,
|
|
||||||
pub registers: Option<PeripheralRegisters>,
|
|
||||||
pub rcc: Option<PeripheralRcc>,
|
|
||||||
pub pins: &'static [PeripheralPin],
|
|
||||||
pub dma_channels: &'static [PeripheralDmaChannel],
|
|
||||||
pub interrupts: &'static [PeripheralInterrupt],
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Eq, PartialEq, Clone)]
|
|
||||||
pub struct PeripheralRegisters {
|
|
||||||
pub kind: &'static str,
|
|
||||||
pub version: &'static str,
|
|
||||||
pub block: &'static str,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Eq, PartialEq, Clone)]
|
|
||||||
pub struct PeripheralInterrupt {
|
|
||||||
pub signal: &'static str,
|
|
||||||
pub interrupt: &'static str,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Eq, PartialEq, Clone)]
|
|
||||||
pub struct PeripheralRcc {
|
|
||||||
pub clock: &'static str,
|
|
||||||
pub enable: Option<PeripheralRccRegister>,
|
|
||||||
pub reset: Option<PeripheralRccRegister>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Eq, PartialEq, Clone)]
|
|
||||||
pub struct PeripheralRccRegister {
|
|
||||||
pub register: &'static str,
|
|
||||||
pub field: &'static str,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Eq, PartialEq, Clone)]
|
|
||||||
pub struct PeripheralPin {
|
|
||||||
pub pin: &'static str,
|
|
||||||
pub signal: &'static str,
|
|
||||||
pub af: Option<u8>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Eq, PartialEq, Clone)]
|
|
||||||
pub struct DmaChannel {
|
|
||||||
pub name: &'static str,
|
|
||||||
pub dma: &'static str,
|
|
||||||
pub channel: u32,
|
|
||||||
pub dmamux: Option<&'static str>,
|
|
||||||
pub dmamux_channel: Option<u32>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Eq, PartialEq, Clone)]
|
|
||||||
pub struct PeripheralDmaChannel {
|
|
||||||
pub signal: &'static str,
|
|
||||||
pub channel: Option<&'static str>,
|
|
||||||
pub dmamux: Option<&'static str>,
|
|
||||||
pub dma: Option<&'static str>,
|
|
||||||
pub request: Option<u32>,
|
|
||||||
}
|
|
|
@ -1,6 +0,0 @@
|
||||||
[alias]
|
|
||||||
xtask = "run --package xtask --"
|
|
||||||
ci = "run --package xtask -- ci"
|
|
||||||
core = "run --package xtask -- core"
|
|
||||||
examples = "run --package xtask -- examples"
|
|
||||||
fmt = "run --package xtask -- fmt"
|
|
|
@ -1,11 +0,0 @@
|
||||||
[package]
|
|
||||||
edition = "2021"
|
|
||||||
name = "xtask"
|
|
||||||
version = "0.1.0"
|
|
||||||
license = "MIT OR Apache-2.0"
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
anyhow = "1.0.43"
|
|
||||||
xshell = "0.1.17"
|
|
||||||
yaml-rust = "0.4.5"
|
|
||||||
walkdir = "2.3.2"
|
|
|
@ -1,221 +0,0 @@
|
||||||
#![allow(dead_code)]
|
|
||||||
#![deny(unused_must_use)]
|
|
||||||
|
|
||||||
use std::path::{Path, PathBuf};
|
|
||||||
use std::{env, format, fs};
|
|
||||||
|
|
||||||
use walkdir::WalkDir;
|
|
||||||
use xshell::{cmd, Cmd};
|
|
||||||
use yaml_rust::YamlLoader;
|
|
||||||
|
|
||||||
extern crate yaml_rust;
|
|
||||||
|
|
||||||
fn main() -> Result<(), anyhow::Error> {
|
|
||||||
let args = env::args().skip(1).collect::<Vec<_>>();
|
|
||||||
let args = args.iter().map(|s| &**s).collect::<Vec<_>>();
|
|
||||||
|
|
||||||
match &args[..] {
|
|
||||||
["ci"] => task_ci()?,
|
|
||||||
["core"] => task_check(Realm::Core)?,
|
|
||||||
["metapac"] => task_metapac_gen()?,
|
|
||||||
["examples"] => task_check(Realm::Examples)?,
|
|
||||||
["fmt-check"] => task_cargo_fmt_check()?,
|
|
||||||
["fmt"] => task_cargo_fmt()?,
|
|
||||||
_ => {
|
|
||||||
println!("");
|
|
||||||
println!("USAGE: cargo xtask [command]");
|
|
||||||
println!("");
|
|
||||||
println!("Commands:");
|
|
||||||
println!(" ci :: Runs entire CI");
|
|
||||||
println!(" core :: Builds the core");
|
|
||||||
println!(" metapac :: Builds the metapac");
|
|
||||||
println!(" examples :: Builds the examples");
|
|
||||||
println!(" fmt-check :: Checks rustfmt");
|
|
||||||
println!(" fmt :: Performs rustfmt");
|
|
||||||
println!("");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn task_ci() -> Result<(), anyhow::Error> {
|
|
||||||
task_check(Realm::Core)?;
|
|
||||||
task_check(Realm::Examples)?;
|
|
||||||
task_metapac_gen()?;
|
|
||||||
task_cargo_fmt_check()?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Copy, Clone)]
|
|
||||||
enum Realm {
|
|
||||||
All,
|
|
||||||
Core,
|
|
||||||
Examples,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Realm {
|
|
||||||
fn accepts(&self, package: &str) -> bool {
|
|
||||||
match self {
|
|
||||||
Realm::All => true,
|
|
||||||
Realm::Core => !package.contains("examples"),
|
|
||||||
Realm::Examples => package.contains("examples"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn task_check(realm: Realm) -> Result<(), anyhow::Error> {
|
|
||||||
let _e = xshell::pushenv("CI", "true");
|
|
||||||
|
|
||||||
let matrix_yaml = root_dir().join(".github").join("workflows").join("rust.yml");
|
|
||||||
|
|
||||||
let matrix = YamlLoader::load_from_str(&*fs::read_to_string(matrix_yaml).unwrap()).unwrap();
|
|
||||||
|
|
||||||
let matrix = &matrix.get(0).unwrap()["jobs"]["ci"]["strategy"]["matrix"]["include"];
|
|
||||||
|
|
||||||
let entries = matrix.as_vec().unwrap();
|
|
||||||
|
|
||||||
for entry in entries {
|
|
||||||
let package = entry["package"].as_str().unwrap();
|
|
||||||
if !realm.accepts(package) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
let target = entry["target"].as_str().unwrap();
|
|
||||||
let features = entry["features"].as_str();
|
|
||||||
let package_dir = root_dir().join(entry["package"].as_str().unwrap());
|
|
||||||
let _p = xshell::pushd(package_dir)?;
|
|
||||||
banner(&*format!(
|
|
||||||
"Building {} [target={}] [features={}]",
|
|
||||||
package,
|
|
||||||
target,
|
|
||||||
features.unwrap_or("default-features")
|
|
||||||
));
|
|
||||||
|
|
||||||
let root_cargo_dir = root_dir().join(".cargo");
|
|
||||||
fs::create_dir_all(root_cargo_dir.clone()).unwrap();
|
|
||||||
fs::write(
|
|
||||||
root_cargo_dir.join("config"),
|
|
||||||
"[target.\"cfg(all())\"]\nrustflags = [\"-D\", \"warnings\"]",
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let mut args = Vec::new();
|
|
||||||
args.push("check");
|
|
||||||
args.push("--target");
|
|
||||||
args.push(target);
|
|
||||||
|
|
||||||
if let Some(features) = features {
|
|
||||||
args.push("--features");
|
|
||||||
args.push(features);
|
|
||||||
}
|
|
||||||
|
|
||||||
let command = Cmd::new(PathBuf::from("cargo"));
|
|
||||||
let command = command.args(args);
|
|
||||||
let result = command.run();
|
|
||||||
|
|
||||||
fs::remove_file(root_cargo_dir.join("config")).unwrap();
|
|
||||||
|
|
||||||
result?;
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn task_metapac_gen() -> Result<(), anyhow::Error> {
|
|
||||||
banner("Building metapac");
|
|
||||||
let _p = xshell::pushd(root_dir().join("stm32-metapac-gen"));
|
|
||||||
cmd!("cargo run").run()?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn task_cargo_fmt() -> Result<(), anyhow::Error> {
|
|
||||||
for entry in WalkDir::new(root_dir())
|
|
||||||
.follow_links(false)
|
|
||||||
.into_iter()
|
|
||||||
.filter_map(|e| e.ok())
|
|
||||||
{
|
|
||||||
let f_name = entry.file_name().to_string_lossy();
|
|
||||||
|
|
||||||
if f_name.ends_with(".rs") {
|
|
||||||
if !is_primary_source(entry.path()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
let mut args = Vec::new();
|
|
||||||
args.push("--skip-children");
|
|
||||||
args.push("--unstable-features");
|
|
||||||
args.push("--edition=2018");
|
|
||||||
args.push(&*entry.path().to_str().unwrap());
|
|
||||||
let command = Cmd::new("rustfmt");
|
|
||||||
command.args(args).run()?;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn task_cargo_fmt_check() -> Result<(), anyhow::Error> {
|
|
||||||
let mut actual_result = Ok(());
|
|
||||||
for entry in WalkDir::new(root_dir())
|
|
||||||
.follow_links(false)
|
|
||||||
.into_iter()
|
|
||||||
.filter_map(|e| e.ok())
|
|
||||||
{
|
|
||||||
let f_name = entry.file_name().to_string_lossy();
|
|
||||||
|
|
||||||
if f_name.ends_with(".rs") {
|
|
||||||
if !is_primary_source(entry.path()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
let mut args = Vec::new();
|
|
||||||
args.push("--check");
|
|
||||||
args.push("--skip-children");
|
|
||||||
args.push("--unstable-features");
|
|
||||||
args.push("--edition=2018");
|
|
||||||
args.push(&*entry.path().to_str().unwrap());
|
|
||||||
let command = Cmd::new("rustfmt");
|
|
||||||
if let Err(result) = command.args(args).run() {
|
|
||||||
actual_result = Err(result.into());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
actual_result
|
|
||||||
}
|
|
||||||
|
|
||||||
fn root_dir() -> PathBuf {
|
|
||||||
let mut xtask_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
|
||||||
xtask_dir.pop();
|
|
||||||
xtask_dir
|
|
||||||
}
|
|
||||||
|
|
||||||
fn examples_dir() -> PathBuf {
|
|
||||||
root_dir().join("examples")
|
|
||||||
}
|
|
||||||
|
|
||||||
fn is_primary_source(path: &Path) -> bool {
|
|
||||||
let mut current = path;
|
|
||||||
|
|
||||||
loop {
|
|
||||||
let current_file_name = current.file_name().unwrap().to_str().unwrap();
|
|
||||||
if current_file_name == "target"
|
|
||||||
|| current_file_name == "stm32-metapac-gen"
|
|
||||||
|| current_file_name == "stm32-data"
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(path) = current.parent() {
|
|
||||||
current = path.into();
|
|
||||||
if current == root_dir() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn banner(text: &str) {
|
|
||||||
println!("------------------------------------------------------------------------------------------------------------------------------------------------");
|
|
||||||
println!("== {}", text);
|
|
||||||
println!("------------------------------------------------------------------------------------------------------------------------------------------------");
|
|
||||||
}
|
|
Loading…
Reference in a new issue