aboutsummaryrefslogtreecommitdiff
path: root/examples/stm32wle5/src/bin/button_exti.rs
diff options
context:
space:
mode:
authorRaul Alimbekov <[email protected]>2025-12-16 09:05:22 +0300
committerGitHub <[email protected]>2025-12-16 09:05:22 +0300
commitc9a04b4b732b7a3b696eb8223664c1a7942b1875 (patch)
tree6dbe5c02e66eed8d8762f13f95afd24f8db2b38c /examples/stm32wle5/src/bin/button_exti.rs
parentcde24a3ef1117653ba5ed4184102b33f745782fb (diff)
parent5ae6e060ec1c90561719aabdc29d5b6e7b8b0a82 (diff)
Merge branch 'main' into main
Diffstat (limited to 'examples/stm32wle5/src/bin/button_exti.rs')
-rw-r--r--examples/stm32wle5/src/bin/button_exti.rs64
1 files changed, 64 insertions, 0 deletions
diff --git a/examples/stm32wle5/src/bin/button_exti.rs b/examples/stm32wle5/src/bin/button_exti.rs
new file mode 100644
index 000000000..9ffc39948
--- /dev/null
+++ b/examples/stm32wle5/src/bin/button_exti.rs
@@ -0,0 +1,64 @@
1#![no_std]
2#![no_main]
3
4use defmt::*;
5#[cfg(feature = "defmt-rtt")]
6use defmt_rtt as _;
7use embassy_executor::Spawner;
8use embassy_stm32::exti::{self, ExtiInput};
9use embassy_stm32::gpio::Pull;
10use embassy_stm32::{bind_interrupts, interrupt, low_power};
11use panic_probe as _;
12use static_cell::StaticCell;
13
14bind_interrupts!(
15 pub struct Irqs{
16 EXTI0 => exti::InterruptHandler<interrupt::typelevel::EXTI0>;
17});
18
19#[embassy_executor::main(executor = "low_power::Executor")]
20async fn async_main(_spawner: Spawner) {
21 let mut config = embassy_stm32::Config::default();
22 // enable HSI clock
23 config.rcc.hsi = true;
24 // enable LSI clock for RTC
25 config.rcc.ls = embassy_stm32::rcc::LsConfig::default_lsi();
26 config.rcc.msi = Some(embassy_stm32::rcc::MSIRange::RANGE4M);
27 config.rcc.sys = embassy_stm32::rcc::Sysclk::MSI;
28 // enable ADC with HSI clock
29 config.rcc.mux.adcsel = embassy_stm32::pac::rcc::vals::Adcsel::HSI;
30 #[cfg(feature = "defmt-serial")]
31 {
32 // disable debug during sleep to reduce power consumption since we are
33 // using defmt-serial on LPUART1.
34 config.enable_debug_during_sleep = false;
35 // if we are using defmt-serial on LPUART1, we need to use HSI for the clock
36 // so that its registers are preserved during STOP modes.
37 config.rcc.mux.lpuart1sel = embassy_stm32::pac::rcc::vals::Lpuart1sel::HSI;
38 }
39 // Initialize STM32WL peripherals (use default config like wio-e5-async example)
40 let p = embassy_stm32::init(config);
41
42 #[cfg(feature = "defmt-serial")]
43 {
44 use embassy_stm32::mode::Blocking;
45 use embassy_stm32::usart::Uart;
46 let config = embassy_stm32::usart::Config::default();
47 let uart = Uart::new_blocking(p.LPUART1, p.PC0, p.PC1, config).expect("failed to configure UART!");
48 static SERIAL: StaticCell<Uart<'static, Blocking>> = StaticCell::new();
49 defmt_serial::defmt_serial(SERIAL.init(uart));
50 }
51
52 info!("Hello World!");
53
54 let mut button = ExtiInput::new(p.PA0, p.EXTI0, Pull::Up, Irqs);
55
56 info!("Press the USER button...");
57
58 loop {
59 button.wait_for_falling_edge().await;
60 info!("Pressed!");
61 button.wait_for_rising_edge().await;
62 info!("Released!");
63 }
64}