aboutsummaryrefslogtreecommitdiff
path: root/examples/stm32f1/src
diff options
context:
space:
mode:
authorMariusz Ryndzionek <[email protected]>2021-09-26 17:08:22 +0200
committerMariusz Ryndzionek <[email protected]>2021-09-28 18:31:04 +0200
commitbce909ec1eea95f93a6887aae5aa0b37d953ec85 (patch)
treed22557144ceab9172e8b1d4784fab870d48b9816 /examples/stm32f1/src
parent1650983e463e5f237d68957b0de1537f807cbc63 (diff)
Initial STM32F1 family support with two examples for STM32F103C8 (Blue Pill)
Diffstat (limited to 'examples/stm32f1/src')
-rw-r--r--examples/stm32f1/src/bin/blinky.rs29
-rw-r--r--examples/stm32f1/src/bin/hello.rs27
-rw-r--r--examples/stm32f1/src/example_common.rs17
3 files changed, 73 insertions, 0 deletions
diff --git a/examples/stm32f1/src/bin/blinky.rs b/examples/stm32f1/src/bin/blinky.rs
new file mode 100644
index 000000000..1e4f2deec
--- /dev/null
+++ b/examples/stm32f1/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.PC13, 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/stm32f1/src/bin/hello.rs b/examples/stm32f1/src/bin/hello.rs
new file mode 100644
index 000000000..efcb9a244
--- /dev/null
+++ b/examples/stm32f1/src/bin/hello.rs
@@ -0,0 +1,27 @@
1#![no_std]
2#![no_main]
3#![feature(type_alias_impl_trait)]
4
5use defmt::info;
6use embassy::executor::Spawner;
7use embassy::time::{Duration, Timer};
8use embassy_stm32::time::Hertz;
9use embassy_stm32::Config;
10use embassy_stm32::Peripherals;
11
12#[path = "../example_common.rs"]
13mod example_common;
14
15fn config() -> Config {
16 let mut config = Config::default();
17 config.rcc.sys_ck = Some(Hertz(36_000_000));
18 config
19}
20
21#[embassy::main(config = "config()")]
22async fn main(_spawner: Spawner, _p: Peripherals) -> ! {
23 loop {
24 info!("Hello World!");
25 Timer::after(Duration::from_secs(1)).await;
26 }
27}
diff --git a/examples/stm32f1/src/example_common.rs b/examples/stm32f1/src/example_common.rs
new file mode 100644
index 000000000..54d633837
--- /dev/null
+++ b/examples/stm32f1/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}