summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bsp/stm32/libraries/HAL_Drivers/drv_common.c24
-rw-r--r--src/scheduler.c2
2 files changed, 19 insertions, 7 deletions
diff --git a/bsp/stm32/libraries/HAL_Drivers/drv_common.c b/bsp/stm32/libraries/HAL_Drivers/drv_common.c
index f150d81fef..bf7ed20e94 100644
--- a/bsp/stm32/libraries/HAL_Drivers/drv_common.c
+++ b/bsp/stm32/libraries/HAL_Drivers/drv_common.c
@@ -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);
}
/**
diff --git a/src/scheduler.c b/src/scheduler.c
index 677be6cff7..06f305ea0b 100644
--- a/src/scheduler.c
+++ b/src/scheduler.c
@@ -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*/