diff options
| author | Joonas Javanainen <[email protected]> | 2022-03-27 18:42:22 +0300 |
|---|---|---|
| committer | Joonas Javanainen <[email protected]> | 2022-03-27 18:45:37 +0300 |
| commit | a16fef21e1e8004a207a85cf542f3402213cac87 (patch) | |
| tree | 12d1273583b68fa49e3e8a704bf11c961eb33af5 /examples/stm32f2/src | |
| parent | a608d0deaf7b75fc1c270f74be0891318794074d (diff) | |
Add blinky example for STM32F2
Default configuration is for NUCLEO-F207ZG board
Diffstat (limited to 'examples/stm32f2/src')
| -rw-r--r-- | examples/stm32f2/src/bin/blinky.rs | 29 | ||||
| -rw-r--r-- | examples/stm32f2/src/example_common.rs | 19 |
2 files changed, 48 insertions, 0 deletions
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 | } | ||
