aboutsummaryrefslogtreecommitdiff
path: root/examples/stm32g0/src
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2021-08-20 01:35:02 +0200
committerGitHub <[email protected]>2021-08-20 01:35:02 +0200
commit0be6e4a384b3c2fee34f6f6db5f86ecbf9cea5e5 (patch)
treef5b6608d18e0a49a28fd04389684cb81d7a17022 /examples/stm32g0/src
parent8e5f1f4b5e8ff20897ac86ca81605d50c3dfa966 (diff)
parentda707051b0bc963b63aea209dc47108de15543f5 (diff)
Merge pull request #333 from bgamari/stm32g0
Add support for STM32G0
Diffstat (limited to 'examples/stm32g0/src')
-rw-r--r--examples/stm32g0/src/bin/blinky.rs31
-rw-r--r--examples/stm32g0/src/bin/button.rs29
-rw-r--r--examples/stm32g0/src/bin/button_exti.rs31
-rw-r--r--examples/stm32g0/src/example_common.rs17
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"]
8mod example_common;
9use embassy::executor::Spawner;
10use embassy::time::{Duration, Timer};
11use embassy_stm32::gpio::{Level, Output, Speed};
12use embassy_stm32::Peripherals;
13use embedded_hal::digital::v2::OutputPin;
14use example_common::*;
15
16#[embassy::main]
17async 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"]
8mod example_common;
9use cortex_m_rt::entry;
10use embassy_stm32::gpio::{Input, Pull};
11use embedded_hal::digital::v2::InputPin;
12use example_common::*;
13
14#[entry]
15fn 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"]
8mod example_common;
9use embassy::executor::Spawner;
10use embassy_stm32::exti::ExtiInput;
11use embassy_stm32::gpio::{Input, Pull};
12use embassy_stm32::Peripherals;
13use embassy_traits::gpio::{WaitForFallingEdge, WaitForRisingEdge};
14use example_common::*;
15
16#[embassy::main]
17async 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
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}