Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(arch): add stm32 support #237

Merged
merged 2 commits into from
Jul 9, 2024
Merged
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
278 changes: 199 additions & 79 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ members = [
"src/riot-rs-boards",
"src/riot-rs-boards/nrf52",
"src/riot-rs-boards/nrf52840dk",
"src/riot-rs-boards/nucleo-f401re",
"src/riot-rs-chips",
"src/riot-rs-debug",
"src/riot-rs-macros",
Expand Down Expand Up @@ -43,6 +42,7 @@ embassy-net = { version = "0.4", default-features = false }
embassy-net-driver-channel = { version = "0.2.0", default-features = false }
embassy-nrf = { version = "0.1", default-features = false }
embassy-rp = { version = "0.1", default-features = false }
embassy-stm32 = { version = "0.1", default-features = false }
embassy-sync = { version = "0.6", default-features = false }
embassy-time = { version = "0.3", default-features = false }
embassy-usb = { version = "0.1", default-features = false }
Expand All @@ -58,6 +58,7 @@ riot-rs = { path = "src/riot-rs", default-features = false }
riot-rs-bench = { path = "src/riot-rs-bench", default-features = false }
riot-rs-boards = { path = "src/riot-rs-boards", default-features = false }
riot-rs-debug = { path = "src/riot-rs-debug", default-features = false }
riot-rs-embassy = { path = "src/riot-rs-embassy", default-features = false }
riot-rs-rt = { path = "src/riot-rs-rt" }
riot-rs-runqueue = { path = "src/riot-rs-runqueue" }
riot-rs-utils = { path = "src/riot-rs-utils", default-features = false }
Expand Down Expand Up @@ -97,6 +98,7 @@ embassy-net = { git = "https://github.com/kaspar030/embassy", branch = "for-riot
embassy-rp = { git = "https://github.com/kaspar030/embassy", branch = "for-riot-rs-240605" }
embassy-net-driver = { git = "https://github.com/kaspar030/embassy", branch = "for-riot-rs-240605" }
embassy-net-driver-channel = { git = "https://github.com/kaspar030/embassy", branch = "for-riot-rs-240605" }
embassy-stm32 = { git = "https://github.com/kaspar030/embassy", branch = "for-riot-rs-240605" }
embassy-sync = { git = "https://github.com/kaspar030/embassy", branch = "for-riot-rs-240605" }
embassy-time-driver = { git = "https://github.com/kaspar030/embassy", branch = "for-riot-rs-240605" }
embassy-time-queue-driver = { git = "https://github.com/kaspar030/embassy", branch = "for-riot-rs-240605" }
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ The following list of hardware is currently supported:
- [Raspberry Pi Pico W](https://www.raspberrypi.com/products/raspberry-pi-pico/) (RP2040, Cortex-M0+)
- [BBC Micro:Bit v2](https://tech.microbit.org/hardware/2-0-revision/) (Cortex-M4)
- [Expressif ESP32-C6-DevKitC-1](https://docs.espressif.com/projects/espressif-esp-dev-kits/en/latest/esp32c6/esp32-c6-devkitc-1/user_guide.html) (RISC-V)
- [ST NUCLEO-F401RE](https://www.st.com/en/evaluation-tools/nucleo-f401re.html) (Cortex-M4)
- [ST NUCLEO-H755ZI-Q](https://www.st.com/en/evaluation-tools/nucleo-h755zi-q.html) (Cortex-M7)
- [ST NUCLEO-WB55RG](https://www.st.com/en/evaluation-tools/p-nucleo-wb55.html) (Cortex-M4)
- and more to come soon.

## Status
Expand Down
1 change: 1 addition & 0 deletions _typos.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[default.extend-words]
hax = "hax"
hsi = "hsi"

[default.extend-identifiers]
celcius = "celcius" # Until embedded-aht20 is fixed
Expand Down
67 changes: 66 additions & 1 deletion laze-project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,18 @@ contexts:
-serial mon:stdio
-semihosting-config enable=on,target=native
-kernel
PROBE_RS_PROTOCOL: swd

var_options:
# this turns ${FEATURES} from a list to "--features=feature1,feature2"
FEATURES:
start: --features=
joiner: ","

# this prefixes `--protocol=` to `PROBE_RS_PROTOCOL`
PROBE_RS_PROTOCOL:
start: --protocol=

rules:
- name: LINK
description: CARGO ${out}
Expand Down Expand Up @@ -294,6 +299,55 @@ contexts:
RUSTC_TARGET: riscv32imac-unknown-none-elf
CARGO_TARGET_PREFIX: CARGO_TARGET_RISCV32IMAC_UNKNOWN_NONE_ELF

- name: stm32
help: STM32 support (based on embassy-stm32)
parent: riot-rs
selects:
- ?probe-rs
env:
OPENOCD_ARGS: foo
RUSTFLAGS:
- --cfg context=\"stm32\"

- name: stm32f401retx
parent: stm32
selects:
- thumbv7em-none-eabi # actually eabihf, but riot-rs doesn't support hard float yet
env:
PROBE_RS_CHIP: STM32F401RETx
PROBE_RS_PROTOCOL: swd
RUSTFLAGS:
- --cfg context=\"stm32f401retx\"
CARGO_ENV:
# This ISR is unused on a naked board. Configured here for testing.
- CONFIG_SWI=USART2

- name: stm32wb55rgvx
parent: stm32
selects:
- thumbv7em-none-eabi # actually eabihf, but riot-rs doesn't support hard float yet
env:
PROBE_RS_CHIP: STM32WB55RGVx
PROBE_RS_PROTOCOL: swd
RUSTFLAGS:
- --cfg context=\"stm32wb55rgvx\"
CARGO_ENV:
# This ISR is unused on a naked board. Configured here for testing.
- CONFIG_SWI=LPUART1
ROMemories marked this conversation as resolved.
Show resolved Hide resolved

- name: stm32h755zitx
parent: stm32
selects:
- thumbv7em-none-eabi # actually eabihf, but riot-rs doesn't support hard float yet
env:
PROBE_RS_CHIP: STM32H755ZITx
PROBE_RS_PROTOCOL: swd
RUSTFLAGS:
- --cfg context=\"stm32h755zitx\"
CARGO_ENV:
# This ISR is unused on a naked board. Configured here for testing.
- CONFIG_SWI=UART5

modules:
- name: cortex-m
env:
Expand Down Expand Up @@ -485,7 +539,7 @@ modules:
- ?debug-console
env:
global:
CARGO_RUNNER: "'probe-rs run --chip ${PROBE_RS_CHIP}'"
CARGO_RUNNER: "'probe-rs run ${PROBE_RS_PROTOCOL} --chip ${PROBE_RS_CHIP}'"

- name: probe-rs-run
help: "deprecated alias for `probe-rs`"
Expand Down Expand Up @@ -528,6 +582,8 @@ modules:
- rpi-pico
- rpi-pico-w
- particle-xenon
- st-nucleo-h755zi-q
- st-nucleo-wb55
env:
global:
RUSTFLAGS:
Expand Down Expand Up @@ -714,6 +770,15 @@ builders:
- name: nrf5340dk
parent: nrf5340

- name: st-nucleo-f401re
parent: stm32f401retx

- name: st-nucleo-h755zi-q
parent: stm32h755zitx

- name: st-nucleo-wb55
parent: stm32wb55rgvx

apps:
# define a dummy host application so the host tasks work
- name: host
Expand Down
5 changes: 4 additions & 1 deletion src/riot-rs-boards/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@ nrf52840-mdk = { optional = true, path = "nrf52840-mdk" }
nrf52840dk = { optional = true, path = "nrf52840dk" }
nrf52dk = { optional = true, path = "nrf52dk" }
nrf5340dk = { optional = true, path = "nrf5340dk" }
nucleo-f401re = { optional = true, path = "nucleo-f401re" }
st-nucleo-f401re = { optional = true, path = "st-nucleo-f401re" }
kaspar030 marked this conversation as resolved.
Show resolved Hide resolved
st-nucleo-wb55 = { optional = true, path = "st-nucleo-wb55" }
rpi-pico = { optional = true, path = "rpi-pico" }
particle-xenon = { optional = true, path = "particle-xenon" }
st-nucleo-h755zi-q = { optional = true, path = "st-nucleo-h755zi-q" }

[features]
# Allows to have no boards selected, useful to run platform-independent tooling
no-boards = []
# both "rpi-pico" and "rpi-pico-w" are valid, so no "dep:rpi-pico"
kaspar030 marked this conversation as resolved.
Show resolved Hide resolved
rpi-pico-w = ["rpi-pico/rpi-pico-w"]
17 changes: 0 additions & 17 deletions src/riot-rs-boards/nucleo-f401re/src/lib.rs

This file was deleted.

6 changes: 6 additions & 0 deletions src/riot-rs-boards/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ cfg_if! {
} else if #[cfg(feature = "rpi-pico-w")] {
// sharing rpi-pico
pub use rpi_pico as board;
} else if #[cfg(feature = "st-nucleo-f401re")] {
pub use st_nucleo_f401re as board;
} else if #[cfg(feature = "st-nucleo-wb55")] {
pub use st_nucleo_wb55 as board;
} else if #[cfg(feature = "st-nucleo-h755zi-q")] {
pub use st_nucleo_h755zi_q as board;
} else if #[cfg(feature = "no-boards")] {
// Do nothing
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
[package]
name = "nucleo-f401re"
name = "st-nucleo-f401re"
version = "0.1.0"
authors = ["Kaspar Schleiser <kaspar@schleiser.de>"]
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
stm32f4xx = { path = "../../riot-rs-chips/stm32f4xx", features = ["stm32f401"] }
embassy-stm32 = { workspace = true, features = ["stm32f401re"] }
riot-rs-debug = { workspace = true, features = ["rtt-target"] }
riot-rs-rt.workspace = true
15 changes: 15 additions & 0 deletions src/riot-rs-boards/st-nucleo-f401re/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use std::env;
use std::fs::copy;
use std::path::PathBuf;

fn main() {
// Put the linker script somewhere the linker can find it
let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());

copy("memory.x", out.join("memory.x")).unwrap();

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

println!("cargo:rerun-if-changed=memory.x");
println!("cargo:rerun-if-changed=build.rs");
}
5 changes: 5 additions & 0 deletions src/riot-rs-boards/st-nucleo-f401re/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#![no_std]

pub fn init() {
riot_rs_debug::println!("boards::st-nucleo-f401re::init()");
}
15 changes: 15 additions & 0 deletions src/riot-rs-boards/st-nucleo-h755zi-q/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "st-nucleo-h755zi-q"
version = "0.1.0"
edition = "2021"

[dependencies]
embassy-stm32 = { workspace = true, features = [
"stm32h755zi-cm7",
"memory-x",
"rt",
] }
riot-rs-debug = { workspace = true, features = ["rtt-target"] }
riot-rs-embassy = { workspace = true, features = ["stm32-usb-synopsis"] }
riot-rs-rt.workspace = true
stm32 = { path = "../../riot-rs-chips/stm32" }
7 changes: 7 additions & 0 deletions src/riot-rs-boards/st-nucleo-h755zi-q/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#![no_std]

use riot_rs_debug::println;

pub fn init() {
println!("st-nucleo-h755zi-q::init()");
}
12 changes: 12 additions & 0 deletions src/riot-rs-boards/st-nucleo-wb55/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "st-nucleo-wb55"
version = "0.1.0"
authors = ["Kaspar Schleiser <kaspar@schleiser.de>"]
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
embassy-stm32 = { workspace = true, features = ["stm32wb55rg"] }
riot-rs-embassy = { workspace = true, features = ["stm32-usb"] }
riot-rs-debug = { workspace = true, features = ["rtt-target"] }
riot-rs-rt.workspace = true
15 changes: 15 additions & 0 deletions src/riot-rs-boards/st-nucleo-wb55/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use std::env;
use std::fs::copy;
use std::path::PathBuf;

fn main() {
// Put the linker script somewhere the linker can find it
let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());

copy("memory.x", out.join("memory.x")).unwrap();

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

println!("cargo:rerun-if-changed=memory.x");
println!("cargo:rerun-if-changed=build.rs");
}
5 changes: 5 additions & 0 deletions src/riot-rs-boards/st-nucleo-wb55/memory.x
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
MEMORY
{
FLASH : ORIGIN = 0x08000000, LENGTH = 1024K /* BANK_1 */
RAM : ORIGIN = 0x20000000, LENGTH = 192K
}
5 changes: 5 additions & 0 deletions src/riot-rs-boards/st-nucleo-wb55/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#![no_std]

pub fn init() {
riot_rs_debug::println!("boards::st-nucleo-wb55::init()");
}
10 changes: 10 additions & 0 deletions src/riot-rs-chips/stm32/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "stm32"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[target.'cfg(context = "stm32h7b0")'.dependencies]
riot-rs-embassy = { path = "../../riot-rs-embassy" }
riot-rs-rt = { path = "../../riot-rs-rt", features = ["rtt-target"] }
1 change: 1 addition & 0 deletions src/riot-rs-chips/stm32/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#![no_std]
14 changes: 14 additions & 0 deletions src/riot-rs-embassy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ cyw43-pio = { version = "0.1.0", features = ["overclock"], optional = true }

# listed here for conditional feature selection
embassy-nrf = { workspace = true, default-features = false, optional = true }
embassy-stm32 = { workspace = true, default-features = false, optional = true }
esp-hal = { workspace = true, default-features = false, optional = true }
esp-hal-embassy = { workspace = true, default-features = false, optional = true }
esp-wifi = { workspace = true, optional = true }
Expand Down Expand Up @@ -104,6 +105,13 @@ esp-wifi = { workspace = true, default-features = false, features = [
"esp32c6",
], optional = true }

[target.'cfg(context = "stm32")'.dependencies]
embassy-stm32 = { workspace = true, features = [
"rt",
"time-driver-any",
"unstable-pac",
] }

[features]
time = ["dep:embassy-time", "embassy-executor/integrated-timers"]
usb = ["dep:embassy-usb"]
Expand Down Expand Up @@ -138,7 +146,13 @@ executor-none = []
defmt = [
"embassy-net?/defmt",
"embassy-nrf?/defmt",
"embassy-stm32?/defmt",
"embassy-time?/defmt",
"embassy-usb?/defmt",
"esp-wifi?/defmt",
]

# These are chosen automatically by riot-rs-boards and select the correct stm32
# usb peripheral support.
stm32-usb = []
stm32-usb-synopsis = []
Loading
Loading