Skip to content

Commit

Permalink
Set SysTick CLKSOURCE bit before enabling SysTick
Browse files Browse the repository at this point in the history
  • Loading branch information
jefftenney committed Apr 9, 2023
1 parent aa987a3 commit a4070ec
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions portable/ARMv8M/non_secure/port.c
Original file line number Diff line number Diff line change
Expand Up @@ -620,8 +620,12 @@ __attribute__( ( weak ) ) void vPortSetupTimerInterrupt( void ) /* PRIVILEGED_FU
}
#endif /* configUSE_TICKLESS_IDLE */

/* Stop and reset the SysTick. */
portNVIC_SYSTICK_CTRL_REG = 0UL;
/* Stop and reset the SysTick. Set the CLKSOURCE bit now while the SysTick
* is stopped to accommodate a bug in QEMU versions older than 7.0.0. The
* code that starts Systick (below) sets or clears the CLKSOURCE to match
* the build configuration, so this temporary setting of the CLKSOURCE bit
* has no impact on the actual operation of the SysTick. */
portNVIC_SYSTICK_CTRL_REG = portNVIC_SYSTICK_CLK_BIT;
portNVIC_SYSTICK_CURRENT_VALUE_REG = 0UL;

/* Configure SysTick to interrupt at the requested rate. */
Expand Down

1 comment on commit a4070ec

@jefftenney
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@paulbartell This change really is all that is required to address the old QEMU issue. Even with tickless idle enabled. No changes are required in vPortSuppressTicksAndSleep() because it never clears the CLKSOURCE bit (unless the build configuration indicates the CLKSOURCE bit should be clear). If we never clear the CLKSOURCE bit, we can't run into the QEMU issue.

The new code comment could use a little work though.

Please sign in to comment.