wake up pin working for the wake up

This commit is contained in:
Priec
2025-12-14 14:33:01 +01:00
parent f4ca3071f0
commit 20dfdbc335
5 changed files with 21 additions and 22 deletions

View File

@@ -11,6 +11,7 @@ use embassy_time::{Duration, Timer};
use dma_gpio::config::BAUD; use dma_gpio::config::BAUD;
use dma_gpio::wakeup::iwdg::{clear_wakeup_flags, init_watchdog_reset}; use dma_gpio::wakeup::iwdg::{clear_wakeup_flags, init_watchdog_reset};
use dma_gpio::wakeup::gpio::gpio_wakeup;
use dma_gpio::sleep::handler::execute_low_power; use dma_gpio::sleep::handler::execute_low_power;
use dma_gpio::hw_uart_pc::init::{init_hw_uart_to_pc, LowPowerCmd, CMD_CH}; use dma_gpio::hw_uart_pc::init::{init_hw_uart_to_pc, LowPowerCmd, CMD_CH};
use {defmt_rtt as _, panic_probe as _}; use {defmt_rtt as _, panic_probe as _};
@@ -29,7 +30,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);
@@ -65,6 +66,7 @@ async fn main(spawner: Spawner) {
info!("ready for uart"); info!("ready for uart");
let mut iwdg = Some(p.IWDG); let mut iwdg = Some(p.IWDG);
spawner.spawn(gpio_wakeup(p.PA0, p.EXTI0).unwrap()); // exti wake up
loop { loop {
let cmd = CMD_CH.receive().await; let cmd = CMD_CH.receive().await;
execute_low_power(cmd, &mut iwdg).await; execute_low_power(cmd, &mut iwdg).await;

View File

@@ -97,7 +97,7 @@ pub async fn uart_cmd_task() {
CMD_CH.send(LowPowerCmd::StopMode(StopModeConfig { CMD_CH.send(LowPowerCmd::StopMode(StopModeConfig {
mode: stop_mode, mode: stop_mode,
entry: StopEntry::Wfi, // to tu je, lebo nejdem prepisovat kod, kvoli entry: StopEntry::Wfi, // to tu je, lebo nejdem prepisovat kod, kvoli
// posratemu halu co si nevie urobit konzistentnost // pos**temu halu co si nevie urobit konzistentnost
})).await; })).await;
continue; continue;
} }

View File

@@ -14,7 +14,7 @@ use defmt::info;
pub async fn execute_low_power( pub async fn execute_low_power(
cmd: LowPowerCmd, cmd: LowPowerCmd,
iwdg: &mut Option<Peri<'static, peripherals::IWDG>> iwdg: &mut Option<Peri<'static, peripherals::IWDG>>
) -> ! { ) {
Timer::after(Duration::from_millis(10)).await; Timer::after(Duration::from_millis(10)).await;
match cmd { match cmd {
@@ -45,14 +45,16 @@ pub async fn execute_low_power(
} }
LowPowerCmd::StopMode(StopModeConfig { mode, entry }) => { LowPowerCmd::StopMode(StopModeConfig { mode, entry }) => {
info!("Entering {:?} with {:?}", mode, entry); info!("Entering {:?} with {:?}", mode, entry);
if let Some(wdg) = iwdg.take() {
init_watchdog_reset(wdg).await;
}
match mode { match mode {
StopMode::Stop0 => enter_stop0(), StopMode::Stop0 => enter_stop0(),
StopMode::Stop1 => enter_stop1(entry), StopMode::Stop1 => enter_stop1(entry),
StopMode::Stop2 => enter_stop2(entry), StopMode::Stop2 => enter_stop2(entry),
StopMode::Stop3 => enter_stop3(entry), StopMode::Stop3 => {
if let Some(wdg) = iwdg.take() {
init_watchdog_reset(wdg).await;
}
enter_stop3(entry);
}
} }
} }
} }

View File

@@ -22,7 +22,7 @@ impl From<StopEntry> for u8 {
} }
} }
pub fn enter_stop0() -> ! { pub fn enter_stop0() {
unsafe extern "C" { unsafe extern "C" {
fn rust_LL_PWR_SetPowerMode(mode: u32); fn rust_LL_PWR_SetPowerMode(mode: u32);
} }
@@ -35,12 +35,11 @@ pub fn enter_stop0() -> ! {
let mut core = Peripherals::steal(); let mut core = Peripherals::steal();
core.SCB.set_sleepdeep(); core.SCB.set_sleepdeep();
asm::wfi(); asm::wfi();
core.SCB.clear_sleepdeep();
} }
cortex_m::asm::udf();
} }
pub fn enter_stop1(entry: StopEntry) -> ! { pub fn enter_stop1(entry: StopEntry) {
unsafe extern "C" { unsafe extern "C" {
fn HAL_PWREx_EnterSTOP1Mode(entry: u8); fn HAL_PWREx_EnterSTOP1Mode(entry: u8);
} }
@@ -48,11 +47,9 @@ pub fn enter_stop1(entry: StopEntry) -> ! {
unsafe { unsafe {
HAL_PWREx_EnterSTOP1Mode(entry.into()); HAL_PWREx_EnterSTOP1Mode(entry.into());
} }
cortex_m::asm::udf()
} }
pub fn enter_stop2(entry: StopEntry) -> ! { pub fn enter_stop2(entry: StopEntry) {
unsafe extern "C" { unsafe extern "C" {
fn HAL_PWREx_EnterSTOP2Mode(entry: u8); fn HAL_PWREx_EnterSTOP2Mode(entry: u8);
} }
@@ -60,11 +57,9 @@ pub fn enter_stop2(entry: StopEntry) -> ! {
unsafe { unsafe {
HAL_PWREx_EnterSTOP2Mode(entry.into()); HAL_PWREx_EnterSTOP2Mode(entry.into());
} }
cortex_m::asm::udf()
} }
pub fn enter_stop3(entry: StopEntry) -> ! { pub fn enter_stop3(entry: StopEntry) {
unsafe extern "C" { unsafe extern "C" {
fn HAL_PWREx_EnterSTOP3Mode(entry: u8); fn HAL_PWREx_EnterSTOP3Mode(entry: u8);
} }
@@ -72,6 +67,4 @@ pub fn enter_stop3(entry: StopEntry) -> ! {
unsafe { unsafe {
HAL_PWREx_EnterSTOP3Mode(entry.into()); HAL_PWREx_EnterSTOP3Mode(entry.into());
} }
cortex_m::asm::udf()
} }

View File

@@ -4,6 +4,7 @@ use defmt::info;
use embassy_stm32::exti::ExtiInput; use embassy_stm32::exti::ExtiInput;
use embassy_stm32::gpio::Pull; use embassy_stm32::gpio::Pull;
use embassy_stm32::{peripherals, interrupt}; use embassy_stm32::{peripherals, interrupt};
use embassy_time::{Duration, Timer};
use embassy_hal_internal::Peri; use embassy_hal_internal::Peri;
/// GPIO pin as an EXTI wakeup source. /// GPIO pin as an EXTI wakeup source.
@@ -13,11 +14,12 @@ pub async fn gpio_wakeup(
ch: Peri<'static, peripherals::EXTI0> ch: Peri<'static, peripherals::EXTI0>
) { ) {
info!("Configuring EXTI wake input on PA0 (rising edge)"); info!("Configuring EXTI wake input on PA0 (rising edge)");
let mut btn = ExtiInput::new(pin, ch, Pull::Down); let mut btn = ExtiInput::new(pin, ch, Pull::Up);
loop { loop {
info!("Waiting for rising edge on PA0"); info!("Waiting for rising edge on PA0");
btn.wait_for_rising_edge().await; btn.wait_for_falling_edge().await;
info!("GPIO wakeup: event detected!"); info!("GPIO wakeup: event detected!");
Timer::after(Duration::from_millis(50)).await;
} }
} }