2022-03-17 10:36 AM
I have stm32f4 standby which works as expected if wakeup PA0 is low - my mcu wakes up once I apply high to PA0
I have the problem if PA0 line is constantly high I get wake up right after standby. My understanding is it's supposed to wait for rising edge and not wake up on high level if it was there the moment of standby call? Datasheet says "The device exits the Standby mode when" ... "rising edge on the WKUP pin occurs."
PWR_CR_CWUF might be relevant and I do clear it yet things are not the way I expect those.
How can I fix my code to work as desired only on rising edge or is MCU behaving as expected based on high level regardless of edges?
// Don't get bothered by interrupts
__disable_irq();
SysTick->CTRL = 0;
SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
PWR->CR |= PWR_CR_PDDS; // PDDS = use standby mode (not stop mode)
PWR->CR |= PWR_CR_CSBF; // Clear standby flag
//Enable Wakeup Pin for PA0
PWR->CSR |= PWR_CSR_EWUP;
// Clear wakeup flag - it may be set if PA0 is already
// high when we enable it as a wake source
PWR->CR |= PWR_CR_CWUF; //Clear Wakeup Pin flag for PA0
__WFI();
2022-03-18 02:30 AM
Well, it could be that you have a pending interrupt when you set PWR_CSR_EWUP so it looks like the wakeup fires immediately. Perhaps it would make sense to exchange lines 10 and 14 to clear first and then enable:
// Clear wakeup flag - it may be set if PA0 is already
// high when we enable it as a wake source
PWR->CR |= PWR_CR_CWUF; //Clear Wakeup Pin flag for PA0
//Enable Wakeup Pin for PA0
PWR->CSR |= PWR_CSR_EWUP;
Regards
/Peter
2022-03-18 12:11 PM
I've tried with the proposed different order of instructions but no changes in outcome - still auto-reboot if I supply constant 5v