4
0
mirror of https://github.com/RT-Thread/rt-thread.git synced 2025-02-21 05:17:10 +08:00

[bsp][stm32] add rt_hw_us_delay

This commit is contained in:
guozhanxin 2019-03-05 18:22:28 +08:00
parent aa7166df01
commit f4e74ccd18

View File

@ -86,6 +86,41 @@ void _Error_Handler(char *s, int num)
/* USER CODE END Error_Handler */
}
/**
* This function will delay for some us.
*
* @param us the delay time of us
*/
void rt_hw_us_delay(rt_uint32_t us)
{
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)
{
tnow = SysTick->VAL;
if (tnow != told)
{
if (tnow < told)
{
tcnt += told - tnow;
}
else
{
tcnt += reload - tnow + told;
}
told = tnow;
if (tcnt >= ticks)
{
break;
}
}
}
}
/**
* This function will initial STM32 board.
*/