aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/stm32f2/.cargo/config6
-rw-r--r--examples/stm32f2/Cargo.toml21
-rw-r--r--examples/stm32f2/build.rs5
-rw-r--r--examples/stm32f2/src/bin/blinky.rs29
-rw-r--r--examples/stm32f2/src/example_common.rs19
5 files changed, 80 insertions, 0 deletions
diff --git a/examples/stm32f2/.cargo/config b/examples/stm32f2/.cargo/config
new file mode 100644
index 000000000..30b6d1909
--- /dev/null
+++ b/examples/stm32f2/.cargo/config
@@ -0,0 +1,6 @@
1[target.'cfg(all(target_arch = "arm", target_os = "none"))']
2# replace STM32F207ZGTx with your chip as listed in `probe-run --list-chips`
3runner = "probe-run --chip STM32F207ZGTx"
4
5[build]
6target = "thumbv7m-none-eabi"
diff --git a/examples/stm32f2/Cargo.toml b/examples/stm32f2/Cargo.toml
new file mode 100644
index 000000000..ee1d7ce2b
--- /dev/null
+++ b/examples/stm32f2/Cargo.toml
@@ -0,0 +1,21 @@
1[package]
2authors = ["Dario Nieuwenhuis <[email protected]>"]
3edition = "2018"
4name = "embassy-stm32f2-examples"
5version = "0.1.0"
6resolver = "2"
7
8[dependencies]
9embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt"] }
10embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32f207zg", "unstable-pac", "memory-x", "time-driver-any", "exti"] }
11
12defmt = "0.3"
13defmt-rtt = "0.3"
14
15cortex-m = "0.7.3"
16cortex-m-rt = "0.7.0"
17embedded-hal = "0.2.6"
18panic-probe = { version = "0.3", features = ["print-defmt"] }
19futures = { version = "0.3.17", default-features = false, features = ["async-await"] }
20heapless = { version = "0.7.5", default-features = false }
21nb = "1.0.0"
diff --git a/examples/stm32f2/build.rs b/examples/stm32f2/build.rs
new file mode 100644
index 000000000..8cd32d7ed
--- /dev/null
+++ b/examples/stm32f2/build.rs
@@ -0,0 +1,5 @@
1fn main() {
2 println!("cargo:rustc-link-arg-bins=--nmagic");
3 println!("cargo:rustc-link-arg-bins=-Tlink.x");
4 println!("cargo:rustc-link-arg-bins=-Tdefmt.x");
5}
diff --git a/examples/stm32f2/src/bin/blinky.rs b/examples/stm32f2/src/bin/blinky.rs
new file mode 100644
index 000000000..637c2f4fd
--- /dev/null
+++ b/examples/stm32f2/src/bin/blinky.rs
@@ -0,0 +1,29 @@
1#![no_std]
2#![no_main]
3#![feature(type_alias_impl_trait)]
4
5#[path = "../example_common.rs"]
6mod example_common;
7
8use embassy::executor::Spawner;
9use embassy::time::{Duration, Timer};
10use embassy_stm32::gpio::{Level, Output, Speed};
11use embassy_stm32::Peripherals;
12use example_common::*;
13
14#[embassy::main]
15async fn main(_spawner: Spawner, p: Peripherals) {
16 info!("Hello World!");
17
18 let mut led = Output::new(p.PB14, Level::High, Speed::Low);
19
20 loop {
21 info!("high");
22 led.set_high();
23 Timer::after(Duration::from_millis(1000)).await;
24
25 info!("low");
26 led.set_low();
27 Timer::after(Duration::from_millis(1000)).await;
28 }
29}
diff --git a/examples/stm32f2/src/example_common.rs b/examples/stm32f2/src/example_common.rs
new file mode 100644
index 000000000..e14517033
--- /dev/null
+++ b/examples/stm32f2/src/example_common.rs
@@ -0,0 +1,19 @@
1#![macro_use]
2
3use defmt_rtt as _; // global logger
4use panic_probe as _;
5
6pub use defmt::*;
7
8use core::sync::atomic::{AtomicUsize, Ordering};
9
10defmt::timestamp! {
11 "{=u64}",
12 {
13 static COUNT: AtomicUsize = AtomicUsize::new(0);
14 // NOTE(no-CAS) `timestamps` runs with interrupts disabled
15 let n = COUNT.load(Ordering::Relaxed);
16 COUNT.store(n + 1, Ordering::Relaxed);
17 n as u64
18 }
19}