summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBernard Xiong <[email protected]>2019-03-06 01:13:06 +0800
committerGitHub <[email protected]>2019-03-06 01:13:06 +0800
commit85a0aaa3c2dc2f563ca25a91a00c033eddbb78d2 (patch)
treed63db61b41166e48b6d95b8c61ca576b10efbbee
parent6008be4055d5b4bab7da2735d12fcd7fa1bff031 (diff)
parentf4e74ccd18255442c269b25a501a7629cdde7b75 (diff)
Merge pull request #2381 from Guozhanxin/hw_us
[bsp][stm32] add rt_hw_us_delay
-rw-r--r--bsp/stm32/libraries/HAL_Drivers/drv_common.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/bsp/stm32/libraries/HAL_Drivers/drv_common.c b/bsp/stm32/libraries/HAL_Drivers/drv_common.c
index e267b94b24..350c3fab40 100644
--- a/bsp/stm32/libraries/HAL_Drivers/drv_common.c
+++ b/bsp/stm32/libraries/HAL_Drivers/drv_common.c
@@ -87,6 +87,41 @@ void _Error_Handler(char *s, int num)
}
/**
+ * 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.
*/
RT_WEAK void rt_hw_board_init()