From 36365e38ba3f2cfb810235e4b1b2f7145c813cfd Mon Sep 17 00:00:00 2001 From: Adithya Baglody Date: Fri, 20 Apr 2018 11:44:23 +0530 Subject: [PATCH] drivers: timers: systick: Enforce a barrier in _timer_cycle_get_32. The code assumes that when the systick counter hits zero, the timer interrupt will be taken before the loop can read the LOAD/VAL registers, but this is not architecturally guaranteed, and so the code can see a post-reload SysTick->VAL and a pre-reload clock_accumulated_count, which causes it to return an incorrectly small cycle count. By adding a ISB we overcome this issue. Signed-off-by: Adithya Baglody --- drivers/timer/cortex_m_systick.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/timer/cortex_m_systick.c b/drivers/timer/cortex_m_systick.c index 14c3a38b0b2..7f709500e99 100644 --- a/drivers/timer/cortex_m_systick.c +++ b/drivers/timer/cortex_m_systick.c @@ -772,6 +772,7 @@ return (u32_t) get_elapsed_count(); #else count = SysTick->LOAD - SysTick->VAL; #endif + __ISB(); } while (cac != clock_accumulated_count); return cac + count;