FreeRTOS: osDelay vs HAL_delay

When creating a FreeRTOS application project with STM32CubeMx, there are two ways you can use to introduce a delay, namely osDelay and HAL_Delay .

What is the difference between them and which one is preferable?

osDelay Code:

/*********************** Generic Wait Functions *******************************/
/**
* @brief   Wait for Timeout (Time Delay)
* @param   millisec      time delay value
* @retval  status code that indicates the execution status of the function.
*/
osStatus osDelay (uint32_t millisec)
{
#if INCLUDE_vTaskDelay
  TickType_t ticks = millisec / portTICK_PERIOD_MS;

  vTaskDelay(ticks ? ticks : 1);          /* Minimum delay = 1 tick */

  return osOK;
#else
  (void) millisec;

  return osErrorResource;
#endif
}

HAL_Delay Code:

/**
* @brief This function provides accurate delay (in milliseconds) based 
*        on variable incremented.
* @note In the default implementation , SysTick timer is the source of time base.
*       It is used to generate interrupts at regular time intervals where uwTick
*       is incremented.
* @note ThiS function is declared as __weak to be overwritten in case of other
*       implementations in user file.
* @param Delay: specifies the delay time length, in milliseconds.
* @retval None
*/
__weak void HAL_Delay(__IO uint32_t Delay)
{
  uint32_t tickstart = 0;
  tickstart = HAL_GetTick();
  while((HAL_GetTick() - tickstart) < Delay)
  {
  }
}
+4
source share
3 answers

HAL_Delay FreeRTOS _osDelay - , FreeRTOS strong > . (acc @Clifford:) .

osDelay CMSIS vTaskDelay() , , osDelay - , _vTaskDelay() - Ticks . ( @Bence Kaulics:) , OS , .

HAL_Delay . , . ( @Bence Kaulics:) , OS . , , HAL_Delay , HAL. (acc. @Clifford:) HAL FreeRTOS ( FreeRTOS )

Delay FreeRTOS, vTaskDelay() vTaskDelayUntil() .

(acc. @Clifford:)
FreeRTOS API functino, , .
CubeMX - .

+7

. HAL_Delay , , , , , while . .

vTaskDelay , , , , , , , prio .

+3

, HAL_Delay() RTOS, NULL. HAL_Delay() RTOS, . , - . , .

osDelay (), on the other hand, affects latency using RTOS. He tells RTOS that he has nothing to do before the expiration of the delay period, so RTOS does not set a processing time for the task during this period. This saves processing time, potentially saves energy and allows tasks with lower priority to receive processing time during the delay period. http://www.freertos.org/FAQWhat.html#WhyUseRTOS

+1
source

Source: https://habr.com/ru/post/1669936/


All Articles