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 | |
| parent | 4b74e8fc50b3b1839f118d9b310f793a46adc416 (diff) | |
Add example for STM32WL55
| -rw-r--r-- | embassy-stm32/src/exti/mod.rs | 3 | ||||
| -rw-r--r-- | embassy-stm32/src/rcc/wl5x/mod.rs | 9 | ||||
| -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 | ||||
| m--------- | stm32-data | 0 |
8 files changed, 132 insertions, 10 deletions
diff --git a/embassy-stm32/src/exti/mod.rs b/embassy-stm32/src/exti/mod.rs index 164cdba33..3f43e0bc7 100644 --- a/embassy-stm32/src/exti/mod.rs +++ b/embassy-stm32/src/exti/mod.rs | |||
| @@ -37,6 +37,7 @@ macro_rules! foreach_exti_irq { | |||
| 37 | #[cfg_attr(exti_v1, path = "v1.rs")] | 37 | #[cfg_attr(exti_v1, path = "v1.rs")] |
| 38 | #[cfg_attr(exti_h7, path = "v1.rs")] | 38 | #[cfg_attr(exti_h7, path = "v1.rs")] |
| 39 | #[cfg_attr(exti_wb55, path = "v2.rs")] | 39 | #[cfg_attr(exti_wb55, path = "v2.rs")] |
| 40 | #[cfg_attr(exti_wl5x, path = "v2.rs")] | ||
| 40 | mod _version; | 41 | mod _version; |
| 41 | 42 | ||
| 42 | #[allow(unused)] | 43 | #[allow(unused)] |
| @@ -110,6 +111,6 @@ pub(crate) unsafe fn init() { | |||
| 110 | 111 | ||
| 111 | foreach_exti_irq!(enable_irq); | 112 | foreach_exti_irq!(enable_irq); |
| 112 | 113 | ||
| 113 | #[cfg(not(rcc_wb55))] | 114 | #[cfg(not(any(rcc_wb55, rcc_wl5x)))] |
| 114 | <crate::peripherals::SYSCFG as crate::rcc::sealed::RccPeripheral>::enable(); | 115 | <crate::peripherals::SYSCFG as crate::rcc::sealed::RccPeripheral>::enable(); |
| 115 | } | 116 | } |
diff --git a/embassy-stm32/src/rcc/wl5x/mod.rs b/embassy-stm32/src/rcc/wl5x/mod.rs index b91adb203..72caad2ec 100644 --- a/embassy-stm32/src/rcc/wl5x/mod.rs +++ b/embassy-stm32/src/rcc/wl5x/mod.rs | |||
| @@ -116,15 +116,6 @@ impl<'d> Rcc<'d> { | |||
| 116 | pub fn clocks(&self) -> &'static Clocks { | 116 | pub fn clocks(&self) -> &'static Clocks { |
| 117 | unsafe { get_freqs() } | 117 | unsafe { get_freqs() } |
| 118 | } | 118 | } |
| 119 | |||
| 120 | pub fn enable_debug_wfe(&mut self, _dbg: &mut peripherals::DBGMCU, enable_dma: bool) { | ||
| 121 | // NOTE(unsafe) We have exclusive access to the RCC and DBGMCU | ||
| 122 | unsafe { | ||
| 123 | pac::RCC.ahb1enr().modify(|w| w.set_dma1en(enable_dma)); | ||
| 124 | |||
| 125 | Dbgmcu::enable_all(); | ||
| 126 | } | ||
| 127 | } | ||
| 128 | } | 119 | } |
| 129 | 120 | ||
| 130 | /// Extension trait that freezes the `RCC` peripheral with provided clocks configuration | 121 | /// Extension trait that freezes the `RCC` peripheral with provided clocks configuration |
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 | } | ||
diff --git a/stm32-data b/stm32-data | |||
| Subproject 75a76596c37f07cbbdaa3a689c1776297063b65 | Subproject bfd4797d1278c3e0b4611bc79e12346dedbde7c | ||
