Improved accuracy of common_hal_mcu_delay_us of STM port.
SysTick Current Value Register must be cleared before enabling.
This commit is contained in:
parent
e8f21f012c
commit
a0074c36d8
@ -41,13 +41,14 @@
|
|||||||
#include "supervisor/shared/safe_mode.h"
|
#include "supervisor/shared/safe_mode.h"
|
||||||
|
|
||||||
void common_hal_mcu_delay_us(uint32_t delay) {
|
void common_hal_mcu_delay_us(uint32_t delay) {
|
||||||
uint32_t ticks_per_us = HAL_RCC_GetSysClockFreq() / 1000000;
|
uint32_t ticks_per_us = HAL_RCC_GetSysClockFreq() / 1000000UL;
|
||||||
delay *= ticks_per_us;
|
delay *= ticks_per_us;
|
||||||
|
SysTick->VAL = 0UL;
|
||||||
SysTick->LOAD = delay;
|
SysTick->LOAD = delay;
|
||||||
SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_ENABLE_Msk;
|
SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_ENABLE_Msk;
|
||||||
while ((SysTick->CTRL & SysTick_CTRL_COUNTFLAG_Msk) == 0) {
|
while ((SysTick->CTRL & SysTick_CTRL_COUNTFLAG_Msk) == 0) {
|
||||||
}
|
}
|
||||||
SysTick->CTRL = 0;
|
SysTick->CTRL = 0UL;
|
||||||
}
|
}
|
||||||
|
|
||||||
volatile uint32_t nesting_count = 0;
|
volatile uint32_t nesting_count = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user