IGtti
IGtti

Reputation: 59

STM32 FreeRTOS - Tasks with same priority running serial

I am starting on the FreeRTOS. During my first tests I found something not clear for me.

Created 4 tasks with the same priority (osPriorityNormal). All 4 tasks have the same code:

void StartDefaultTask(void *argument)
{
/* USER CODE BEGIN 5 */

    uint8_t DebugString[50];
    uint32_t ui32_SysTimer;

/* Infinite loop */
for(;;)
{
      ui32_SysTimer = xTaskGetTickCount();
      snprintf(DebugString, 30, "%10lu : DefaultTask\n", ui32_SysTimer);
      HAL_UART_Transmit(&huart2, DebugString, strlen(DebugString), 1000);
      vTaskDelay(500);
}
/* USER CODE END 5 */
}

Looking to the output data on the serial monitor, I was expecting to see all 4 tasks being called almost in parallel. Since the 500ms should not block the processing flow. But they are running in series!

Same priorities

Changing the priorities than I see the expected behavior.

Different priorities

Why they are not starting in parallel when using the same priority? Is the vTaskDelay() appropriate to give this minimum time to the task run again?

Thank you.

Upvotes: 1

Views: 690

Answers (1)

IGtti
IGtti

Reputation: 59

It seems the problem was in the output to the console. The HAL_UART_Transmit function is getting a busy status and losing some of the data. That is the reason for the serial timing sequency.

One possible solution is to store the data in a buffer and print it to the console only once, in a dedicated task.

Upvotes: 2

Related Questions