From 236318332b84496f69feef9080bd1b0145be6c82 Mon Sep 17 00:00:00 2001 From: Grant Ramsay Date: Wed, 4 Oct 2023 10:08:42 +1300 Subject: [PATCH] drivers: systick: Fix Cortex-M SysTick dropping 1 cycle per tick `last_load` is the full N cycles and `SysTick->LOAD` should be loaded with `last_load - 1` for the calculations work correctly. Note: This only affects a kernel in ticked operation. Tickless kernels periodically restart the timer correctly. Signed-off-by: Grant Ramsay --- drivers/timer/cortex_m_systick.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/timer/cortex_m_systick.c b/drivers/timer/cortex_m_systick.c index ff4414c5619..e026c3603c6 100644 --- a/drivers/timer/cortex_m_systick.c +++ b/drivers/timer/cortex_m_systick.c @@ -314,9 +314,9 @@ static int sys_clock_driver_init(void) { NVIC_SetPriority(SysTick_IRQn, _IRQ_PRIO_OFFSET); - last_load = CYC_PER_TICK - 1; + last_load = CYC_PER_TICK; overflow_cyc = 0U; - SysTick->LOAD = last_load; + SysTick->LOAD = last_load - 1; SysTick->VAL = 0; /* resets timer to last_load */ SysTick->CTRL |= (SysTick_CTRL_ENABLE_Msk | SysTick_CTRL_TICKINT_Msk |