Merge pull request #4135 from balanceTWK/master_hal_delay

[BSP][STM32] update void HAL_Delay(__IO uint32_t Delay)
This commit is contained in:
Bernard Xiong 2020-12-30 08:09:49 +08:00 committed by GitHub
commit b2a6dbadf4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 7 deletions

View File

@ -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);
}
/**

View File

@ -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*/