Blocking vs non-blocking UART using an RTOS
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-10-20 1: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.
- Labels:
-
STM32H5 Series
-
UART-USART
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-10-21 5:41 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-10-20 2: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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-10-20 3:44 AM
Thanks for the quick reply!
Would that advantage also apply when the HAL function is called from an RTOS?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-10-20 4:43 AM
its same , with or without rtos.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-10-21 5:41 PM
