From f4ca3071f01aaf5762b12a9e69918fae697800c3 Mon Sep 17 00:00:00 2001 From: Priec Date: Sun, 14 Dec 2025 12:50:21 +0100 Subject: [PATCH] exti gpio wake up --- semestralka_2_uart/Cargo.toml | 2 +- semestralka_2_uart/src/bin/main.rs | 2 +- semestralka_2_uart/src/wakeup/gpio.rs | 23 +++++++++++++++++++++++ semestralka_2_uart/src/wakeup/iwdg.rs | 10 ++-------- semestralka_2_uart/src/wakeup/mod.rs | 1 + 5 files changed, 28 insertions(+), 10 deletions(-) create mode 100644 semestralka_2_uart/src/wakeup/gpio.rs diff --git a/semestralka_2_uart/Cargo.toml b/semestralka_2_uart/Cargo.toml index f57b237..bdaf178 100644 --- a/semestralka_2_uart/Cargo.toml +++ b/semestralka_2_uart/Cargo.toml @@ -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-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-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-graphics = "0.8.1" diff --git a/semestralka_2_uart/src/bin/main.rs b/semestralka_2_uart/src/bin/main.rs index 152a080..adfafc7 100644 --- a/semestralka_2_uart/src/bin/main.rs +++ b/semestralka_2_uart/src/bin/main.rs @@ -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); diff --git a/semestralka_2_uart/src/wakeup/gpio.rs b/semestralka_2_uart/src/wakeup/gpio.rs new file mode 100644 index 0000000..7761e78 --- /dev/null +++ b/semestralka_2_uart/src/wakeup/gpio.rs @@ -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 wake‑up 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 wake‑up: event detected!"); + } +} diff --git a/semestralka_2_uart/src/wakeup/iwdg.rs b/semestralka_2_uart/src/wakeup/iwdg.rs index 53c6479..0f1afed 100644 --- a/semestralka_2_uart/src/wakeup/iwdg.rs +++ b/semestralka_2_uart/src/wakeup/iwdg.rs @@ -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); diff --git a/semestralka_2_uart/src/wakeup/mod.rs b/semestralka_2_uart/src/wakeup/mod.rs index 87ed559..0c6cd63 100644 --- a/semestralka_2_uart/src/wakeup/mod.rs +++ b/semestralka_2_uart/src/wakeup/mod.rs @@ -1,3 +1,4 @@ // src/wakeup/mod.rs pub mod iwdg; +pub mod gpio;