summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorguozhanxin <[email protected]>2019-03-05 18:22:28 +0800
committerguozhanxin <[email protected]>2019-03-05 18:23:22 +0800
commitf4e74ccd18255442c269b25a501a7629cdde7b75 (patch)
treefdc6635d316caec714347647aa3ea427939b0dc7
parentaa7166df01a06b4ba16add3a601d54470dbb2938 (diff)
[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()