split the wakeup now, properly working
This commit is contained in:
@@ -3,7 +3,6 @@
|
|||||||
#![no_main]
|
#![no_main]
|
||||||
|
|
||||||
use defmt::*;
|
use defmt::*;
|
||||||
use core::ptr::addr_of_mut;
|
|
||||||
use embassy_stm32::pac;
|
use embassy_stm32::pac;
|
||||||
use embassy_executor::Spawner;
|
use embassy_executor::Spawner;
|
||||||
use embassy_futures::yield_now;
|
use embassy_futures::yield_now;
|
||||||
@@ -12,7 +11,6 @@ use embassy_stm32::peripherals;
|
|||||||
use embassy_stm32::Config;
|
use embassy_stm32::Config;
|
||||||
use embassy_stm32::usart::{BufferedUart, Config as UsartConfig, BufferedInterruptHandler};
|
use embassy_stm32::usart::{BufferedUart, Config as UsartConfig, BufferedInterruptHandler};
|
||||||
use embassy_stm32::gpio::{Output, Level, Speed};
|
use embassy_stm32::gpio::{Output, Level, Speed};
|
||||||
use embassy_stm32::wdg::IndependentWatchdog;
|
|
||||||
use embassy_time::{Duration, Timer};
|
use embassy_time::{Duration, Timer};
|
||||||
|
|
||||||
use static_cell::StaticCell;
|
use static_cell::StaticCell;
|
||||||
@@ -20,6 +18,7 @@ use dma_gpio::config::{
|
|||||||
BAUD, PIPE_HW_RX, PIPE_HW_TX,
|
BAUD, PIPE_HW_RX, PIPE_HW_TX,
|
||||||
};
|
};
|
||||||
use dma_gpio::hw_uart_pc::{driver::uart_task, usart1};
|
use dma_gpio::hw_uart_pc::{driver::uart_task, usart1};
|
||||||
|
use dma_gpio::wakeup::iwdg::{clear_wakeup_flags, init_watchdog};
|
||||||
use {defmt_rtt as _, panic_probe as _};
|
use {defmt_rtt as _, panic_probe as _};
|
||||||
|
|
||||||
bind_interrupts!(struct Irqs {
|
bind_interrupts!(struct Irqs {
|
||||||
@@ -30,8 +29,6 @@ unsafe extern "C" {
|
|||||||
fn HAL_PWR_EnterSTANDBYMode();
|
fn HAL_PWR_EnterSTANDBYMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
const PWR_FLAG_SBF: u32 = 1 << 1;
|
|
||||||
|
|
||||||
#[embassy_executor::main]
|
#[embassy_executor::main]
|
||||||
async fn main(spawner: Spawner) {
|
async fn main(spawner: Spawner) {
|
||||||
info!("boot");
|
info!("boot");
|
||||||
@@ -40,16 +37,10 @@ async fn main(spawner: Spawner) {
|
|||||||
let _led_ground = Output::new(p.PB0, Level::Low, Speed::Low);
|
let _led_ground = Output::new(p.PB0, Level::Low, Speed::Low);
|
||||||
info!("init m8");
|
info!("init m8");
|
||||||
|
|
||||||
// Clearing after the wakeup
|
clear_wakeup_flags();
|
||||||
let rcc = pac::RCC;
|
|
||||||
rcc.csr().write(|w| w.set_rmvf(true));
|
led.set_high();
|
||||||
|
info!("LED ON (MCU awake)");
|
||||||
// Check wake source
|
|
||||||
let pwr = pac::PWR;
|
|
||||||
if pwr.sr().read().sbf() {
|
|
||||||
info!("Woke from Standby via watchdog");
|
|
||||||
pwr.sr().write(|w| w.set_sbf(true));
|
|
||||||
}
|
|
||||||
|
|
||||||
// HARDWARE UART to the PC
|
// HARDWARE UART to the PC
|
||||||
let mut cfg = UsartConfig::default();
|
let mut cfg = UsartConfig::default();
|
||||||
@@ -74,19 +65,10 @@ async fn main(spawner: Spawner) {
|
|||||||
info!("DBGMCU CR: dbg_stop={}, dbg_standby={}", cr.dbg_stop(), cr.dbg_standby());
|
info!("DBGMCU CR: dbg_stop={}, dbg_standby={}", cr.dbg_stop(), cr.dbg_standby());
|
||||||
|
|
||||||
// MAIN LOOP
|
// MAIN LOOP
|
||||||
info!("tick start");
|
info!("Preparing for standby...");
|
||||||
led.set_high();
|
|
||||||
info!("LED IS HIGH");
|
|
||||||
Timer::after(Duration::from_millis(500)).await;
|
Timer::after(Duration::from_millis(500)).await;
|
||||||
led.set_low();
|
|
||||||
info!("LED IS LOW");
|
|
||||||
Timer::after(Duration::from_millis(500)).await;
|
|
||||||
led.set_high();
|
|
||||||
info!("LED IS HIGH");
|
|
||||||
|
|
||||||
info!("Iwdg init");
|
init_watchdog(p.IWDG).await;
|
||||||
let mut watchdog = IndependentWatchdog::new(p.IWDG, 2_000_000); // 2 seconds
|
|
||||||
watchdog.unleash();
|
|
||||||
Timer::after(Duration::from_millis(10)).await;
|
Timer::after(Duration::from_millis(10)).await;
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
@@ -96,5 +78,6 @@ async fn main(spawner: Spawner) {
|
|||||||
|
|
||||||
loop {
|
loop {
|
||||||
cortex_m::asm::wfi();
|
cortex_m::asm::wfi();
|
||||||
|
yield_now().await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,5 +6,7 @@ pub const BAUD: u32 = 9_600;
|
|||||||
pub const PIPE_HW_TX_SIZE: usize = 1024;
|
pub const PIPE_HW_TX_SIZE: usize = 1024;
|
||||||
pub const PIPE_HW_RX_SIZE: usize = 1024;
|
pub const PIPE_HW_RX_SIZE: usize = 1024;
|
||||||
|
|
||||||
|
pub const WATCHDOG_TIMEOUT_US: u32 = 2_000_000; // 2 seconds
|
||||||
|
|
||||||
pub static PIPE_HW_TX: Pipe<CriticalSectionRawMutex, PIPE_HW_TX_SIZE> = Pipe::new();
|
pub static PIPE_HW_TX: Pipe<CriticalSectionRawMutex, PIPE_HW_TX_SIZE> = Pipe::new();
|
||||||
pub static PIPE_HW_RX: Pipe<CriticalSectionRawMutex, PIPE_HW_RX_SIZE> = Pipe::new();
|
pub static PIPE_HW_RX: Pipe<CriticalSectionRawMutex, PIPE_HW_RX_SIZE> = Pipe::new();
|
||||||
|
|||||||
@@ -1 +1,13 @@
|
|||||||
// src/sleep/standby.rs
|
// src/sleep/standby.rs
|
||||||
|
|
||||||
|
pub fn enter_standby() -> ! {
|
||||||
|
unsafe extern "C" {
|
||||||
|
fn HAL_PWR_EnterSTANDBYMode();
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe {
|
||||||
|
HAL_PWR_EnterSTANDBYMode();
|
||||||
|
}
|
||||||
|
|
||||||
|
cortex_m::asm::udf(); // never happen marker
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,3 +1,34 @@
|
|||||||
// src/wakeup/iwdg.rs
|
// 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;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user