diff options
author | Peter Hinch <peterhinch@users.noreply.github.com> | 2020-09-27 08:42:52 +0100 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2021-03-11 00:56:01 +1100 |
commit | 0facd891e7b4e226e7a905309f917dc271c1860b (patch) | |
tree | f173222be5457cf03a013c46a3b43df211e21e94 | |
parent | 85ea4ac0e56faca680aa03c41eb4009464401f07 (diff) |
stm32/powerctrl: Save and restore EWUP state when configuring standby.
This allows the user to enable wake-up sources using the EWUP bits, on F7
MCUs.
Disabling the wake-up sources while clearing the wake-up flags follows the
reference manual and ST examples.
-rw-r--r-- | ports/stm32/powerctrl.c | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/ports/stm32/powerctrl.c b/ports/stm32/powerctrl.c index bf8be647f..a579713b6 100644 --- a/ports/stm32/powerctrl.c +++ b/ports/stm32/powerctrl.c @@ -712,10 +712,14 @@ void powerctrl_enter_standby_mode(void) { RTC->ISR &= ~ISR_BITS; #if defined(STM32F7) + // Save EWUP state + uint32_t csr2_ewup = PWR->CSR2 & (PWR_CSR2_EWUP6 | PWR_CSR2_EWUP5 | PWR_CSR2_EWUP4 | PWR_CSR2_EWUP3 | PWR_CSR2_EWUP2 | PWR_CSR2_EWUP1); // disable wake-up flags PWR->CSR2 &= ~(PWR_CSR2_EWUP6 | PWR_CSR2_EWUP5 | PWR_CSR2_EWUP4 | PWR_CSR2_EWUP3 | PWR_CSR2_EWUP2 | PWR_CSR2_EWUP1); // clear global wake-up flag PWR->CR2 |= PWR_CR2_CWUPF6 | PWR_CR2_CWUPF5 | PWR_CR2_CWUPF4 | PWR_CR2_CWUPF3 | PWR_CR2_CWUPF2 | PWR_CR2_CWUPF1; + // Restore EWUP state + PWR->CSR2 |= csr2_ewup; #elif defined(STM32H7) EXTI_D1->PR1 = 0x3fffff; PWR->WKUPCR |= PWR_WAKEUP_FLAG1 | PWR_WAKEUP_FLAG2 | PWR_WAKEUP_FLAG3 | PWR_WAKEUP_FLAG4 | PWR_WAKEUP_FLAG5 | PWR_WAKEUP_FLAG6; |