Skip to main content
Associate II
October 20, 2023
Solved

Blocking vs non-blocking UART using an RTOS

  • October 20, 2023
  • 3 replies
  • 5787 views

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. 

This topic has been closed for replies.

3 replies

gbm
Lead III
October 20, 2023

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.

My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice
nunokisiAuthor
Associate II
October 20, 2023

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

AScha.3
Super User
October 20, 2023

its same , with or without rtos.

"If you feel a post has answered your question, please click ""Accept as Solution""."
Piranha
PiranhaBest answer
Principal III
October 22, 2023