Skip to content

Commit 4f7c5fa

Browse files
author
Krzysztof Blazewicz
committed
stmhal/hal: reapply HAL commit 9db719b for f4
1 parent c79ff99 commit 4f7c5fa

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

stmhal/hal/f4/src/stm32f4xx_hal.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -337,11 +337,14 @@ __weak uint32_t HAL_GetTick(void)
337337
*/
338338
__weak void HAL_Delay(__IO uint32_t Delay)
339339
{
340-
uint32_t tickstart = 0U;
341-
tickstart = HAL_GetTick();
342-
while((HAL_GetTick() - tickstart) < Delay)
343-
{
344-
}
340+
uint32_t start = HAL_GetTick();
341+
342+
// Note that the following works (due to the magic of 2's complement numbers)
343+
// even when Delay causes wraparound.
344+
345+
while (HAL_GetTick() - start <= Delay) {
346+
__WFI(); // enter sleep mode, waiting for interrupt
347+
}
345348
}
346349

347350
/**

0 commit comments

Comments
 (0)