Merge pull request #1520 from ylz0923/master

[stm32f10x-HAL] add function rt_hw_us_delay
This commit is contained in:
ZYH 2018-06-12 20:36:29 +08:00 committed by GitHub
commit 39de7a3271
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 20 additions and 0 deletions

View File

@ -113,3 +113,23 @@ void rt_hw_board_init(void)
rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
#endif
}
/**
* 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 delta;
us = us * (SysTick->LOAD / (1000000 / RT_TICK_PER_SECOND));
delta = SysTick->VAL;
if (delta < us)
{
/* wait current OSTick left time gone */
while (SysTick->VAL < us);
us -= delta;
delta = SysTick->LOAD;
}
while (delta - SysTick->VAL < us);
}