Skip to content

Commit 58b8ac9

Browse files
committed
Merge branch 'main' into feat/add-ble-headers
2 parents 633e30f + 6d9597a commit 58b8ac9

File tree

9 files changed

+67
-43
lines changed

9 files changed

+67
-43
lines changed

.github/workflows/rust.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ jobs:
2929
- name: Load sources
3030
run: ./d download-all
3131
- name: Run build
32-
run: cargo run --release --bin stm32-bindings-gen -- --target=thumbv8m.main-none-eabihf
32+
run: cargo run --release --bin stm32-bindings-gen
3333
- name: Run package build
3434
run: cd build/stm32-bindings && cargo build --target=thumbv8m.main-none-eabihf

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// Uncomment the target of your chip.
1616
// "rust-analyzer.cargo.target": "thumbv6m-none-eabi",
1717
//"rust-analyzer.cargo.target": "thumbv7m-none-eabi",
18-
"rust-analyzer.cargo.target": "thumbv7em-none-eabi",
18+
// "rust-analyzer.cargo.target": "thumbv7em-none-eabi",
1919
//"rust-analyzer.cargo.target": "thumbv7em-none-eabihf",
2020
// "rust-analyzer.cargo.target": "thumbv8m.main-none-eabihf",
2121
"rust-analyzer.cargo.features": [],

d

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,17 @@ set -e
44
cd $(dirname $0)
55

66
CMD=$1
7-
REV=8382ecbcc976ab5e91070b386700dbfd1e654275
7+
REV=v1.8.0
88
shift
99

1010
case "$CMD" in
1111
gen)
12-
cargo run --release stm32-bindings-gen -- --target=thumbv8m.main-none-eabihf
12+
cargo run --release stm32-bindings-gen
1313
;;
1414
download-all)
1515
rm -rf ./sources/
16-
git clone https://github.com/STMicroelectronics/STM32CubeWBA.git ./sources/ -q
16+
git clone --branch $REV https://github.com/STMicroelectronics/STM32CubeWBA.git ./sources/STM32CubeWBA/ --depth 1 -q
1717
cd ./sources/
18-
git checkout $REV
1918
;;
2019
*)
2120
echo "unknown command"

d.ps1

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,15 @@ param (
66
[string]$peri
77
)
88

9-
$REV = "8382ecbcc976ab5e91070b386700dbfd1e654275"
9+
$REV = "v1.8.0"
1010

1111
Switch ($CMD) {
1212
"gen" {
13-
cargo run --release stm32-bindings-gen -- --target=thumbv8m.main-none-eabihf
13+
cargo run --release stm32-bindings-gen
1414
}
1515
"download-all" {
1616
rm -r -Force ./sources/ -ErrorAction SilentlyContinue
17-
git clone https://github.com/STMicroelectronics/STM32CubeWBA.git ./sources/
18-
cd ./sources/
19-
git checkout $REV
17+
git clone --branch $REV https://github.com/STMicroelectronics/STM32CubeWBA.git ./sources/STM32CubeWBA/ --depth 1 -q
2018
cd ..
2119
}
2220
default {

stm32-bindings-gen/res/Cargo.toml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "stm32-bindings"
3-
version = "18.0.0"
3+
version = "0.1.0"
44
edition = "2024"
55
license = "MIT OR Apache-2.0"
66
repository = "https://github.com/embassy-rs/stm32-data"
@@ -15,8 +15,8 @@ include = [
1515
]
1616

1717
[package.metadata.docs.rs]
18-
features = ["stm32h755zi-cm7", "pac", "metadata"]
19-
default-target = "thumbv7em-none-eabihf"
18+
features = []
19+
default-target = "thumbv8m.main-none-eabihf"
2020
targets = []
2121
rustdoc-args = ["--cfg", "docsrs"]
2222

@@ -53,6 +53,10 @@ defmt = { version = "0.3.0", optional = true }
5353
[features]
5454
default = ["pac"]
5555

56+
wba_wpan_mac = []
57+
wba_wpan_ble = []
58+
n6_ai_runtime = []
59+
5660
# Build the actual PAC. Set by default.
5761
# If you just want the metadata, unset it with `default-features = false`.
5862
pac = []
Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1-
pub mod ble_stack;
2-
pub mod mac_802_15_4;
3-
4-
pub use self::mac_802_15_4 as mac;
5-
pub use self::mac_802_15_4 as wpan_wba;
1+
#[cfg(feature = "wba_wpan_mac")]
2+
pub mod wba_wpan_mac;
3+
#[cfg(feature = "wba_wpan_mac")]
4+
pub use self::wba_wpan_mac as mac_802_15_4;
5+
#[cfg(feature = "wba_wpan_mac")]
6+
pub use self::wba_wpan_mac as wpan_wba;
67

8+
#[cfg(feature = "wba_wpan_ble")]
9+
pub mod ble_stack;
10+
#[cfg(feature = "wba_wpan_ble")]
711
pub use self::ble_stack as ble;
12+
#[cfg(feature = "wba_wpan_ble")]
813
pub use self::ble_stack as ble_wba;

stm32-bindings-gen/src/lib.rs

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const STD_TO_CORE_REPLACEMENTS: &[(&str, &str)] = &[
1717
#[derive(Debug, Clone, Copy)]
1818
struct BindingSpec {
1919
module: &'static str,
20+
feature: Option<&'static str>,
2021
header: &'static str,
2122
include_dirs: &'static [&'static str],
2223
clang_args: &'static [&'static str],
@@ -33,26 +34,27 @@ struct LibraryArtifact {
3334

3435
const BINDING_SPECS: &[BindingSpec] = &[
3536
BindingSpec {
36-
module: "mac_802_15_4",
37-
header: "stm32-bindings-gen/inc/wpan-wba.h",
37+
module: "wba_wpan_mac",
38+
feature: Some("wba_wpan_mac"),
39+
header: "stm32-bindings-gen/inc/wba_wpan_mac.h",
3840
include_dirs: &[
41+
"Middlewares/ST/STM32_WPAN",
3942
"Middlewares/ST/STM32_WPAN/mac_802_15_4/core/inc",
4043
"Middlewares/ST/STM32_WPAN/mac_802_15_4/mac_utilities/inc",
41-
"Middlewares/ST/STM32_WPAN",
42-
"Drivers/CMSIS/Core/Include",
44+
"Middlewares/ST/STM32_WPAN/link_layer/ll_cmd_lib/inc",
4345
"Middlewares/ST/STM32_WPAN/link_layer/ll_cmd_lib/inc/_40nm_reg_files",
46+
"Middlewares/ST/STM32_WPAN/link_layer/ll_cmd_lib/inc/ot_inc",
4447
"Middlewares/ST/STM32_WPAN/link_layer/ll_cmd_lib/config",
4548
"Middlewares/ST/STM32_WPAN/link_layer/ll_cmd_lib/config/ieee_15_4_basic",
46-
"Middlewares/ST/STM32_WPAN/link_layer/ll_cmd_lib/inc",
47-
"Middlewares/ST/STM32_WPAN/link_layer/ll_cmd_lib/inc/ot_inc",
49+
"Drivers/CMSIS/Core/Include",
4850
],
4951
clang_args: &["-DSUPPORT_MAC=1", "-DMAC=1", "-DMAC_LAYER=1"],
5052
allowlist: &[],
51-
aliases: &["mac", "wpan_wba"],
53+
aliases: &["mac", "mac_802_15_4", "wpan_wba"],
5254
library_artifacts: &[
5355
LibraryArtifact {
5456
source: "Middlewares/ST/STM32_WPAN/mac_802_15_4/lib",
55-
destination: "src/lib/mac",
57+
destination: "src/lib/wba_wpan_mac",
5658
},
5759
LibraryArtifact {
5860
source: "Middlewares/ST/STM32_WPAN/mac_802_15_4/lib/wba_mac_lib.a",
@@ -66,20 +68,21 @@ const BINDING_SPECS: &[BindingSpec] = &[
6668
},
6769
BindingSpec {
6870
module: "ble_stack",
71+
feature: Some("wba_wpan_ble"),
6972
header: "stm32-bindings-gen/inc/ble-wba.h",
7073
include_dirs: &[
74+
"Middlewares/ST/STM32_WPAN",
7175
"Middlewares/ST/STM32_WPAN/ble/stack/include",
7276
"Middlewares/ST/STM32_WPAN/ble/stack/include/auto",
73-
"Middlewares/ST/STM32_WPAN",
74-
"Drivers/CMSIS/Core/Include",
77+
"Middlewares/ST/STM32_WPAN/link_layer/ll_cmd_lib/inc",
7578
"Middlewares/ST/STM32_WPAN/link_layer/ll_cmd_lib/inc/_40nm_reg_files",
79+
"Middlewares/ST/STM32_WPAN/link_layer/ll_cmd_lib/inc/ot_inc",
7680
"Middlewares/ST/STM32_WPAN/link_layer/ll_cmd_lib/config",
7781
"Middlewares/ST/STM32_WPAN/link_layer/ll_cmd_lib/config/ble_basic_plus",
78-
"Middlewares/ST/STM32_WPAN/link_layer/ll_cmd_lib/inc",
79-
"Middlewares/ST/STM32_WPAN/link_layer/ll_cmd_lib/inc/ot_inc",
8082
"Middlewares/ST/STM32_WPAN/ble/audio/Inc",
8183
"Middlewares/ST/STM32_WPAN/ble/codec/codec_manager/Inc",
8284
"Middlewares/ST/STM32_WPAN/ble/codec/lc3/Inc",
85+
"Drivers/CMSIS/Core/Include",
8386
],
8487
clang_args: &["-DBLE=1", "-DSUPPORT_BLE=1", "-DEXT_ADDRESS_LENGTH=8"],
8588
allowlist: &[],
@@ -162,13 +165,19 @@ impl Gen {
162165

163166
let mut modules = Vec::new();
164167
let mut aliases = Vec::new();
168+
165169
for spec in BINDING_SPECS {
166170
println!(" -> generating `{}` bindings", spec.module);
167171
self.generate_bindings_for_spec(spec);
168172
self.copy_artifacts_for_spec(spec);
169-
modules.push(spec.module.to_owned());
173+
174+
modules.push((spec.module.to_owned(), spec.feature.map(str::to_owned)));
170175
for alias in spec.aliases {
171-
aliases.push((spec.module.to_owned(), alias.to_string()));
176+
aliases.push((
177+
spec.module.to_owned(),
178+
alias.to_string(),
179+
spec.feature.map(str::to_owned),
180+
));
172181
}
173182
}
174183

@@ -188,16 +197,26 @@ impl Gen {
188197
self.write_bytes("src/lib.rs", include_bytes!("../res/src/lib.rs"));
189198
}
190199

191-
fn write_bindings_mod(&self, modules: &[String], aliases: &[(String, String)]) {
200+
fn write_bindings_mod(
201+
&self,
202+
modules: &[(String, Option<String>)],
203+
aliases: &[(String, String, Option<String>)],
204+
) {
192205
let mut body = String::new();
193-
for module in modules {
206+
for (module, feature) in modules {
207+
if let Some(feature) = feature {
208+
body.push_str(&format!("#[cfg(feature = \"{feature}\")]\n"));
209+
}
194210
body.push_str("pub mod ");
195211
body.push_str(module);
196212
body.push_str(";\n");
197213
}
198214
if !aliases.is_empty() {
199215
body.push('\n');
200-
for (module, alias) in aliases {
216+
for (module, alias, feature) in aliases {
217+
if let Some(feature) = feature {
218+
body.push_str(&format!("#[cfg(feature = \"{feature}\")]\n"));
219+
}
201220
body.push_str("pub use self::");
202221
body.push_str(module);
203222
body.push_str(" as ");
@@ -273,9 +292,8 @@ impl Gen {
273292
self.copy_file(&src, &dst)
274293
.unwrap_or_else(|err| panic!("Failed to copy file {}: {err}", src.display()));
275294
} else if src.is_dir() {
276-
self.copy_dir(&src, &dst).unwrap_or_else(|err| {
277-
panic!("Failed to copy directory {}: {err}", src.display())
278-
});
295+
self.copy_dir(&src, &dst)
296+
.unwrap_or_else(|err| panic!("Failed to copy dir {}: {err}", src.display()));
279297
} else {
280298
panic!(
281299
"Artifact source {} is neither file nor directory",
@@ -345,7 +363,7 @@ impl Gen {
345363
contents = contents.replace(from, to);
346364
}
347365

348-
let normalized = contents
366+
contents
349367
.lines()
350368
.map(|line| {
351369
if let Some(rest) = line.strip_prefix("pub const ") {
@@ -357,9 +375,7 @@ impl Gen {
357375
line.to_owned()
358376
})
359377
.collect::<Vec<_>>()
360-
.join("\n");
361-
362-
normalized
378+
.join("\n")
363379
}
364380

365381
fn is_thumb_target(triple: &str) -> bool {

stm32-bindings-gen/src/main.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ fn main() {
1212
sources_dir,
1313
target_triple,
1414
};
15+
1516
Gen::new(opts).run_gen();
1617
}
1718

19+
#[allow(dead_code)]
1820
fn resolve_target_triple() -> String {
1921
let mut args = env::args().skip(1);
2022
let mut positional: Option<String> = None;

0 commit comments

Comments
 (0)