diff options
| author | cyz <[email protected]> | 2021-06-09 12:35:52 +0800 |
|---|---|---|
| committer | cyz <[email protected]> | 2021-06-09 12:35:52 +0800 |
| commit | 796c8affdd0b16c5286ed8b01a4871736ae719c8 (patch) | |
| tree | abb0d68d34e5987580d0f49f6ae2de29462ef0fe /bsp/stm32 | |
| parent | 2961b37104443b9f63bbd5a6b5b8d84c7797d2c6 (diff) | |
rt_hw_us_delay的实现有问题,针对这一问题进行了修改
Diffstat (limited to 'bsp/stm32')
| -rw-r--r-- | bsp/stm32/libraries/HAL_Drivers/drv_common.c | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/bsp/stm32/libraries/HAL_Drivers/drv_common.c b/bsp/stm32/libraries/HAL_Drivers/drv_common.c index 74007b6e88..61171e7c8d 100644 --- a/bsp/stm32/libraries/HAL_Drivers/drv_common.c +++ b/bsp/stm32/libraries/HAL_Drivers/drv_common.c @@ -113,16 +113,32 @@ void _Error_Handler(char *s, int num) */ void rt_hw_us_delay(rt_uint32_t us) { - rt_uint32_t start, now, delta, reload, us_tick; - start = SysTick->VAL; - reload = SysTick->LOAD; - us_tick = SystemCoreClock / 1000000UL; - do + rt_uint32_t ticks; + rt_uint32_t told, tnow, tcnt = 0; + rt_uint32_t reload = SysTick->LOAD; + + ticks = us * reload / (1000000 / RT_TICK_PER_SECOND); + told = SysTick->VAL; + while (1) { - now = SysTick->VAL; - delta = start >= now ? start - now : reload + start - now; + tnow = SysTick->VAL; + if (tnow != told) + { + if (tnow < told) + { + tcnt += told - tnow; + } + else + { + tcnt += reload - tnow + told; + } + told = tnow; + if (tcnt >= ticks) + { + break; + } + } } - while (delta < us_tick * us); } /** |
