We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 9a229a1 commit 2fa0645Copy full SHA for 2fa0645
cores/arduino/stm32/clock.c
@@ -98,13 +98,22 @@
98
*/
99
100
/**
101
- * @brief Function called wto read the current micro second
+ * @brief Function called to read the current micro second
102
* @param None
103
* @retval None
104
105
uint32_t GetCurrentMicro(void)
106
{
107
- return (HAL_GetTick()*1000) + ((SystemCoreClock/1000-SysTick->VAL)/(SystemCoreClock/1000000));
+ uint32_t m0 = HAL_GetTick();
108
+ uint32_t u0 = SysTick->LOAD - SysTick->VAL;
109
+ uint32_t m1 = HAL_GetTick();
110
+ uint32_t u1 = SysTick->LOAD - SysTick->VAL;
111
+
112
+ if (m1 > m0) {
113
+ return ( m1 * 1000 + (u1 * 1000) / SysTick->LOAD);
114
+ } else {
115
+ return ( m0 * 1000 + (u0 * 1000) / SysTick->LOAD);
116
+ }
117
}
118
119
0 commit comments