From c6365ffb922c7718b0ab238fe2437d4b726228b7 Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 5 Dec 2018 00:40:05 +1100 Subject: [PATCH] stm32/powerctrl: Add support for standby mode on L4 MCUs. This maps to machine.deepsleep() which is now supported. --- ports/stm32/modmachine.c | 4 ---- ports/stm32/powerctrl.c | 6 ++++-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/ports/stm32/modmachine.c b/ports/stm32/modmachine.c index 26eb99296d..7c8104b130 100644 --- a/ports/stm32/modmachine.c +++ b/ports/stm32/modmachine.c @@ -330,11 +330,7 @@ STATIC mp_obj_t machine_sleep(void) { MP_DEFINE_CONST_FUN_OBJ_0(machine_sleep_obj, machine_sleep); STATIC mp_obj_t machine_deepsleep(void) { - #if defined(STM32L4) - printf("machine.deepsleep not supported yet\n"); - #else powerctrl_enter_standby_mode(); - #endif return mp_const_none; } MP_DEFINE_CONST_FUN_OBJ_0(machine_deepsleep_obj, machine_deepsleep); diff --git a/ports/stm32/powerctrl.c b/ports/stm32/powerctrl.c index d4590029c9..fe4d580017 100644 --- a/ports/stm32/powerctrl.c +++ b/ports/stm32/powerctrl.c @@ -340,7 +340,6 @@ void powerctrl_enter_stop_mode(void) { enable_irq(irq_state); } -#if !defined(STM32L4) void powerctrl_enter_standby_mode(void) { rtc_init_finalise(); @@ -376,6 +375,10 @@ void powerctrl_enter_standby_mode(void) { PWR->CR2 |= PWR_CR2_CWUPF6 | PWR_CR2_CWUPF5 | PWR_CR2_CWUPF4 | PWR_CR2_CWUPF3 | PWR_CR2_CWUPF2 | PWR_CR2_CWUPF1; #elif defined(STM32H7) // TODO + #elif defined(STM32L4) + // clear all wake-up flags + PWR->SCR |= PWR_SCR_CWUF5 | PWR_SCR_CWUF4 | PWR_SCR_CWUF3 | PWR_SCR_CWUF2 | PWR_SCR_CWUF1; + // TODO #else // clear global wake-up flag PWR->CR |= PWR_CR_CWUF; @@ -388,4 +391,3 @@ void powerctrl_enter_standby_mode(void) { HAL_PWR_EnterSTANDBYMode(); // we never return; MCU is reset on exit from standby } -#endif