diff --git a/drivers/timer/cortex_m_systick.c b/drivers/timer/cortex_m_systick.c index 450cdac6b75..ba4b96b5d07 100644 --- a/drivers/timer/cortex_m_systick.c +++ b/drivers/timer/cortex_m_systick.c @@ -28,7 +28,7 @@ #include /* running total of timer count */ -static uint32_t clock_accumulated_count; +static volatile uint32_t clock_accumulated_count; /* * A board support package's board.h header must provide definitions for the @@ -559,7 +559,14 @@ int _sys_clock_driver_init(struct device *device) */ uint32_t _timer_cycle_get_32(void) { - return clock_accumulated_count + (SysTick->LOAD - SysTick->VAL); + uint32_t cac, count; + + do { + cac = clock_accumulated_count; + count = SysTick->LOAD - SysTick->VAL; + } while (cac != clock_accumulated_count); + + return cac + count; } #ifdef CONFIG_SYSTEM_CLOCK_DISABLE