wake up pin working for the wake up
This commit is contained in:
@@ -11,6 +11,7 @@ use embassy_time::{Duration, Timer};
|
||||
|
||||
use dma_gpio::config::BAUD;
|
||||
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::hw_uart_pc::init::{init_hw_uart_to_pc, LowPowerCmd, CMD_CH};
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
@@ -29,7 +30,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);
|
||||
@@ -65,6 +66,7 @@ async fn main(spawner: Spawner) {
|
||||
info!("ready for uart");
|
||||
let mut iwdg = Some(p.IWDG);
|
||||
|
||||
spawner.spawn(gpio_wakeup(p.PA0, p.EXTI0).unwrap()); // exti wake up
|
||||
loop {
|
||||
let cmd = CMD_CH.receive().await;
|
||||
execute_low_power(cmd, &mut iwdg).await;
|
||||
|
||||
@@ -97,7 +97,7 @@ pub async fn uart_cmd_task() {
|
||||
CMD_CH.send(LowPowerCmd::StopMode(StopModeConfig {
|
||||
mode: stop_mode,
|
||||
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;
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ use defmt::info;
|
||||
pub async fn execute_low_power(
|
||||
cmd: LowPowerCmd,
|
||||
iwdg: &mut Option<Peri<'static, peripherals::IWDG>>
|
||||
) -> ! {
|
||||
) {
|
||||
Timer::after(Duration::from_millis(10)).await;
|
||||
|
||||
match cmd {
|
||||
@@ -45,14 +45,16 @@ pub async fn execute_low_power(
|
||||
}
|
||||
LowPowerCmd::StopMode(StopModeConfig { mode, entry }) => {
|
||||
info!("Entering {:?} with {:?}", mode, entry);
|
||||
if let Some(wdg) = iwdg.take() {
|
||||
init_watchdog_reset(wdg).await;
|
||||
}
|
||||
match mode {
|
||||
StopMode::Stop0 => enter_stop0(),
|
||||
StopMode::Stop1 => enter_stop1(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ impl From<StopEntry> for u8 {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn enter_stop0() -> ! {
|
||||
pub fn enter_stop0() {
|
||||
unsafe extern "C" {
|
||||
fn rust_LL_PWR_SetPowerMode(mode: u32);
|
||||
}
|
||||
@@ -35,12 +35,11 @@ pub fn enter_stop0() -> ! {
|
||||
let mut core = Peripherals::steal();
|
||||
core.SCB.set_sleepdeep();
|
||||
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" {
|
||||
fn HAL_PWREx_EnterSTOP1Mode(entry: u8);
|
||||
}
|
||||
@@ -48,11 +47,9 @@ pub fn enter_stop1(entry: StopEntry) -> ! {
|
||||
unsafe {
|
||||
HAL_PWREx_EnterSTOP1Mode(entry.into());
|
||||
}
|
||||
|
||||
cortex_m::asm::udf()
|
||||
}
|
||||
|
||||
pub fn enter_stop2(entry: StopEntry) -> ! {
|
||||
pub fn enter_stop2(entry: StopEntry) {
|
||||
unsafe extern "C" {
|
||||
fn HAL_PWREx_EnterSTOP2Mode(entry: u8);
|
||||
}
|
||||
@@ -60,11 +57,9 @@ pub fn enter_stop2(entry: StopEntry) -> ! {
|
||||
unsafe {
|
||||
HAL_PWREx_EnterSTOP2Mode(entry.into());
|
||||
}
|
||||
|
||||
cortex_m::asm::udf()
|
||||
}
|
||||
|
||||
pub fn enter_stop3(entry: StopEntry) -> ! {
|
||||
pub fn enter_stop3(entry: StopEntry) {
|
||||
unsafe extern "C" {
|
||||
fn HAL_PWREx_EnterSTOP3Mode(entry: u8);
|
||||
}
|
||||
@@ -72,6 +67,4 @@ pub fn enter_stop3(entry: StopEntry) -> ! {
|
||||
unsafe {
|
||||
HAL_PWREx_EnterSTOP3Mode(entry.into());
|
||||
}
|
||||
|
||||
cortex_m::asm::udf()
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ use defmt::info;
|
||||
use embassy_stm32::exti::ExtiInput;
|
||||
use embassy_stm32::gpio::Pull;
|
||||
use embassy_stm32::{peripherals, interrupt};
|
||||
use embassy_time::{Duration, Timer};
|
||||
use embassy_hal_internal::Peri;
|
||||
|
||||
/// GPIO pin as an EXTI wake‑up source.
|
||||
@@ -13,11 +14,12 @@ pub async fn gpio_wakeup(
|
||||
ch: Peri<'static, peripherals::EXTI0>
|
||||
) {
|
||||
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 {
|
||||
info!("→ Waiting for rising edge on PA0…");
|
||||
btn.wait_for_rising_edge().await;
|
||||
info!("Waiting for rising edge on PA0");
|
||||
btn.wait_for_falling_edge().await;
|
||||
info!("GPIO wake‑up: event detected!");
|
||||
Timer::after(Duration::from_millis(50)).await;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user