Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,24 @@ jobs:
run: ./d download-all
- name: Run build
run: cargo run --release --bin stm32-bindings-gen
- name: Check wba-linklayer
run: cargo check --manifest-path wba-linklayer/Cargo.toml
- name: Run package build
run: |
cd build/stm32-bindings
export CARGO_BUILD_TARGET=thumbv8m.main-none-eabihf
cargo fix --lib -p stm32-bindings --allow-no-vcs
cargo build
cargo package
ls target/package
for crate_dir in linklayer-bindings; do
echo "::group::Packaging ${crate_dir}"
(
cd build/${crate_dir}
cargo fix --lib --allow-no-vcs --target ${CARGO_BUILD_TARGET}
cargo build --target ${CARGO_BUILD_TARGET}
cargo package
ls target/package
)
echo "::endgroup::"
done
- name: Upload package build
uses: actions/upload-artifact@v4
with:
name: crate
path: build/stm32-bindings/target/package/*.crate
path: build/*-bindings/target/package/*.crate
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ members = [
"stm32-bindings-gen",
]
exclude = [
"build"
"build",
"wba-linklayer",
]

# Optimize for dev experience: shortest "build+run" time after making a small change.
Expand Down
24 changes: 24 additions & 0 deletions stm32-bindings-gen/res/ble/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[package]
name = "ble-bindings"
version = "0.1.0"
edition = "2024"
license = "MIT OR Apache-2.0"
description = "Raw STM32 WBA BLE stack bindings generated from the ST middleware."
build = "build.rs"

[lib]
path = "src/lib.rs"

[dependencies]
linklayer-bindings = { path = "../linklayer-bindings" }

[features]
default = []
lib_stm32wba_ble_stack_po = []
lib_stm32wba_ble_stack_llo = []
lib_stm32wba_ble_stack_full = []
lib_stm32wba_ble_stack_basic = []
lib_stm32wba_ble_stack_basic_plus = []
lib_lc3 = []
lib_codec_mngr = []
lib_ble_audio = []
28 changes: 28 additions & 0 deletions stm32-bindings-gen/res/ble/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# ble-bindings

Raw bindings for the STM32 WBA Bluetooth Low Energy stack. This crate is generated automatically by `stm32-bindings-gen` and is meant to be consumed by higher-level wrappers that expose safe BLE abstractions.

## Overview

The generator ingests the ST middleware headers and prebuilt static libraries, then uses `bindgen` to emit Rust FFI items. Everything in this crate mirrors the original C API one-to-one; you should treat every item as `unsafe` and build ergonomic wrappers in a separate crate.

## Layout

- `src/bindings/`: Modules produced by `bindgen`, containing raw FFI definitions.
- `src/lib/`: Static libraries copied from the STM32CubeWBA distribution. Selecting the proper feature toggles which archives get linked.
- `build.rs`: Registers the static libraries with Cargo based on the enabled features.

## Usage

1. Run `cargo run -p stm32-bindings-gen` so this crate is regenerated under `build/ble-bindings`.
2. Add a path dependency in your Cargo manifest pointing to that directory.
3. Enable the feature corresponding to the static library variant required by your project (e.g. `lib_stm32wba_ble_stack_full`).
4. Wrap the raw FFI functions in a higher-level API before exposing them to the rest of your system.

## Feature Flags

Each `lib_*` feature matches a static archive provided by ST. Enable exactly the variants you need and the build script will emit the proper `cargo:rustc-link-lib` entries.

## Regeneration

If the underlying middleware or binding configuration changes, rerun `cargo run -p stm32-bindings-gen`. The generator will overwrite this crate with the latest bindings, libraries, and metadata.
41 changes: 41 additions & 0 deletions stm32-bindings-gen/res/ble/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use std::path::{Path, PathBuf};
use std::{env, fs, io};

fn add_dir(dir: &Path) -> io::Result<()> {
if !dir.exists() {
return Ok(());
}

println!("cargo:rustc-link-search=native={}", dir.display());

for entry in fs::read_dir(dir)? {
let entry = entry?;
let path = entry.path();
if path.is_dir() {
add_dir(&path)?;
}
}

Ok(())
}

fn main() {
let crate_dir = PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").unwrap());
let lib_dir = crate_dir.join("src").join("lib");
let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap_or_default();
let target_family = env::var("CARGO_CFG_TARGET_FAMILY").unwrap_or_default();
let is_embedded = target_os == "none" || target_family == "embedded";

if !is_embedded {
return;
}

add_dir(&lib_dir).expect("failed to add link search paths");

env::vars()
.filter_map(|(key, _)| {
key.strip_prefix("CARGO_FEATURE_LIB_")
.map(|suffix| suffix.to_ascii_lowercase())
})
.for_each(|lib| println!("cargo:rustc-link-lib=static={lib}"));
}
14 changes: 14 additions & 0 deletions stm32-bindings-gen/res/ble/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#![no_std]
#![allow(non_snake_case)]
#![allow(non_camel_case_types)]
#![allow(non_upper_case_globals)]
#![doc(html_no_source)]

/// Raw bindings generated by `stm32-bindings-gen`.
///
/// The `bindings` module is produced by `bindgen` and exposes a one-to-one FFI
/// surface to the STM32 WBA BLE middleware. All items should be treated as
/// `unsafe` and wrapped by higher-level crates before use.
pub mod bindings;

pub use bindings::*;
46 changes: 46 additions & 0 deletions stm32-bindings-gen/res/linklayer/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
[package]
name = "linklayer-bindings"
version = "0.1.0"
edition = "2024"
license = "MIT OR Apache-2.0"
description = "Raw STM32 WBA link-layer bindings generated from the ST middleware."
build = "build.rs"

[lib]
path = "src/lib.rs"

[dependencies]

[features]
default = []
lib_wba5_linklayer_ble_basic_20_links_lib = []
lib_wba5_linklayer_ble_basic_lib = []
lib_wba5_linklayer_ble_basic_plus_20_links_lib = []
lib_wba5_linklayer_ble_basic_plus_lib = []
lib_wba5_linklayer_ble_full_lib = []
lib_wba5_linklayer_ble_mac_lib = []
lib_wba5_linklayer_ble_peripheral_only_lib = []
lib_wba5_linklayer_ble_thread_lib = []
lib_wba5_linklayer_rawmac_lib = []
lib_wba5_linklayer_thread_lib = []
lib_wba5_linklayer15_4 = []
lib_wba6_linklayer_ble_basic_20_links_lib = []
lib_wba6_linklayer_ble_basic_lib = []
lib_wba6_linklayer_ble_basic_plus_20_links_lib = []
lib_wba6_linklayer_ble_basic_plus_lib = []
lib_wba6_linklayer_ble_full_lib = []
lib_wba6_linklayer_ble_mac_lib = []
lib_wba6_linklayer_ble_peripheral_only_lib = []
lib_wba6_linklayer_ble_thread_lib = []
lib_wba6_linklayer_rawmac_lib = []
lib_wba6_linklayer_thread_lib = []
lib_wba6_linklayer15_4 = []
lib_wba_mac_lib = []
lib_stm32wba_ble_stack_basic = []
lib_stm32wba_ble_stack_basic_plus = []
lib_stm32wba_ble_stack_full = []
lib_stm32wba_ble_stack_llo = []
lib_stm32wba_ble_stack_po = []
lib_lc3 = []
lib_codec_mngr = []
lib_ble_audio = []
28 changes: 28 additions & 0 deletions stm32-bindings-gen/res/linklayer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# linklayer-bindings

Raw bindings for the STM32 WBA link-layer middleware. This crate is generated automatically by `stm32-bindings-gen` and is intended to be consumed by higher-level wrappers that provide safe abstractions for BLE or IEEE 802.15.4 stacks.

## Overview

The generator pulls in STM-provided headers and static libraries, then runs `bindgen` to emit Rust FFI shims. No additional logic lives here—consumers should treat every item as `unsafe` and wrap it before use.

## Layout

- `src/bindings/`: Raw Rust modules produced by `bindgen`.
- `src/lib/`: Static libraries copied from the STM32CubeWBA middleware tree, gated behind Cargo features.
- `build.rs`: Emits the appropriate `cargo:rustc-link-*` directives based on the selected features.

## Usage

1. Ensure `stm32-bindings-gen` has been run so this crate exists in `build/linklayer-bindings`.
2. Add a path dependency in your Cargo manifest pointing at that directory.
3. Opt into the desired static library variant by enabling the matching `lib_*` feature exposed by this crate.
4. Call the generated functions through `unsafe` code and wrap them in a higher-level API before exposing them to the rest of your application.

## Feature Flags

Each feature named `lib_<variant>` selects one of the prebuilt static archives shipped by ST. Enable exactly the libraries required by your firmware configuration; the build script will link them automatically.

## Regeneration

If the upstream ST middleware or the bindings configuration changes, rerun `cargo run -p stm32-bindings-gen`. The generator will overwrite this crate with the latest bindings, static libraries, and metadata.
40 changes: 40 additions & 0 deletions stm32-bindings-gen/res/linklayer/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
use std::path::{Path, PathBuf};
use std::{env, fs, io};

fn add_dir(dir: &Path) -> io::Result<()> {
if !dir.exists() {
return Ok(());
}

println!("cargo:rustc-link-search=native={}", dir.display());

for entry in fs::read_dir(dir)? {
let entry = entry?;
let path = entry.path();
if path.is_dir() {
add_dir(&path)?;
}
}
Ok(())
}

fn main() {
let crate_dir = PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").unwrap());
let lib_dir = crate_dir.join("src").join("lib");
let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap_or_default();
let target_family = env::var("CARGO_CFG_TARGET_FAMILY").unwrap_or_default();
let is_embedded = target_os == "none" || target_family == "embedded";

if !is_embedded {
return;
}

add_dir(&lib_dir).expect("failed to add link search paths");

env::vars()
.filter_map(|(key, _)| {
key.strip_prefix("CARGO_FEATURE_LIB_")
.map(|s| s.to_ascii_lowercase())
})
.for_each(|lib| println!("cargo:rustc-link-lib=static={lib}"));
}
14 changes: 14 additions & 0 deletions stm32-bindings-gen/res/linklayer/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#![no_std]
#![allow(non_snake_case)]
#![allow(non_camel_case_types)]
#![allow(non_upper_case_globals)]
#![doc(html_no_source)]

/// Raw bindings generated by `stm32-bindings-gen`.
///
/// The `bindings` module is produced by `bindgen` and exposes a one-to-one FFI
/// surface to the STM32 WBA link-layer middleware. All items should be treated
/// as `unsafe` and wrapped by higher-level crates before use.
pub mod bindings;

pub use bindings::*;
17 changes: 17 additions & 0 deletions stm32-bindings-gen/res/mac/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[package]
name = "mac-bindings"
version = "0.1.0"
edition = "2024"
license = "MIT OR Apache-2.0"
description = "Raw STM32 WBA IEEE 802.15.4 MAC bindings generated from the ST middleware."
build = "build.rs"

[lib]
path = "src/lib.rs"

[dependencies]
linklayer-bindings = { path = "../linklayer-bindings" }

[features]
default = []
lib_wba_mac_lib = []
28 changes: 28 additions & 0 deletions stm32-bindings-gen/res/mac/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# mac-bindings

Raw bindings for the STM32 WBA IEEE 802.15.4 MAC middleware. This crate is generated automatically by `stm32-bindings-gen` and is intended to be consumed by higher-level wrappers that provide safe abstractions for IEEE 802.15.4 stacks.

## Overview

The generator pulls in STM-provided headers and static libraries, then runs `bindgen` to emit Rust FFI shims. No additional logic lives here—consumers should treat every item as `unsafe` and wrap it before use.

## Layout

- `src/bindings/`: Raw Rust modules produced by `bindgen`.
- `src/lib/`: Static libraries copied from the STM32CubeWBA middleware tree, gated behind Cargo features.
- `build.rs`: Emits the appropriate `cargo:rustc-link-*` directives based on the selected features.

## Usage

1. Ensure `stm32-bindings-gen` has been run so this crate exists in `build/mac-bindings`.
2. Add a path dependency in your Cargo manifest pointing at that directory.
3. Opt into the desired static library variant by enabling the matching `lib_*` feature exposed by this crate.
4. Call the generated functions through `unsafe` code and wrap them in a higher-level API before exposing them to the rest of your application.

## Feature Flags

Each feature named `lib_<variant>` selects one of the prebuilt static archives shipped by ST. Enable exactly the libraries required by your firmware configuration; the build script will link them automatically.

## Regeneration

If the upstream ST middleware or the bindings configuration changes, rerun `cargo run -p stm32-bindings-gen`. The generator will overwrite this crate with the latest bindings, static libraries, and metadata.
41 changes: 41 additions & 0 deletions stm32-bindings-gen/res/mac/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use std::path::{Path, PathBuf};
use std::{env, fs, io};

fn add_dir(dir: &Path) -> io::Result<()> {
if !dir.exists() {
return Ok(());
}

println!("cargo:rustc-link-search=native={}", dir.display());

for entry in fs::read_dir(dir)? {
let entry = entry?;
let path = entry.path();
if path.is_dir() {
add_dir(&path)?;
}
}

Ok(())
}

fn main() {
let crate_dir = PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").unwrap());
let lib_dir = crate_dir.join("src").join("lib");
let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap_or_default();
let target_family = env::var("CARGO_CFG_TARGET_FAMILY").unwrap_or_default();
let is_embedded = target_os == "none" || target_family == "embedded";

if !is_embedded {
return;
}

add_dir(&lib_dir).expect("failed to add link search paths");

env::vars()
.filter_map(|(key, _)| {
key.strip_prefix("CARGO_FEATURE_LIB_")
.map(|suffix| suffix.to_ascii_lowercase())
})
.for_each(|lib| println!("cargo:rustc-link-lib=static={lib}"));
}
14 changes: 14 additions & 0 deletions stm32-bindings-gen/res/mac/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#![no_std]
#![allow(non_snake_case)]
#![allow(non_camel_case_types)]
#![allow(non_upper_case_globals)]
#![doc(html_no_source)]

/// Raw bindings generated by `stm32-bindings-gen`.
///
/// The `bindings` module is produced by `bindgen` and exposes a one-to-one FFI
/// surface to the STM32 WBA MAC middleware. All items should be treated as
/// `unsafe` and wrapped by higher-level crates before use.
pub mod bindings;

pub use bindings::*;
Loading