split the wakeup now, properly working

This commit is contained in:
Priec
2025-12-03 16:52:30 +01:00
parent 9be1d514fb
commit 33543099c2
4 changed files with 53 additions and 25 deletions

View File

@@ -1,3 +1,34 @@
// src/wakeup/iwdg.rs
use defmt::info;
use embassy_stm32::peripherals;
use embassy_stm32::wdg::IndependentWatchdog;
use embassy_stm32::Peri;
use embassy_time::{Duration, Timer};
use embassy_stm32::pac;
use crate::config::WATCHDOG_TIMEOUT_US;
pub fn clear_wakeup_flags() {
info!("Clearing wakeup flags...");
// Clear reset flags
// let rcc = unsafe { &*pac::RCC::ptr() };
let rcc = pac::RCC;
rcc.csr().write(|w| w.set_rmvf(true));
// Check and clear Standby wakeup flag
// let pwr = unsafe { &*pac::PWR::ptr() };
let pwr = pac::PWR;
if pwr.sr().read().sbf() {
info!("Woke from Standby mode");
pwr.sr().write(|w| w.set_sbf(true));
}
}
pub async fn init_watchdog(iwdg: Peri<'_, peripherals::IWDG>) {
info!("Initializing watchdog after watchdog wake...");
let mut watchdog = IndependentWatchdog::new(iwdg, WATCHDOG_TIMEOUT_US);
watchdog.unleash();
Timer::after(Duration::from_millis(10)).await;
}