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

@@ -29,7 +29,7 @@ async fn main(spawner: Spawner) {
info!("LED ON (MCU awake)");
// LED BLINK
spawner.spawn(led_blink(led).unwrap());
// spawner.spawn(led_blink(led).unwrap());
// INIT HW UART
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;
/// Clears system reset and standby flags after wakeup.
///
/// 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.
/// Call early in startup
///
/// # Registers
/// - `RCC_CSR` — Reset and Clock Control / Status
@@ -38,10 +35,7 @@ pub fn clear_wakeup_flags() {
}
/// Initializes the Independent Watchdog (IWDG) timer.
/// Wakeup source: Can wake the system from Standby mode on timeout
///
/// # Timing
/// - Timeout value is configured in `WATCHDOG_TIMEOUT_US` from config.rs
/// Timeout value is configured in `WATCHDOG_TIMEOUT_US` from config.rs
pub async fn init_watchdog_reset(iwdg: Peri<'static, peripherals::IWDG>) {
info!("Initializing watchdog after watchdog wake...");
let mut watchdog = IndependentWatchdog::new(iwdg, WATCHDOG_TIMEOUT_US);

View File

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