diff options
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/stm32f2/.cargo/config | 6 | ||||
| -rw-r--r-- | examples/stm32f2/Cargo.toml | 21 | ||||
| -rw-r--r-- | examples/stm32f2/build.rs | 5 | ||||
| -rw-r--r-- | examples/stm32f2/src/bin/blinky.rs | 29 | ||||
| -rw-r--r-- | examples/stm32f2/src/example_common.rs | 19 |
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` | ||
| 3 | runner = "probe-run --chip STM32F207ZGTx" | ||
| 4 | |||
| 5 | [build] | ||
| 6 | target = "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] | ||
| 2 | authors = ["Dario Nieuwenhuis <[email protected]>"] | ||
| 3 | edition = "2018" | ||
| 4 | name = "embassy-stm32f2-examples" | ||
| 5 | version = "0.1.0" | ||
| 6 | resolver = "2" | ||
| 7 | |||
| 8 | [dependencies] | ||
| 9 | embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt"] } | ||
| 10 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32f207zg", "unstable-pac", "memory-x", "time-driver-any", "exti"] } | ||
| 11 | |||
| 12 | defmt = "0.3" | ||
| 13 | defmt-rtt = "0.3" | ||
| 14 | |||
| 15 | cortex-m = "0.7.3" | ||
| 16 | cortex-m-rt = "0.7.0" | ||
| 17 | embedded-hal = "0.2.6" | ||
| 18 | panic-probe = { version = "0.3", features = ["print-defmt"] } | ||
| 19 | futures = { version = "0.3.17", default-features = false, features = ["async-await"] } | ||
| 20 | heapless = { version = "0.7.5", default-features = false } | ||
| 21 | nb = "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 @@ | |||
| 1 | fn 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"] | ||
| 6 | mod example_common; | ||
| 7 | |||
| 8 | use embassy::executor::Spawner; | ||
| 9 | use embassy::time::{Duration, Timer}; | ||
| 10 | use embassy_stm32::gpio::{Level, Output, Speed}; | ||
| 11 | use embassy_stm32::Peripherals; | ||
| 12 | use example_common::*; | ||
| 13 | |||
| 14 | #[embassy::main] | ||
| 15 | async 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 | |||
| 3 | use defmt_rtt as _; // global logger | ||
| 4 | use panic_probe as _; | ||
| 5 | |||
| 6 | pub use defmt::*; | ||
| 7 | |||
| 8 | use core::sync::atomic::{AtomicUsize, Ordering}; | ||
| 9 | |||
| 10 | defmt::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 | } | ||
