diff options
Diffstat (limited to 'examples/stm32g0/src')
| -rw-r--r-- | examples/stm32g0/src/bin/blinky.rs | 31 | ||||
| -rw-r--r-- | examples/stm32g0/src/bin/button.rs | 29 | ||||
| -rw-r--r-- | examples/stm32g0/src/bin/button_exti.rs | 31 | ||||
| -rw-r--r-- | examples/stm32g0/src/example_common.rs | 17 |
4 files changed, 108 insertions, 0 deletions
diff --git a/examples/stm32g0/src/bin/blinky.rs b/examples/stm32g0/src/bin/blinky.rs new file mode 100644 index 000000000..a30887f7d --- /dev/null +++ b/examples/stm32g0/src/bin/blinky.rs | |||
| @@ -0,0 +1,31 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(trait_alias)] | ||
| 4 | #![feature(type_alias_impl_trait)] | ||
| 5 | #![allow(incomplete_features)] | ||
| 6 | |||
| 7 | #[path = "../example_common.rs"] | ||
| 8 | mod example_common; | ||
| 9 | use embassy::executor::Spawner; | ||
| 10 | use embassy::time::{Duration, Timer}; | ||
| 11 | use embassy_stm32::gpio::{Level, Output, Speed}; | ||
| 12 | use embassy_stm32::Peripherals; | ||
| 13 | use embedded_hal::digital::v2::OutputPin; | ||
| 14 | use example_common::*; | ||
| 15 | |||
| 16 | #[embassy::main] | ||
| 17 | async fn main(_spawner: Spawner, p: Peripherals) { | ||
| 18 | info!("Hello World!"); | ||
| 19 | |||
| 20 | let mut led = Output::new(p.PB7, Level::High, Speed::Low); | ||
| 21 | |||
| 22 | loop { | ||
| 23 | info!("high"); | ||
| 24 | unwrap!(led.set_high()); | ||
| 25 | Timer::after(Duration::from_millis(300)).await; | ||
| 26 | |||
| 27 | info!("low"); | ||
| 28 | unwrap!(led.set_low()); | ||
| 29 | Timer::after(Duration::from_millis(300)).await; | ||
| 30 | } | ||
| 31 | } | ||
diff --git a/examples/stm32g0/src/bin/button.rs b/examples/stm32g0/src/bin/button.rs new file mode 100644 index 000000000..a834b2fce --- /dev/null +++ b/examples/stm32g0/src/bin/button.rs | |||
| @@ -0,0 +1,29 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(trait_alias)] | ||
| 4 | #![feature(type_alias_impl_trait)] | ||
| 5 | #![allow(incomplete_features)] | ||
| 6 | |||
| 7 | #[path = "../example_common.rs"] | ||
| 8 | mod example_common; | ||
| 9 | use cortex_m_rt::entry; | ||
| 10 | use embassy_stm32::gpio::{Input, Pull}; | ||
| 11 | use embedded_hal::digital::v2::InputPin; | ||
| 12 | use example_common::*; | ||
| 13 | |||
| 14 | #[entry] | ||
| 15 | fn main() -> ! { | ||
| 16 | info!("Hello World!"); | ||
| 17 | |||
| 18 | let p = embassy_stm32::init(Default::default()); | ||
| 19 | |||
| 20 | let button = Input::new(p.PC13, Pull::Up); | ||
| 21 | |||
| 22 | loop { | ||
| 23 | if unwrap!(button.is_high()) { | ||
| 24 | info!("high"); | ||
| 25 | } else { | ||
| 26 | info!("low"); | ||
| 27 | } | ||
| 28 | } | ||
| 29 | } | ||
diff --git a/examples/stm32g0/src/bin/button_exti.rs b/examples/stm32g0/src/bin/button_exti.rs new file mode 100644 index 000000000..c55d6408c --- /dev/null +++ b/examples/stm32g0/src/bin/button_exti.rs | |||
| @@ -0,0 +1,31 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(trait_alias)] | ||
| 4 | #![feature(type_alias_impl_trait)] | ||
| 5 | #![allow(incomplete_features)] | ||
| 6 | |||
| 7 | #[path = "../example_common.rs"] | ||
| 8 | mod example_common; | ||
| 9 | use embassy::executor::Spawner; | ||
| 10 | use embassy_stm32::exti::ExtiInput; | ||
| 11 | use embassy_stm32::gpio::{Input, Pull}; | ||
| 12 | use embassy_stm32::Peripherals; | ||
| 13 | use embassy_traits::gpio::{WaitForFallingEdge, WaitForRisingEdge}; | ||
| 14 | use example_common::*; | ||
| 15 | |||
| 16 | #[embassy::main] | ||
| 17 | async fn main(_spawner: Spawner, p: Peripherals) { | ||
| 18 | info!("Hello World!"); | ||
| 19 | |||
| 20 | let button = Input::new(p.PC13, Pull::Up); | ||
| 21 | let mut button = ExtiInput::new(button, p.EXTI13); | ||
| 22 | |||
| 23 | info!("Press the USER button..."); | ||
| 24 | |||
| 25 | loop { | ||
| 26 | button.wait_for_falling_edge().await; | ||
| 27 | info!("Pressed!"); | ||
| 28 | button.wait_for_rising_edge().await; | ||
| 29 | info!("Released!"); | ||
| 30 | } | ||
| 31 | } | ||
diff --git a/examples/stm32g0/src/example_common.rs b/examples/stm32g0/src/example_common.rs new file mode 100644 index 000000000..54d633837 --- /dev/null +++ b/examples/stm32g0/src/example_common.rs | |||
| @@ -0,0 +1,17 @@ | |||
| 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! {"{=u64}", { | ||
| 11 | static COUNT: AtomicUsize = AtomicUsize::new(0); | ||
| 12 | // NOTE(no-CAS) `timestamps` runs with interrupts disabled | ||
| 13 | let n = COUNT.load(Ordering::Relaxed); | ||
| 14 | COUNT.store(n + 1, Ordering::Relaxed); | ||
| 15 | n as u64 | ||
| 16 | } | ||
| 17 | } | ||
