summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBernard Xiong <[email protected]>2021-10-13 15:39:42 +0800
committerGitHub <[email protected]>2021-10-13 15:39:42 +0800
commite7f4a1177ae2dff7884e0e59dd082cef73d9b65f (patch)
tree51e670774fbd464f249acb4f9593531f4b771cd2
parent577bd1cc7c2b91e47ef0680020ee5f1c2b5260a3 (diff)
parentceef6543ee86eee1fa5d00902a2a25566c6b0b9c (diff)
Merge pull request #5148 from loogg/mlw-fx
fix the tick of drv_common.c in stm32 bsp
-rw-r--r--bsp/stm32/libraries/HAL_Drivers/drv_common.c41
1 files changed, 23 insertions, 18 deletions
diff --git a/bsp/stm32/libraries/HAL_Drivers/drv_common.c b/bsp/stm32/libraries/HAL_Drivers/drv_common.c
index 6cd9130a4a..81983b36cd 100644
--- a/bsp/stm32/libraries/HAL_Drivers/drv_common.c
+++ b/bsp/stm32/libraries/HAL_Drivers/drv_common.c
@@ -28,20 +28,19 @@ static void reboot(uint8_t argc, char **argv)
MSH_CMD_EXPORT(reboot, Reboot System);
#endif /* RT_USING_FINSH */
+extern __IO uint32_t uwTick;
+static uint32_t _systick_ms = 1;
+
/* SysTick configuration */
void rt_hw_systick_init(void)
{
-#if defined (SOC_SERIES_STM32H7)
- HAL_SYSTICK_Config((HAL_RCCEx_GetD1SysClockFreq()) / RT_TICK_PER_SECOND);
-#elif defined (SOC_SERIES_STM32MP1)
- HAL_SYSTICK_Config(HAL_RCC_GetSystemCoreClockFreq() / RT_TICK_PER_SECOND);
-#else
- HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq() / RT_TICK_PER_SECOND);
-#endif
-#if !defined (SOC_SERIES_STM32MP1)
- HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
-#endif
+ HAL_SYSTICK_Config(SystemCoreClock / RT_TICK_PER_SECOND);
+
NVIC_SetPriority(SysTick_IRQn, 0xFF);
+
+ _systick_ms = 1000u / RT_TICK_PER_SECOND;
+ if(_systick_ms == 0)
+ _systick_ms = 1;
}
/**
@@ -53,7 +52,9 @@ void SysTick_Handler(void)
/* enter interrupt */
rt_interrupt_enter();
- HAL_IncTick();
+ if(SysTick->CTRL & SysTick_CTRL_COUNTFLAG_Msk)
+ HAL_IncTick();
+
rt_tick_increase();
/* leave interrupt */
@@ -62,7 +63,15 @@ void SysTick_Handler(void)
uint32_t HAL_GetTick(void)
{
- return rt_tick_get_millisecond();
+ if(SysTick->CTRL & SysTick_CTRL_COUNTFLAG_Msk)
+ HAL_IncTick();
+
+ return uwTick;
+}
+
+void HAL_IncTick(void)
+{
+ uwTick += _systick_ms;
}
void HAL_SuspendTick(void)
@@ -91,6 +100,8 @@ void HAL_Delay(__IO uint32_t Delay)
/* re-implement tick interface for STM32 HAL */
HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
{
+ rt_hw_systick_init();
+
/* Return function status */
return HAL_OK;
}
@@ -163,14 +174,8 @@ RT_WEAK void rt_hw_board_init()
/* HAL_Init() function is called at the beginning of the program */
HAL_Init();
- /* enable interrupt */
- __set_PRIMASK(0);
/* System clock initialization */
SystemClock_Config();
- /* disable interrupt */
- __set_PRIMASK(1);
-
- rt_hw_systick_init();
/* Heap initialization */
#if defined(RT_USING_HEAP)