未验证 提交 b2a6dbad 编写于 作者: B Bernard Xiong 提交者: GitHub

Merge pull request #4135 from balanceTWK/master_hal_delay

[BSP][STM32] update void HAL_Delay(__IO uint32_t Delay)
......@@ -30,7 +30,7 @@ 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);
HAL_SYSTICK_Config(HAL_RCC_GetSystemCoreClockFreq() / RT_TICK_PER_SECOND);
#else
HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq() / RT_TICK_PER_SECOND);
#endif
......@@ -71,7 +71,17 @@ void HAL_ResumeTick(void)
void HAL_Delay(__IO uint32_t Delay)
{
rt_thread_mdelay(Delay);
if (rt_thread_self())
{
rt_thread_mdelay(Delay);
}
else
{
for (rt_uint32_t count = 0; count < Delay; count++)
{
rt_hw_us_delay(1000);
}
}
}
/* re-implement tick interface for STM32 HAL */
......@@ -90,7 +100,7 @@ void _Error_Handler(char *s, int num)
{
/* USER CODE BEGIN Error_Handler */
/* User can add his own implementation to report the HAL error return state */
while(1)
while (1)
{
}
/* USER CODE END Error_Handler */
......@@ -107,10 +117,12 @@ void rt_hw_us_delay(rt_uint32_t us)
start = SysTick->VAL;
reload = SysTick->LOAD;
us_tick = SystemCoreClock / 1000000UL;
do {
do
{
now = SysTick->VAL;
delta = start > now ? start - now : reload + start - now;
} while(delta < us_tick * us);
delta = start >= now ? start - now : reload + start - now;
}
while (delta < us_tick * us);
}
/**
......
......@@ -43,7 +43,7 @@ rt_uint8_t rt_thread_ready_table[32];
#ifndef RT_USING_SMP
extern volatile rt_uint8_t rt_interrupt_nest;
static rt_int16_t rt_scheduler_lock_nest;
struct rt_thread *rt_current_thread;
struct rt_thread *rt_current_thread = RT_NULL;
rt_uint8_t rt_current_priority;
#endif /*RT_USING_SMP*/
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册