aboutsummaryrefslogtreecommitdiff
path: root/examples/stm32g4/src
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2021-11-27 02:21:53 +0100
committerDario Nieuwenhuis <[email protected]>2021-11-27 02:34:23 +0100
commit88d4b0c00d5164f2fe6307bacce74887b3f8d4da (patch)
treea74fe2a9024167880d4ee4c7ac4f748ce5415f76 /examples/stm32g4/src
parentc7d97290284d2637c1eb89f65ff18f913342a71b (diff)
stm32: add stm32g4 support.
Diffstat (limited to 'examples/stm32g4/src')
-rw-r--r--examples/stm32g4/src/bin/blinky.rs29
-rw-r--r--examples/stm32g4/src/bin/button.rs27
-rw-r--r--examples/stm32g4/src/bin/button_exti.rs29
-rw-r--r--examples/stm32g4/src/example_common.rs17
4 files changed, 102 insertions, 0 deletions
diff --git a/examples/stm32g4/src/bin/blinky.rs b/examples/stm32g4/src/bin/blinky.rs
new file mode 100644
index 000000000..a43922a63
--- /dev/null
+++ b/examples/stm32g4/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;
7use embassy::executor::Spawner;
8use embassy::time::{Duration, Timer};
9use embassy_stm32::gpio::{Level, Output, Speed};
10use embassy_stm32::Peripherals;
11use embedded_hal::digital::v2::OutputPin;
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.PA5, Level::High, Speed::Low);
19
20 loop {
21 info!("high");
22 unwrap!(led.set_high());
23 Timer::after(Duration::from_millis(300)).await;
24
25 info!("low");
26 unwrap!(led.set_low());
27 Timer::after(Duration::from_millis(300)).await;
28 }
29}
diff --git a/examples/stm32g4/src/bin/button.rs b/examples/stm32g4/src/bin/button.rs
new file mode 100644
index 000000000..f0a4c8745
--- /dev/null
+++ b/examples/stm32g4/src/bin/button.rs
@@ -0,0 +1,27 @@
1#![no_std]
2#![no_main]
3#![feature(type_alias_impl_trait)]
4
5#[path = "../example_common.rs"]
6mod example_common;
7use cortex_m_rt::entry;
8use embassy_stm32::gpio::{Input, Pull};
9use embedded_hal::digital::v2::InputPin;
10use example_common::*;
11
12#[entry]
13fn main() -> ! {
14 info!("Hello World!");
15
16 let p = embassy_stm32::init(Default::default());
17
18 let button = Input::new(p.PC13, Pull::Down);
19
20 loop {
21 if unwrap!(button.is_high()) {
22 info!("high");
23 } else {
24 info!("low");
25 }
26 }
27}
diff --git a/examples/stm32g4/src/bin/button_exti.rs b/examples/stm32g4/src/bin/button_exti.rs
new file mode 100644
index 000000000..2c4318d64
--- /dev/null
+++ b/examples/stm32g4/src/bin/button_exti.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;
7use embassy::executor::Spawner;
8use embassy_stm32::exti::ExtiInput;
9use embassy_stm32::gpio::{Input, Pull};
10use embassy_stm32::Peripherals;
11use embassy_traits::gpio::{WaitForFallingEdge, WaitForRisingEdge};
12use example_common::*;
13
14#[embassy::main]
15async fn main(_spawner: Spawner, p: Peripherals) {
16 info!("Hello World!");
17
18 let button = Input::new(p.PC13, Pull::Down);
19 let mut button = ExtiInput::new(button, p.EXTI13);
20
21 info!("Press the USER button...");
22
23 loop {
24 button.wait_for_rising_edge().await;
25 info!("Pressed!");
26 button.wait_for_falling_edge().await;
27 info!("Released!");
28 }
29}
diff --git a/examples/stm32g4/src/example_common.rs b/examples/stm32g4/src/example_common.rs
new file mode 100644
index 000000000..54d633837
--- /dev/null
+++ b/examples/stm32g4/src/example_common.rs
@@ -0,0 +1,17 @@
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! {"{=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}