cancel
Showing results for 
Search instead for 
Did you mean: 

I am doing UART communication with STM32H735G-DK. Without FreeRTOS, It works fine if you do it like this: HAL_UART_Transmit(&huart1, str, sizeof(str), 1000); However, there is no UART output in FreeRTOS.

moon1003
Associate III
 
9 REPLIES 9
moon1003
Associate III

The FreeRTOS environment is a project created by TouchGFX.

The setting of the UART part is the same regardless of FreeRTOS.

moon1003
Associate III

Even in the FreeRTOS environment, the HAL_UART_Transmit function is called normally and the value is put in the huart->Instance->TDR part.

 while (huart->TxXferCount > 0U)

  {

   if (UART_WaitOnFlagUntilTimeout(huart, UART_FLAG_TXE, RESET, tickstart, Timeout) != HAL_OK)

   {

    return HAL_TIMEOUT;

   }

   if (pdata8bits == NULL)

   {

    huart->Instance->TDR = (uint16_t)(*pdata16bits & 0x01FFU);

    pdata16bits++;

   }

   else

   {

    huart->Instance->TDR = (uint8_t)(*pdata8bits & 0xFFU);

    pdata8bits++;

   }

   huart->TxXferCount--;

  }

Make sure pins, clocks and peripheral are correctly initialized. ​

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

The port assignment was different.

thank you.

alister
Lead

Side comment...

HAL_UART_Transmit is blocking and the cycles it waits for the transmit to complete are totally wasted.

An RTOS app can use HAL_UART_Transmit_IT or HAL_UART_Transmit_DMA instead, and use those cycles for something else, and... that makes RTOS a game-changer.

Thank you. I'm trying to use the HAL_UART_Transmit_IT() and HAL_UART_Receive_IT(). Do you have any example or recommendation ?


@iPAS wrote:

Thank you. I'm trying to use the HAL_UART_Transmit_IT() and HAL_UART_Receive_IT(). Do you have any example or recommendation ?


Many hits for it on Google. Read their source code, experiment with sending, watch what happens using a debugger, a terminal and, if necessary and using short sends of known data, using a CRO, then experiment with receiving using loopback or a terminal.

Do you suggest that the rtos do not swich task while HAL calls wait in HAL_UART_Transmit or to that matter any hal calls? I was under the impression that once the scheduling is enabled, other task can function normally?


@Techn wrote:

Do you suggest that the rtos do not swich task while HAL calls wait in HAL_UART_Transmit or to that matter any hal calls? I was under the impression that once the scheduling is enabled, other task can function normally?


An RTOS may switch which task is executing by many different ways. It's not limited to the task executing some RTOS function to yield itself, and obviously it couldn't execute such an RTOS function while it's  executing HAL_UART_Transmit.

The HAL_UART_Transmit function is a blocking function. Its source code says so. Its source code shows you that it doesn't know anything about the RTOS, it starts the UART's transmit and then it loops polling the UART's transmit transmit status until either the transmit is completed or timed out. The HAL_UART_Transmit is not a sensible function to use if your code has anything else important to do.

Your code must transmit on a UART and you want to use an RTOS and HAL. My recommendation is

  1. use Google
  2. study your RTOS generally and its and embedded software's best practices
  3. study the source code of the HAL file containing the HAL_UART_Transmit function and weigh the options you find there
  4. do some experiments and
  5. decide what's sensible to you