exti gpio wake up

This commit is contained in:
Priec
2025-12-14 12:50:21 +01:00
parent bbddc7cf9c
commit f4ca3071f0
5 changed files with 28 additions and 10 deletions

View File

@@ -16,7 +16,7 @@ embassy-sync = { git = "https://github.com/embassy-rs/embassy.git", branch =
embassy-time = { git = "https://github.com/embassy-rs/embassy.git", branch = "main", features = ["tick-hz-32_768"] } embassy-time = { git = "https://github.com/embassy-rs/embassy.git", branch = "main", features = ["tick-hz-32_768"] }
embassy-hal-internal = { git = "https://github.com/embassy-rs/embassy.git", branch = "main" } embassy-hal-internal = { git = "https://github.com/embassy-rs/embassy.git", branch = "main" }
embassy-usb = { git = "https://github.com/embassy-rs/embassy.git", branch = "main" } embassy-usb = { git = "https://github.com/embassy-rs/embassy.git", branch = "main" }
embassy-stm32 = { git = "https://github.com/embassy-rs/embassy.git", branch = "main", features = ["unstable-pac", "stm32u575zi", "time-driver-tim2", "memory-x", "defmt"] } embassy-stm32 = { git = "https://github.com/embassy-rs/embassy.git", branch = "main", features = ["unstable-pac", "stm32u575zi", "time-driver-tim2", "memory-x", "defmt", "exti"] }
embedded-hal = "1.0.0" embedded-hal = "1.0.0"
embedded-graphics = "0.8.1" embedded-graphics = "0.8.1"

View File

@@ -29,7 +29,7 @@ async fn main(spawner: Spawner) {
info!("LED ON (MCU awake)"); info!("LED ON (MCU awake)");
// LED BLINK // LED BLINK
spawner.spawn(led_blink(led).unwrap()); // spawner.spawn(led_blink(led).unwrap());
// INIT HW UART // INIT HW UART
init_hw_uart_to_pc(p.USART1, p.PA10, p.PA9, &spawner); init_hw_uart_to_pc(p.USART1, p.PA10, p.PA9, &spawner);

View File

@@ -0,0 +1,23 @@
// src/wakeup/gpio.rs
use defmt::info;
use embassy_stm32::exti::ExtiInput;
use embassy_stm32::gpio::Pull;
use embassy_stm32::{peripherals, interrupt};
use embassy_hal_internal::Peri;
/// GPIO pin as an EXTI wakeup source.
#[embassy_executor::task]
pub async fn gpio_wakeup(
pin: Peri<'static, peripherals::PA0>,
ch: Peri<'static, peripherals::EXTI0>
) {
info!("Configuring EXTI wake input on PA0 (rising edge)");
let mut btn = ExtiInput::new(pin, ch, Pull::Down);
loop {
info!("→ Waiting for rising edge on PA0…");
btn.wait_for_rising_edge().await;
info!("GPIO wakeup: event detected!");
}
}

View File

@@ -11,10 +11,7 @@ use crate::sleep::standby;
use crate::config::WATCHDOG_TIMEOUT_US; use crate::config::WATCHDOG_TIMEOUT_US;
/// Clears system reset and standby flags after wakeup. /// Clears system reset and standby flags after wakeup.
/// /// Call early in startup
/// Call early in startup to:
/// - Clear reset flags by setting `RMVF` in `RCC_CSR`.
/// - If `SBF` in `PWR_SR` is set (woke from Standby), clear it.
/// ///
/// # Registers /// # Registers
/// - `RCC_CSR` — Reset and Clock Control / Status /// - `RCC_CSR` — Reset and Clock Control / Status
@@ -38,10 +35,7 @@ pub fn clear_wakeup_flags() {
} }
/// Initializes the Independent Watchdog (IWDG) timer. /// Initializes the Independent Watchdog (IWDG) timer.
/// Wakeup source: Can wake the system from Standby mode on timeout /// Timeout value is configured in `WATCHDOG_TIMEOUT_US` from config.rs
///
/// # Timing
/// - Timeout value is configured in `WATCHDOG_TIMEOUT_US` from config.rs
pub async fn init_watchdog_reset(iwdg: Peri<'static, peripherals::IWDG>) { pub async fn init_watchdog_reset(iwdg: Peri<'static, peripherals::IWDG>) {
info!("Initializing watchdog after watchdog wake..."); info!("Initializing watchdog after watchdog wake...");
let mut watchdog = IndependentWatchdog::new(iwdg, WATCHDOG_TIMEOUT_US); let mut watchdog = IndependentWatchdog::new(iwdg, WATCHDOG_TIMEOUT_US);

View File

@@ -1,3 +1,4 @@
// src/wakeup/mod.rs // src/wakeup/mod.rs
pub mod iwdg; pub mod iwdg;
pub mod gpio;