1 parent c79ff99 commit 4f7c5faCopy full SHA for 4f7c5fa
1 file changed
stmhal/hal/f4/src/stm32f4xx_hal.c
@@ -337,11 +337,14 @@ __weak uint32_t HAL_GetTick(void)
337
*/
338
__weak void HAL_Delay(__IO uint32_t Delay)
339
{
340
- uint32_t tickstart = 0U;
341
- tickstart = HAL_GetTick();
342
- while((HAL_GetTick() - tickstart) < Delay)
343
- {
344
- }
+ uint32_t start = HAL_GetTick();
+
+ // Note that the following works (due to the magic of 2's complement numbers)
+ // even when Delay causes wraparound.
345
+ while (HAL_GetTick() - start <= Delay) {
346
+ __WFI(); // enter sleep mode, waiting for interrupt
347
+ }
348
}
349
350
/**
0 commit comments