8000 Merge pull request #5553 from EmergReanimator/stm · tannewt/circuitpython@e5c7ff7 · GitHub
[go: up one dir, main page]

Skip to content

Commit e5c7ff7

Browse files
authored
Merge pull request micropython#5553 from EmergReanimator/stm
Improved accuracy of common_hal_mcu_delay_us of STM port.
2 parents 5572876 + 94866fc commit e5c7ff7

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)
0