diff options
| author | Ulf Lilleengen <[email protected]> | 2021-08-17 13:14:21 +0200 |
|---|---|---|
| committer | Ulf Lilleengen <[email protected]> | 2021-08-17 16:22:47 +0200 |
| commit | 61409e2fb6798a8474d32df581e1cabfa04ec565 (patch) | |
| tree | 6a9bd51971acd3fc6bb36c1f8ec9857b25cc48bb /examples | |
| parent | 4b74e8fc50b3b1839f118d9b310f793a46adc416 (diff) | |
Add example for STM32WL55
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/stm32wl55/Cargo.toml | 34 | ||||
| -rw-r--r-- | examples/stm32wl55/memory.x | 5 | ||||
| -rw-r--r-- | examples/stm32wl55/src/bin/blinky.rs | 34 | ||||
| -rw-r--r-- | examples/stm32wl55/src/bin/button.rs | 40 | ||||
| -rw-r--r-- | examples/stm32wl55/src/example_common.rs | 17 |
5 files changed, 130 insertions, 0 deletions
diff --git a/examples/stm32wl55/Cargo.toml b/examples/stm32wl55/Cargo.toml new file mode 100644 index 000000000..ebbe8b847 --- /dev/null +++ b/examples/stm32wl55/Cargo.toml | |||
| @@ -0,0 +1,34 @@ | |||
| 1 | [package] | ||
| 2 | authors = ["Dario Nieuwenhuis <[email protected]>", "Ulf Lilleengen <[email protected]>"] | ||
| 3 | edition = "2018" | ||
| 4 | name = "embassy-stm32wl55-examples" | ||
| 5 | version = "0.1.0" | ||
| 6 | resolver = "2" | ||
| 7 | |||
| 8 | [features] | ||
| 9 | default = [ | ||
| 10 | "defmt-default", | ||
| 11 | ] | ||
| 12 | defmt-default = [] | ||
| 13 | defmt-trace = [] | ||
| 14 | defmt-debug = [] | ||
| 15 | defmt-info = [] | ||
| 16 | defmt-warn = [] | ||
| 17 | defmt-error = [] | ||
| 18 | |||
| 19 | [dependencies] | ||
| 20 | embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt", "defmt-trace"] } | ||
| 21 | embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] } | ||
| 22 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "defmt-trace", "stm32wl55jc_cm4", "time-driver-tim2", "memory-x"] } | ||
| 23 | embassy-hal-common = {version = "0.1.0", path = "../../embassy-hal-common" } | ||
| 24 | |||
| 25 | defmt = "0.2.0" | ||
| 26 | defmt-rtt = "0.2.0" | ||
| 27 | |||
| 28 | cortex-m = "0.7.1" | ||
| 29 | cortex-m-rt = "0.6.14" | ||
| 30 | embedded-hal = { version = "0.2.4" } | ||
| 31 | panic-probe = { version = "0.2.0", features= ["print-defmt"] } | ||
| 32 | futures = { version = "0.3.8", default-features = false, features = ["async-await"] } | ||
| 33 | rtt-target = { version = "0.3", features = ["cortex-m"] } | ||
| 34 | heapless = { version = "0.7.1", default-features = false } | ||
diff --git a/examples/stm32wl55/memory.x b/examples/stm32wl55/memory.x new file mode 100644 index 000000000..e8b2737fe --- /dev/null +++ b/examples/stm32wl55/memory.x | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | MEMORY | ||
| 2 | { | ||
| 3 | FLASH : ORIGIN = 0x08000000, LENGTH = 256K | ||
| 4 | RAM : ORIGIN = 0x20000000, LENGTH = 64K | ||
| 5 | } | ||
diff --git a/examples/stm32wl55/src/bin/blinky.rs b/examples/stm32wl55/src/bin/blinky.rs new file mode 100644 index 000000000..b5e5ffcf9 --- /dev/null +++ b/examples/stm32wl55/src/bin/blinky.rs | |||
| @@ -0,0 +1,34 @@ | |||
| 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::dbgmcu::Dbgmcu; | ||
| 12 | use embassy_stm32::gpio::{Level, Output, Speed}; | ||
| 13 | use embassy_stm32::Peripherals; | ||
| 14 | use embedded_hal::digital::v2::OutputPin; | ||
| 15 | use example_common::*; | ||
| 16 | |||
| 17 | #[embassy::main] | ||
| 18 | async fn main(_spawner: Spawner, p: Peripherals) { | ||
| 19 | info!("Hello World!"); | ||
| 20 | |||
| 21 | unsafe { Dbgmcu::enable_all() }; | ||
| 22 | |||
| 23 | let mut led = Output::new(p.PB15, Level::High, Speed::Low); | ||
| 24 | |||
| 25 | loop { | ||
| 26 | info!("high"); | ||
| 27 | unwrap!(led.set_high()); | ||
| 28 | Timer::after(Duration::from_millis(500)).await; | ||
| 29 | |||
| 30 | info!("low"); | ||
| 31 | unwrap!(led.set_low()); | ||
| 32 | Timer::after(Duration::from_millis(500)).await; | ||
| 33 | } | ||
| 34 | } | ||
diff --git a/examples/stm32wl55/src/bin/button.rs b/examples/stm32wl55/src/bin/button.rs new file mode 100644 index 000000000..90212d3d7 --- /dev/null +++ b/examples/stm32wl55/src/bin/button.rs | |||
| @@ -0,0 +1,40 @@ | |||
| 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_stm32::{ | ||
| 10 | dbgmcu::Dbgmcu, | ||
| 11 | gpio::{Input, Level, Output, Pull, Speed}, | ||
| 12 | rcc::*, | ||
| 13 | }; | ||
| 14 | use embedded_hal::digital::v2::{InputPin, OutputPin}; | ||
| 15 | use example_common::*; | ||
| 16 | |||
| 17 | use cortex_m_rt::entry; | ||
| 18 | |||
| 19 | #[entry] | ||
| 20 | fn main() -> ! { | ||
| 21 | info!("Hello World!"); | ||
| 22 | |||
| 23 | let mut p = embassy_stm32::init(Default::default()); | ||
| 24 | |||
| 25 | unsafe { Dbgmcu::enable_all() }; | ||
| 26 | |||
| 27 | let button = Input::new(p.PA0, Pull::Up); | ||
| 28 | let mut led1 = Output::new(p.PB15, Level::High, Speed::Low); | ||
| 29 | let mut led2 = Output::new(p.PB9, Level::High, Speed::Low); | ||
| 30 | |||
| 31 | loop { | ||
| 32 | if button.is_high().unwrap() { | ||
| 33 | led1.set_high().unwrap(); | ||
| 34 | led2.set_low().unwrap(); | ||
| 35 | } else { | ||
| 36 | led1.set_low().unwrap(); | ||
| 37 | led2.set_high().unwrap(); | ||
| 38 | } | ||
| 39 | } | ||
| 40 | } | ||
diff --git a/examples/stm32wl55/src/example_common.rs b/examples/stm32wl55/src/example_common.rs new file mode 100644 index 000000000..54d633837 --- /dev/null +++ b/examples/stm32wl55/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 | } | ||
