Skip to content

Commit a0074c3

Browse files
Improved accuracy of common_hal_mcu_delay_us of STM port.
SysTick Current Value Register must be cleared before enabling.
1 parent e8f21f0 commit a0074c3

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

ports/stm/common-hal/microcontroller/__init__.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,14 @@
4141
#include "supervisor/shared/safe_mode.h"
4242

4343
void common_hal_mcu_delay_us(uint32_t delay) {
44-
uint32_t ticks_per_us = HAL_RCC_GetSysClockFreq() / 1000000;
44+
uint32_t ticks_per_us = HAL_RCC_GetSysClockFreq() / 1000000UL;
4545
delay *= ticks_per_us;
46+
SysTick->VAL = 0UL;
4647
SysTick->LOAD = delay;
4748
SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_ENABLE_Msk;
4849
while ((SysTick->CTRL & SysTick_CTRL_COUNTFLAG_Msk) == 0) {
4950
}
50-
SysTick->CTRL = 0;
51+
SysTick->CTRL = 0UL;
5152
}
5253

5354
volatile uint32_t nesting_count = 0;

0 commit comments

Comments
 (0)