diff --git a/cpu/cortexm_common/cortexm_init.c b/cpu/cortexm_common/cortexm_init.c index 5419d92db7..39ff3a9081 100644 --- a/cpu/cortexm_common/cortexm_init.c +++ b/cpu/cortexm_common/cortexm_init.c @@ -49,4 +49,7 @@ void cortexm_init(void) for (IRQn_Type i = 0; i < (int) CPU_IRQ_NUMOF; i++) { NVIC_SetPriority(i, CPU_DEFAULT_IRQ_PRIO); } + + /* enable wake up on events for __WFE CPU sleep */ + SCB->SCR |= SCB_SCR_SEVONPEND_Msk; } diff --git a/cpu/cortexm_common/include/cpu.h b/cpu/cortexm_common/include/cpu.h index c2a79cbacd..fbffb0f2da 100644 --- a/cpu/cortexm_common/include/cpu.h +++ b/cpu/cortexm_common/include/cpu.h @@ -102,6 +102,18 @@ static inline void cpu_print_last_instruction(void) printf("%p\n", (void*) lr_ptr); } +/** + * @brief Put the CPU into the 'wait for event' sleep mode + * + * This function is meant to be used for short periods of time, where it is not + * feasible to switch to the idle thread and back. + */ +static inline void cpu_sleep_until_event(void) +{ + __SEV(); + __WFE(); +} + #ifdef __cplusplus } #endif