Skip to content

Commit b2a6dba

Browse files
authored
Merge pull request #4135 from balanceTWK/master_hal_delay
[BSP][STM32] update void HAL_Delay(__IO uint32_t Delay)
2 parents ce034e6 + f91089b commit b2a6dba

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

bsp/stm32/libraries/HAL_Drivers/drv_common.c

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ void rt_hw_systick_init(void)
3030
#if defined (SOC_SERIES_STM32H7)
3131
HAL_SYSTICK_Config((HAL_RCCEx_GetD1SysClockFreq()) / RT_TICK_PER_SECOND);
3232
#elif defined (SOC_SERIES_STM32MP1)
33-
HAL_SYSTICK_Config(HAL_RCC_GetSystemCoreClockFreq() / RT_TICK_PER_SECOND);
33+
HAL_SYSTICK_Config(HAL_RCC_GetSystemCoreClockFreq() / RT_TICK_PER_SECOND);
3434
#else
3535
HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq() / RT_TICK_PER_SECOND);
3636
#endif
@@ -71,7 +71,17 @@ void HAL_ResumeTick(void)
7171

7272
void HAL_Delay(__IO uint32_t Delay)
7373
{
74-
rt_thread_mdelay(Delay);
74+
if (rt_thread_self())
75+
{
76+
rt_thread_mdelay(Delay);
77+
}
78+
else
79+
{
80+
for (rt_uint32_t count = 0; count < Delay; count++)
81+
{
82+
rt_hw_us_delay(1000);
83+
}
84+
}
7585
}
7686

7787
/* re-implement tick interface for STM32 HAL */
@@ -90,7 +100,7 @@ void _Error_Handler(char *s, int num)
90100
{
91101
/* USER CODE BEGIN Error_Handler */
92102
/* User can add his own implementation to report the HAL error return state */
93-
while(1)
103+
while (1)
94104
{
95105
}
96106
/* USER CODE END Error_Handler */
@@ -107,10 +117,12 @@ void rt_hw_us_delay(rt_uint32_t us)
107117
start = SysTick->VAL;
108118
reload = SysTick->LOAD;
109119
us_tick = SystemCoreClock / 1000000UL;
110-
do {
120+
do
121+
{
111122
now = SysTick->VAL;
112-
delta = start > now ? start - now : reload + start - now;
113-
} while(delta < us_tick * us);
123+
delta = start >= now ? start - now : reload + start - now;
124+
}
125+
while (delta < us_tick * us);
114126
}
115127

116128
/**

src/scheduler.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ rt_uint8_t rt_thread_ready_table[32];
4343
#ifndef RT_USING_SMP
4444
extern volatile rt_uint8_t rt_interrupt_nest;
4545
static rt_int16_t rt_scheduler_lock_nest;
46-
struct rt_thread *rt_current_thread;
46+
struct rt_thread *rt_current_thread = RT_NULL;
4747
rt_uint8_t rt_current_priority;
4848
#endif /*RT_USING_SMP*/
4949

0 commit comments

Comments
 (0)