diff options
author | Krzysztof Blazewicz <krzysztof.blazewicz@uxeon.com> | 2016-09-08 18:13:22 +0200 |
---|---|---|
committer | Krzysztof Blazewicz <krzysztof.blazewicz@uxeon.com> | 2016-11-16 12:43:27 +0100 |
commit | 4f7c5fa64769f836b1cb3d357be4864807e10694 (patch) | |
tree | 7a84fecf02e106c33ee2b7622c40bcb410f380bb | |
parent | c79ff9930aed2a91a888f8eb58f27946ca8287ca (diff) | |
download | micropython-4f7c5fa64769f836b1cb3d357be4864807e10694.tar.gz micropython-4f7c5fa64769f836b1cb3d357be4864807e10694.zip |
stmhal/hal: reapply HAL commit 9db719b for f4
-rw-r--r-- | stmhal/hal/f4/src/stm32f4xx_hal.c | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/stmhal/hal/f4/src/stm32f4xx_hal.c b/stmhal/hal/f4/src/stm32f4xx_hal.c index d388dbf1c2..c0965368ed 100644 --- a/stmhal/hal/f4/src/stm32f4xx_hal.c +++ b/stmhal/hal/f4/src/stm32f4xx_hal.c @@ -337,11 +337,14 @@ __weak uint32_t HAL_GetTick(void) */
__weak void HAL_Delay(__IO uint32_t Delay)
{
- uint32_t tickstart = 0U;
- tickstart = HAL_GetTick();
- while((HAL_GetTick() - tickstart) < Delay)
- {
- }
+ uint32_t start = HAL_GetTick();
+
+ // Note that the following works (due to the magic of 2's complement numbers)
+ // even when Delay causes wraparound.
+
+ while (HAL_GetTick() - start <= Delay) {
+ __WFI(); // enter sleep mode, waiting for interrupt
+ }
}
/**
|