Showing results for 
Search instead for 
Did you mean: 

Blocking vs non-blocking UART using an RTOS


Hello there!

I've been setting up the UART peripheral on my STM32H5 and everything works great! However, there is one thing I can't completely understand:

Using an RTOS to call HAL_UART_Transmit or HAL_UART_Transmit_IT, what's the advantage of one over the other?

AFAIK, the blocking option will use more CPU cycles, and due to the preemptive nature of the RTOS I'm using (freeRTOS), it might take longer to execute in case there are higher priority tasks trying to run.

On the other hand, the HAL_UART_Transmit_IT might sound like a better option (since it is non-blocking) but it also introduces a (or several) ISR call(s), which will run over the RTOS.


On the STM FAQ about the UART peripheral, I noticed the HAL_UART_Transmit is only for low baud rates, why is that? Is due to its blocking nature?

Could anyone explain what would be the best approach here? I'm leaning towards the non-blocking option (and might even add the DMA peripheral) due to its non-blocking behaviour, even it adds a few more ISRs. 

Lead II

The advantage if non-blocking is clear - you don't spend the processor time waiting for data transfer in a polling loop. You may use the time to do some other useful stuff or put the processor to sleep. Of course you may use any version (polling, interrupt, DMA) for any baud rate.


Thanks for the quick reply!
Would that advantage also apply when the HAL function is called from an RTOS?

its same , with or without rtos.

If you feel a post has answered your question, please click "Accept as Solution".