aboutsummaryrefslogtreecommitdiff
path: root/stmhal/hal/src/stm32f4xx_hal.c
diff options
context:
space:
mode:
authorDamien George2014-03-14 00:29:51 +0000
committerDamien George2014-03-14 00:29:51 +0000
commitdeb413e8baf96a4638c73f26fbe4de99380abaf9 (patch)
tree411f696aa43aa55a68df5af05b3921370957fcb1 /stmhal/hal/src/stm32f4xx_hal.c
parent536dde254be99e19700a0934af38b913256475e3 (diff)
parent9db719bb57626d72ab84ab0ccd2294bf89158762 (diff)
Merge pull request #345 from dhylands/stmhal-systick-cleanup
stmhal - More systick cleanup. Fix HAL_Delay
Diffstat (limited to 'stmhal/hal/src/stm32f4xx_hal.c')
-rw-r--r--stmhal/hal/src/stm32f4xx_hal.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/stmhal/hal/src/stm32f4xx_hal.c b/stmhal/hal/src/stm32f4xx_hal.c
index 6df59f9f9..672422553 100644
--- a/stmhal/hal/src/stm32f4xx_hal.c
+++ b/stmhal/hal/src/stm32f4xx_hal.c
@@ -281,11 +281,13 @@ uint32_t HAL_GetTick(void)
*/
void HAL_Delay(__IO uint32_t Delay)
{
- uint32_t timingdelay;
-
- timingdelay = HAL_GetTick() + Delay;
- while(HAL_GetTick() < timingdelay)
- {
+ 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
}
}