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 <gramsay@enphaseenergy.com>
This commit is contained in:
parent
1951d83783
commit
236318332b
|
@ -314,9 +314,9 @@ static int sys_clock_driver_init(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
NVIC_SetPriority(SysTick_IRQn, _IRQ_PRIO_OFFSET);
|
NVIC_SetPriority(SysTick_IRQn, _IRQ_PRIO_OFFSET);
|
||||||
last_load = CYC_PER_TICK - 1;
|
last_load = CYC_PER_TICK;
|
||||||
overflow_cyc = 0U;
|
overflow_cyc = 0U;
|
||||||
SysTick->LOAD = last_load;
|
SysTick->LOAD = last_load - 1;
|
||||||
SysTick->VAL = 0; /* resets timer to last_load */
|
SysTick->VAL = 0; /* resets timer to last_load */
|
||||||
SysTick->CTRL |= (SysTick_CTRL_ENABLE_Msk |
|
SysTick->CTRL |= (SysTick_CTRL_ENABLE_Msk |
|
||||||
SysTick_CTRL_TICKINT_Msk |
|
SysTick_CTRL_TICKINT_Msk |
|
||||||
|
|
Loading…
Reference in a new issue