summaryrefslogtreecommitdiff
path: root/bsp/stm32
diff options
context:
space:
mode:
authorrtthread-bot <[email protected]>2021-06-16 09:32:46 +0000
committerrtthread-bot <[email protected]>2021-06-16 09:32:46 +0000
commit1e7dfa694f15d645bdad1f8e7bebe669df3a3542 (patch)
tree98f21a3a4d5c80becb31167627874e634c7b5fb8 /bsp/stm32
parentc3afd9cc2363bb7ac26d28a0bf5f8f70cf0ee2dd (diff)
parent45b540d33409ff4c26fcbe7929fd782a534fb1fc (diff)
Merge remote-tracking branch 'rtt_gitee/gitee_master'
Diffstat (limited to 'bsp/stm32')
-rw-r--r--bsp/stm32/libraries/HAL_Drivers/drv_common.c32
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);
}
/**