aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorcschuhen <47763321+cschuhen@users.noreply.github.com>2024-02-27 21:25:07 +1000
committerGitHub <noreply@github.com>2024-02-27 11:25:07 +0000
commitb1467c62b4b4f61ce53b6572c30920a72550ea45 (patch)
treef2e685383be2203ee96b7172f11f7bfcdb26d52a /examples
parent27985009579e82673dcaf7a6a715fcf50c184863 (diff)
Add example of using Embassy HAL(stm32) with RTIC. (#891)
The RTIC book mentions Embassy+RTIC but gives no examples. fmt. Add feature flag Seems CI does not deal with 2 levels of depth. Forgot to stage. Thumb m arch. Co-authored-by: Corey Schuhen <cschuhen@gmail.com>
Diffstat (limited to 'examples')
-rw-r--r--examples/embassy-stm32g4/.cargo/config.toml9
-rw-r--r--examples/embassy-stm32g4/Cargo.toml36
-rw-r--r--examples/embassy-stm32g4/build.rs5
-rw-r--r--examples/embassy-stm32g4/src/bin/blinky.rs61
4 files changed, 111 insertions, 0 deletions
diff --git a/examples/embassy-stm32g4/.cargo/config.toml b/examples/embassy-stm32g4/.cargo/config.toml
new file mode 100644
index 0000000..cbe0039
--- /dev/null
+++ b/examples/embassy-stm32g4/.cargo/config.toml
@@ -0,0 +1,9 @@
+[target.'cfg(all(target_arch = "arm", target_os = "none"))']
+# replace STM32G071C8Rx with your chip as listed in `probe-rs chip list`
+runner = "probe-rs run --chip STM32G431CBUx --connect-under-reset"
+
+[build]
+target = "thumbv7m-none-eabi"
+
+[env]
+DEFMT_LOG = "trace"
diff --git a/examples/embassy-stm32g4/Cargo.toml b/examples/embassy-stm32g4/Cargo.toml
new file mode 100644
index 0000000..f4efbe9
--- /dev/null
+++ b/examples/embassy-stm32g4/Cargo.toml
@@ -0,0 +1,36 @@
+[package]
+edition = "2021"
+name = "embassy-stm32g4-examples"
+version = "0.1.0"
+license = "MIT OR Apache-2.0"
+
+[workspace]
+
+[dependencies.rtic]
+path="../../rtic"
+version = "=2.0"
+features = ["thumbv7-backend"]
+
+[dependencies.rtic-monotonics]
+path="../../rtic-monotonics"
+version = "=1.5"
+features = ["cortex-m-systick"]
+
+[dependencies.rtic-sync]
+path="../../rtic-sync"
+version = "=1.3"
+
+[dependencies]
+# Change stm32g431cb to your chip name, if necessary. Also change .cargo/config.toml
+embassy-stm32 = { version = "0.1.0", features = [ "defmt", "time-driver-any", "stm32g431cb", "memory-x", "unstable-pac", "exti"] }
+
+defmt = "0.3"
+defmt-rtt = "0.4"
+
+cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] }
+cortex-m-rt = "0.7.0"
+embedded-hal = "0.2.6"
+panic-probe = { version = "0.3", features = ["print-defmt"] }
+
+[profile.release]
+debug = 2
diff --git a/examples/embassy-stm32g4/build.rs b/examples/embassy-stm32g4/build.rs
new file mode 100644
index 0000000..8cd32d7
--- /dev/null
+++ b/examples/embassy-stm32g4/build.rs
@@ -0,0 +1,5 @@
+fn main() {
+ println!("cargo:rustc-link-arg-bins=--nmagic");
+ println!("cargo:rustc-link-arg-bins=-Tlink.x");
+ println!("cargo:rustc-link-arg-bins=-Tdefmt.x");
+}
diff --git a/examples/embassy-stm32g4/src/bin/blinky.rs b/examples/embassy-stm32g4/src/bin/blinky.rs
new file mode 100644
index 0000000..9cc4899
--- /dev/null
+++ b/examples/embassy-stm32g4/src/bin/blinky.rs
@@ -0,0 +1,61 @@
+#![deny(unsafe_code)]
+#![deny(warnings)]
+#![no_main]
+#![no_std]
+#![feature(type_alias_impl_trait)]
+
+use defmt::*;
+use embassy_stm32::gpio::{Level, Output, Speed};
+use rtic::app;
+use rtic_monotonics::systick::*;
+use {defmt_rtt as _, panic_probe as _};
+
+pub mod pac {
+ pub use embassy_stm32::pac::Interrupt as interrupt;
+ pub use embassy_stm32::pac::*;
+}
+
+#[app(device = pac, peripherals = false, dispatchers = [SPI1])]
+mod app {
+ use super::*;
+
+ #[shared]
+ struct Shared {}
+
+ #[local]
+ struct Local {}
+
+ #[init]
+ fn init(cx: init::Context) -> (Shared, Local) {
+ // Initialize the systick interrupt & obtain the token to prove that we did
+ let systick_mono_token = rtic_monotonics::create_systick_token!();
+ Systick::start(cx.core.SYST, 25_000_000, systick_mono_token);
+
+ let p = embassy_stm32::init(Default::default());
+ info!("Hello World!");
+
+ let mut led = Output::new(p.PC6, Level::High, Speed::Low);
+ info!("high");
+ led.set_high();
+
+ // Schedule the blinking task
+ blink::spawn(led).ok();
+
+ (Shared {}, Local {})
+ }
+
+ #[task()]
+ async fn blink(_cx: blink::Context, mut led: Output<'static, embassy_stm32::peripherals::PC6>) {
+ let mut state = true;
+ loop {
+ info!("blink");
+ if state {
+ led.set_high();
+ } else {
+ led.set_low();
+ }
+ state = !state;
+ Systick::delay(1000.millis()).await;
+ }
+ }
+}