Skip to content

Commit b3c4f3b

Browse files
authored
Merge pull request #2227 from ylz0923/patch-2
Update board.c
2 parents 7aede1b + a5a4c6a commit b3c4f3b

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

bsp/stm32f10x-HAL/drivers/board.c

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -186,15 +186,12 @@ void rt_hw_board_init(void)
186186
*/
187187
void rt_hw_us_delay(rt_uint32_t us)
188188
{
189-
rt_uint32_t delta;
190-
us = us * (SysTick->LOAD / (1000000 / RT_TICK_PER_SECOND));
191-
delta = SysTick->VAL;
192-
if (delta < us)
193-
{
194-
/* wait current OSTick left time gone */
195-
while (SysTick->VAL < us);
196-
us -= delta;
197-
delta = SysTick->LOAD;
198-
}
199-
while (delta - SysTick->VAL < us);
189+
unsigned int start, now, delta, reload, us_tick;
190+
start = SysTick->VAL;
191+
reload = SysTick->LOAD;
192+
us_tick = SystemCoreClock / 1000000UL;
193+
do{
194+
now = SysTick->VAL;
195+
delta = start > now ? start - now : reload + start - now;
196+
} while(delta < us_tick * us);
200197
}

0 commit comments

Comments
 (0)