Page 1 of 1

wakup from sleep on falling edge

Posted: Thu Jun 15, 2023 4:03 am
by hybridA
I want to wakeup from deep sleep after 30seconds and on a falling edge of an input.
Here's the code that puts the MCU to sleep, as found here:

Code: Select all

    wakeupspec.wutr = ((uint32_t)4) << 16;
    wakeupspec.wutr |= 29;
    rtcSTM32SetPeriodicWakeup(&RTCD1, &wakeupspec);
    chSysLock();
    SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
    PWR->CR  |= (PWR_CR_PDDS | PWR_CR_LPDS | PWR_CR_CSBF | PWR_CR_CWUF);
    RTC->ISR &= ~(RTC_ISR_ALRBF | RTC_ISR_ALRAF | RTC_ISR_WUTF | RTC_ISR_TAMP1F |
                    RTC_ISR_TSOVF | RTC_ISR_TSF);
    __enable_irq();
    __WFI();


This works OK, as in waking up every 30 seconds.
Additionally I would want to wake up whenever PC13 is falling.

I tried using palEnablePadEvent(), but that didn't' work. Is there a hal wrapper, or does this have to be done on a register level?

Re: wakup from sleep on falling edge

Posted: Thu Jun 15, 2023 7:28 am
by Giovanni
Hi,

That PAL function enables "PAL events" (callbacks), not the EXTI events you need for wakeup. Try at register level, most of your code is done that way already.

Giovanni