Skip to content

Commit 88133da

Browse files
committed
fix the tick of drv_common.c in stm32 bsp
1 parent 277bb73 commit 88133da

File tree

1 file changed

+23
-18
lines changed

1 file changed

+23
-18
lines changed

bsp/stm32/libraries/HAL_Drivers/drv_common.c

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,19 @@ static void reboot(uint8_t argc, char **argv)
2828
MSH_CMD_EXPORT(reboot, Reboot System);
2929
#endif /* RT_USING_FINSH */
3030

31+
extern __IO uint32_t uwTick;
32+
static uint32_t sysTickMillisecond = 1;
33+
3134
/* SysTick configuration */
3235
void rt_hw_systick_init(void)
3336
{
34-
#if defined (SOC_SERIES_STM32H7)
35-
HAL_SYSTICK_Config((HAL_RCCEx_GetD1SysClockFreq()) / RT_TICK_PER_SECOND);
36-
#elif defined (SOC_SERIES_STM32MP1)
37-
HAL_SYSTICK_Config(HAL_RCC_GetSystemCoreClockFreq() / RT_TICK_PER_SECOND);
38-
#else
39-
HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq() / RT_TICK_PER_SECOND);
40-
#endif
41-
#if !defined (SOC_SERIES_STM32MP1)
42-
HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
43-
#endif
37+
HAL_SYSTICK_Config(SystemCoreClock / RT_TICK_PER_SECOND);
38+
4439
NVIC_SetPriority(SysTick_IRQn, 0xFF);
40+
41+
sysTickMillisecond = 1000u / RT_TICK_PER_SECOND;
42+
if(sysTickMillisecond == 0)
43+
sysTickMillisecond = 1;
4544
}
4645

4746
/**
@@ -53,7 +52,9 @@ void SysTick_Handler(void)
5352
/* enter interrupt */
5453
rt_interrupt_enter();
5554

56-
HAL_IncTick();
55+
if(SysTick->CTRL & SysTick_CTRL_COUNTFLAG_Msk)
56+
HAL_IncTick();
57+
5758
rt_tick_increase();
5859

5960
/* leave interrupt */
@@ -62,7 +63,15 @@ void SysTick_Handler(void)
6263

6364
uint32_t HAL_GetTick(void)
6465
{
65-
return rt_tick_get_millisecond();
66+
if(SysTick->CTRL & SysTick_CTRL_COUNTFLAG_Msk)
67+
HAL_IncTick();
68+
69+
return uwTick;
70+
}
71+
72+
void HAL_IncTick(void)
73+
{
74+
uwTick += sysTickMillisecond;
6675
}
6776

6877
void HAL_SuspendTick(void)
@@ -91,6 +100,8 @@ void HAL_Delay(__IO uint32_t Delay)
91100
/* re-implement tick interface for STM32 HAL */
92101
HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
93102
{
103+
rt_hw_systick_init();
104+
94105
/* Return function status */
95106
return HAL_OK;
96107
}
@@ -163,14 +174,8 @@ RT_WEAK void rt_hw_board_init()
163174
/* HAL_Init() function is called at the beginning of the program */
164175
HAL_Init();
165176

166-
/* enable interrupt */
167-
__set_PRIMASK(0);
168177
/* System clock initialization */
169178
SystemClock_Config();
170-
/* disable interrupt */
171-
__set_PRIMASK(1);
172-
173-
rt_hw_systick_init();
174179

175180
/* Heap initialization */
176181
#if defined(RT_USING_HEAP)

0 commit comments

Comments
 (0)