2023-10-20 01:24 AM
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.
Solved! Go to Solution.
2023-10-21 05:41 PM
2023-10-20 02:09 AM
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.
2023-10-20 03:44 AM
Thanks for the quick reply!
Would that advantage also apply when the HAL function is called from an RTOS?
2023-10-20 04:43 AM
its same , with or without rtos.
2023-10-21 05:41 PM