From 1c281d27689e074f8711ec1ce0fd9270e5f13751 Mon Sep 17 00:00:00 2001 From: Marian Buschsieweke Date: Tue, 5 Dec 2023 11:17:54 +0100 Subject: [PATCH] cpu/cortexm_common: work around bug on WFI for STM32 See [1] for details. (archive.org backup at [2]). Fixes https://github.com/RIOT-OS/RIOT/issues/13918 Fixes https://github.com/RIOT-OS/RIOT/issues/14015 [1]: https://cliffle.com/blog/stm32-wfi-bug/ [2]: https://web.archive.org/web/20231205101603/https://cliffle.com/blog/stm32-wfi-bug/ --- cpu/cortexm_common/include/cpu.h | 4 ++++ cpu/stm32/include/cpu_conf.h | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/cpu/cortexm_common/include/cpu.h b/cpu/cortexm_common/include/cpu.h index c99de0492e..9749778197 100644 --- a/cpu/cortexm_common/include/cpu.h +++ b/cpu/cortexm_common/include/cpu.h @@ -167,6 +167,10 @@ static inline void cortexm_sleep(int deep) unsigned state = irq_disable(); __DSB(); __WFI(); + /* Some CPUs require an ISB after WFI to work around silicon bugs */ +#if CORTEXM_ISB_REQUIRED_AFTER_WFI + __ISB(); +#endif irq_restore(state); } diff --git a/cpu/stm32/include/cpu_conf.h b/cpu/stm32/include/cpu_conf.h index 9f14da6869..a910fee151 100644 --- a/cpu/stm32/include/cpu_conf.h +++ b/cpu/stm32/include/cpu_conf.h @@ -87,6 +87,16 @@ extern "C" { #endif +/** + * @brief Enable workaround for bug in WFI by issuing an ISB + * + * This works around a bug on STM32 systems, see [1] for details, or [2] for + * an archive.org backup. + * [1]: https://cliffle.com/blog/stm32-wfi-bug + * [2]: https://web.archive.org/web/20231205101603/https://cliffle.com/blog/stm32-wfi-bug/ + */ +#define CORTEXM_ISB_REQUIRED_AFTER_WFI 1 + /** * @brief ARM Cortex-M specific CPU configuration * @{