diff --git a/cpu/cortexm_common/include/cpu.h b/cpu/cortexm_common/include/cpu.h index b8e7e29e79b5871a9401217963084f2cc1e35d9a..1e79552051879e17b6c80854ac73e1a3bfb4eb9c 100644 --- a/cpu/cortexm_common/include/cpu.h +++ b/cpu/cortexm_common/include/cpu.h @@ -96,10 +96,10 @@ static inline void cortexm_sleep(int deep) } /* ensure that all memory accesses have completed and trigger sleeping */ - __disable_irq(); + unsigned state = irq_disable(); __DSB(); __WFI(); - __enable_irq(); + irq_restore(state); } /** diff --git a/cpu/stm32_common/periph/pm.c b/cpu/stm32_common/periph/pm.c index d2ad70fcf60d1a0cd1f04eb73ea53983e16955e0..be7f47f760c8cfb49809b26ecef86f4268edab67 100644 --- a/cpu/stm32_common/periph/pm.c +++ b/cpu/stm32_common/periph/pm.c @@ -25,10 +25,22 @@ #include "irq.h" #include "periph/pm.h" +#if defined(CPU_FAM_STM32F1) || defined(CPU_FAM_STM32F2) || defined(CPU_FAM_STM32F4) +#include "stmclk.h" +#endif #define ENABLE_DEBUG (0) #include "debug.h" +#ifndef PM_STOP_CONFIG +/** + * @brief Define config flags for stop mode + * + * Available values can be found in reference manual, PWR section, register CR. + */ +#define PM_STOP_CONFIG (PWR_CR_LPDS | PWR_CR_FPDS) +#endif + void pm_set(unsigned mode) { int deep = 0; @@ -49,6 +61,7 @@ void pm_set(unsigned mode) /* Clear PDDS and LPDS bits to enter stop mode on */ /* deepsleep with voltage regulator on */ PWR->CR &= ~(PWR_CR_PDDS | PWR_CR_LPDS); + PWR->CR |= PM_STOP_CONFIG; /* Set SLEEPDEEP bit of system control block */ deep = 1; break; @@ -56,6 +69,13 @@ void pm_set(unsigned mode) #endif cortexm_sleep(deep); + +#if defined(CPU_FAM_STM32F1) || defined(CPU_FAM_STM32F2) || defined(CPU_FAM_STM32F4) + if (deep) { + /* Re-init clock after STOP */ + stmclk_init_sysclk(); + } +#endif } #if defined(CPU_FAM_STM32F1) || defined(CPU_FAM_STM32F2) || defined(CPU_FAM_STM32F4) diff --git a/cpu/stm32f1/include/periph_cpu.h b/cpu/stm32f1/include/periph_cpu.h index f57c126ec8c09e965a10484f036b083fb9f099ee..e9f11d80b2ca5068ea00b2f6a9a911ea6076b8bc 100644 --- a/cpu/stm32f1/include/periph_cpu.h +++ b/cpu/stm32f1/include/periph_cpu.h @@ -67,6 +67,11 @@ extern "C" { */ #define PM_BLOCKER_INITIAL { .val_u32 = 0x01010101 } +/** + * @brief Define the config flag for stop mode + */ +#define PM_STOP_CONFIG (PWR_CR_LPDS) + #ifndef DOXYGEN /** * @brief Override GPIO mode options