-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SFT-4358: Add stm32h7xx-hal-driver-sys crate.
* extmod/foundation-rust/Cargo.lock: Update file. * extmod/foundation-rust/Cargo.toml [workspace] <members>: Add stm32h7xx-hal-driver-sys. * extmod/foundation-rust/Justfile (generate): Add stm32h7xx-hal-driver-sys bindgen. (lint): Check stm32h7xx-hal-driver-sys bindgen. * extmod/foundation-rust/stm32h7xx-hal-driver-sys/Cargo.toml: New manifest. * extmod/foundation-rust/stm32h7xx-hal-driver-sys/bindgen.sh: New script. * extmod/foundation-rust/stm32h7xx-hal-driver-sys/bindings.h: New header file. * extmod/foundation-rust/stm32h7xx-hal-driver-sys/includes.awk: New AWK script. * extmod/foundation-rust/stm32h7xx-hal-driver-sys/gen.rs: Generate bindings. * extmod/foundation-rust/stm32h7xx-hal-driver-sys/gen.rs.license: New license information file. * extmod/foundation-rust/stm32h7xx-hal-driver-sys/lib.rs: New file.
- Loading branch information
Showing
10 changed files
with
25,803 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
# SPDX-FileCopyrightText: © 2023 Foundation Devices, Inc. <[email protected]> | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
[workspace] | ||
members = ["stm32h7xx-hal-driver-sys"] | ||
|
||
[package] | ||
name = "foundation" | ||
version = "0.1.0" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# SPDX-FileCopyrightText: © 2024 Foundation Devices, Inc. <[email protected]> | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
[package] | ||
name = "stm32h7xx-hal-driver-sys" | ||
version = "0.1.0" | ||
edition = "2021" | ||
license = "GPL-3.0-or-later" |
100 changes: 100 additions & 0 deletions
100
extmod/foundation-rust/stm32h7xx-hal-driver-sys/bindgen.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
#!/usr/bin/env bash | ||
# | ||
# SPDX-FileCopyrightText: © 2024 Foundation Devices, Inc. <[email protected]> | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
# | ||
# Generate bindings of STM32H7xx_HAL_Driver using rust-bindgen. | ||
# | ||
# To generate bindings: | ||
# | ||
# ./bindgen.sh | ||
# | ||
# To check if bindings need to be re-generated: | ||
# | ||
# ./bindgen.sh -c | ||
|
||
CC=arm-none-eabi-gcc | ||
|
||
usage() { | ||
echo "Usage: $0 [-c]" | ||
exit 1 | ||
} | ||
|
||
check=false | ||
while getopts "c" o; do | ||
case "${o}" in | ||
c) | ||
check=true | ||
;; | ||
*) | ||
usage | ||
;; | ||
esac | ||
done | ||
|
||
# From: https://stackoverflow.com/a/246128 | ||
SOURCE=${BASH_SOURCE[0]} | ||
while [ -L "$SOURCE" ] | ||
do | ||
DIR=$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd ) | ||
SOURCE=$(readlink "$SOURCE") | ||
[[ $SOURCE != /* ]] && SOURCE=$DIR/$SOURCE | ||
done | ||
DIR=$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd ) | ||
|
||
system_include_directories=$($CC -v -xc -E /dev/null 2>&1 | awk -f "$DIR/includes.awk") | ||
|
||
clang_arguments='--target=arm-none-eabi -mcpu=cortex-m7' | ||
for includedir in ${system_include_directories} | ||
do | ||
clang_arguments+=" -isystem $includedir" | ||
done | ||
|
||
clang_arguments+=" \ | ||
-I$DIR/../../../lib/cmsis/inc \ | ||
-I$DIR/../../../lib/stm32lib/CMSIS/STM32H7xx/Include \ | ||
-I$DIR/../../../lib/stm32lib/STM32H7xx_HAL_Driver/Inc \ | ||
-I$DIR/../../../ports/stm32/boards/Passport \ | ||
-DSTM32H753xx \ | ||
" | ||
|
||
if [ "$check" = true ] | ||
then | ||
output=$(mktemp) | ||
else | ||
output=$DIR/src/gen.rs | ||
fi | ||
|
||
# NOTE: | ||
# | ||
# --allowlist-item '^.*_BASE$': this is for the peripheral base addresses. | ||
# Should be a cmsis-device-h7-sys crate. | ||
echo "BINDGEN_EXTRA_CLANG_ARGS=$clang_arguments" | ||
echo "generating bindings: $output" | ||
BINDGEN_EXTRA_CLANG_ARGS="$clang_arguments" bindgen $DIR/bindings.h \ | ||
--verbose \ | ||
--rust-target 1.73 \ | ||
--use-core \ | ||
--no-doc-comments \ | ||
--default-enum-style moduleconsts \ | ||
--sort-semantically \ | ||
--allowlist-item '^.*_BASE$' \ | ||
--allowlist-function '^HAL_.*$' \ | ||
--output $output | ||
|
||
# Format the resulting file. | ||
rustfmt --config-path "$DIR/.." $output | ||
|
||
if [ "$check" = true ] | ||
then | ||
echo "verifying if bindings need to be re-generated." | ||
if diff "$DIR/src/gen.rs" "$output" >/dev/null | ||
then | ||
echo "done." | ||
else | ||
echo "error: bindings need to be re-generated!" | ||
exit 1 | ||
fi | ||
else | ||
echo "bindings up to date." | ||
fi |
13 changes: 13 additions & 0 deletions
13
extmod/foundation-rust/stm32h7xx-hal-driver-sys/bindings.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/** | ||
* SPDX-FileCopyrightText: © 2024 Foundation Devices, Inc. <[email protected]> | ||
* SPDX-License-Identifier: GPL-3.0-or-later | ||
* | ||
* This file is passed to cbindgen to generate the Rust bindings. | ||
*/ | ||
|
||
#ifndef BINDINGS_H | ||
#define BINDINGS_H | ||
|
||
#include <stm32h7xx_hal.h> | ||
|
||
#endif /* BINDNIGS_H */ |
18 changes: 18 additions & 0 deletions
18
extmod/foundation-rust/stm32h7xx-hal-driver-sys/includes.awk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# SPDX-FileCopyrightText: © 2024 Foundation Devices, Inc. <[email protected]> | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
# | ||
# Prints a space separalted list of GCC system include paths. | ||
# | ||
# For example: | ||
# | ||
# gcc -v -xc -E /dev/null 2>&1 | awk -f includes.awk | ||
|
||
/#include <...> search starts here:/ { | ||
inside_search_paths = 1; next | ||
} | ||
|
||
/End of search list./ { | ||
inside_search_paths = 0 | ||
} | ||
|
||
inside_search_paths { print } |
Oops, something went wrong.