We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 1e9303c commit 15dc04bCopy full SHA for 15dc04b
cores/arduino/stm32/clock.c
@@ -48,16 +48,15 @@
48
*/
49
uint32_t GetCurrentMicro(void)
50
{
51
- uint32_t m0 = HAL_GetTick();
52
- uint32_t u0 = SysTick->LOAD - SysTick->VAL;
53
- uint32_t m1 = HAL_GetTick();
54
- uint32_t u1 = SysTick->LOAD - SysTick->VAL;
55
-
56
- if (m1 > m0) {
57
- return ( m1 * 1000 + (u1 * 1000) / SysTick->LOAD);
58
- } else {
59
- return ( m0 * 1000 + (u0 * 1000) / SysTick->LOAD);
+ /* Ensure COUNTFLAG is reset by reading SysTick control and status register */
+ LL_SYSTICK_IsActiveCounterFlag();
+ uint32_t m = HAL_GetTick();
+ uint32_t u = SysTick->LOAD - SysTick->VAL;
+ if(LL_SYSTICK_IsActiveCounterFlag()) {
+ m = HAL_GetTick();
+ u = SysTick->LOAD - SysTick->VAL;
60
}
+ return ( m * 1000 + (u * 1000) / SysTick->LOAD);
61
62
63
/**
0 commit comments