diff options
| author | liebman <[email protected]> | 2025-12-18 15:04:45 -0800 |
|---|---|---|
| committer | liebman <[email protected]> | 2025-12-19 07:55:34 -0800 |
| commit | 9008e4ca79a8cea093484f09d02c9ca67e7e2b1f (patch) | |
| tree | 2ef61e05b4d687c8451253b930efae37c309e489 /examples/stm32wl5x-lp/src | |
| parent | 905bdfa7662c2ac5d2dfc81219c9704955473253 (diff) | |
low-power: stm32wl5x
Diffstat (limited to 'examples/stm32wl5x-lp/src')
| -rw-r--r-- | examples/stm32wl5x-lp/src/bin/blinky.rs | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/examples/stm32wl5x-lp/src/bin/blinky.rs b/examples/stm32wl5x-lp/src/bin/blinky.rs new file mode 100644 index 000000000..068b65248 --- /dev/null +++ b/examples/stm32wl5x-lp/src/bin/blinky.rs | |||
| @@ -0,0 +1,59 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | |||
| 4 | use core::mem::MaybeUninit; | ||
| 5 | |||
| 6 | use defmt::*; | ||
| 7 | #[cfg(feature = "defmt-rtt")] | ||
| 8 | use defmt_rtt as _; | ||
| 9 | use embassy_executor::Spawner; | ||
| 10 | use embassy_stm32::SharedData; | ||
| 11 | use embassy_stm32::gpio::{Level, Output, Speed}; | ||
| 12 | use embassy_time::Timer; | ||
| 13 | use panic_probe as _; | ||
| 14 | |||
| 15 | #[unsafe(link_section = ".shared_data")] | ||
| 16 | static SHARED_DATA: MaybeUninit<SharedData> = MaybeUninit::uninit(); | ||
| 17 | |||
| 18 | #[embassy_executor::main(executor = "embassy_stm32::Executor", entry = "cortex_m_rt::entry")] | ||
| 19 | async fn async_main(_spawner: Spawner) { | ||
| 20 | let mut config = embassy_stm32::Config::default(); | ||
| 21 | // enable HSI clock | ||
| 22 | // config.rcc.hsi = true; | ||
| 23 | // enable LSI clock for RTC | ||
| 24 | config.rcc.ls = embassy_stm32::rcc::LsConfig::default_lsi(); | ||
| 25 | config.rcc.msi = Some(embassy_stm32::rcc::MSIRange::RANGE4M); | ||
| 26 | config.rcc.sys = embassy_stm32::rcc::Sysclk::MSI; | ||
| 27 | #[cfg(feature = "defmt-serial")] | ||
| 28 | { | ||
| 29 | // disable debug during sleep to reduce power consumption since we are | ||
| 30 | // using defmt-serial on LPUART1. | ||
| 31 | config.enable_debug_during_sleep = false; | ||
| 32 | } | ||
| 33 | let p = embassy_stm32::init_primary(config, &SHARED_DATA); | ||
| 34 | |||
| 35 | #[cfg(feature = "defmt-serial")] | ||
| 36 | { | ||
| 37 | use embassy_stm32::mode::Blocking; | ||
| 38 | use embassy_stm32::usart::Uart; | ||
| 39 | use static_cell::StaticCell; | ||
| 40 | let config = embassy_stm32::usart::Config::default(); | ||
| 41 | let uart = Uart::new_blocking(p.LPUART1, p.PA3, p.PA2, config).expect("failed to configure UART!"); | ||
| 42 | static SERIAL: StaticCell<Uart<'static, Blocking>> = StaticCell::new(); | ||
| 43 | defmt_serial::defmt_serial(SERIAL.init(uart)); | ||
| 44 | } | ||
| 45 | |||
| 46 | info!("Hello World!"); | ||
| 47 | |||
| 48 | let mut led = Output::new(p.PB15, Level::High, Speed::Low); | ||
| 49 | |||
| 50 | loop { | ||
| 51 | info!("low"); | ||
| 52 | led.set_low(); | ||
| 53 | Timer::after_millis(5000).await; | ||
| 54 | |||
| 55 | info!("high"); | ||
| 56 | led.set_high(); | ||
| 57 | Timer::after_millis(5000).await; | ||
| 58 | } | ||
| 59 | } | ||
