From 304f4ec7d4426f8b549412dde29fc5b2eb4f9af8 Mon Sep 17 00:00:00 2001 From: Marian Buschsieweke Date: Fri, 25 Sep 2020 13:51:38 +0200 Subject: [PATCH] cpu/cortexm_common: flush pipeline after PendSV https://interrupt.memfault.com/blog/arm-cortex-m-exceptions-and-nvic#pendsv-example --- cpu/cortexm_common/thread_arch.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cpu/cortexm_common/thread_arch.c b/cpu/cortexm_common/thread_arch.c index 145372019d..19a1923e64 100644 --- a/cpu/cortexm_common/thread_arch.c +++ b/cpu/cortexm_common/thread_arch.c @@ -297,6 +297,9 @@ void thread_yield_higher(void) /* trigger the PENDSV interrupt to run scheduler and schedule new thread if * applicable */ SCB->ICSR = SCB_ICSR_PENDSVSET_Msk; + /* flush the pipeline. Otherwise we risk that subsequent instructions are + * executed before the IRQ has actually triggered */ + __ISB(); } void __attribute__((naked)) __attribute__((used)) isr_pendsv(void) {