Skip to content

Commit 3907739

Browse files
committed
fix: make micros compatible with ISR
It is kind of revert commit 15dc04b. Note: `delayMicroseconds()` does not rely anymore on `micros()` so accuracy is less important. Fixes #1680 Signed-off-by: Frederic Pillon <[email protected]>
1 parent df9253c commit 3907739

File tree

1 file changed

+9
-8
lines changed
  • libraries/SrcWrapper/src/stm32

1 file changed

+9
-8
lines changed

Diff for: libraries/SrcWrapper/src/stm32/clock.c

+9-8
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,17 @@ extern "C" {
2828
*/
2929
uint32_t getCurrentMicros(void)
3030
{
31-
/* Ensure COUNTFLAG is reset by reading SysTick control and status register */
32-
LL_SYSTICK_IsActiveCounterFlag();
33-
uint32_t m = HAL_GetTick();
31+
uint32_t m0 = HAL_GetTick();
32+
__IO uint32_t u0 = SysTick->VAL;
33+
uint32_t m1 = HAL_GetTick();
34+
__IO uint32_t u1 = SysTick->VAL;
3435
const uint32_t tms = SysTick->LOAD + 1;
35-
__IO uint32_t u = tms - SysTick->VAL;
36-
if (LL_SYSTICK_IsActiveCounterFlag()) {
37-
m = HAL_GetTick();
38-
u = tms - SysTick->VAL;
36+
37+
if (m1 != m0) {
38+
return (m1 * 1000 + ((tms - u1) * 1000) / tms);
39+
} else {
40+
return (m0 * 1000 + ((tms - u0) * 1000) / tms);
3941
}
40-
return (m * 1000 + (u * 1000) / tms);
4142
}
4243

4344
/**

0 commit comments

Comments
 (0)