Skip to main content
Associate III
Feb 6, 2024 1:46 PM UTC
Solved

Does HAL_UART_Transmit/HAL_UART_Receive needs a semaphore?

Say that HAL_UART_Transmit function is concurrently called by two tasks.

So far, I know such a function is blocking, but I am not 100% sure that because of that it shall not be locked before usage if a concurrent task is going to call it.  

This topic has been closed for replies.
TDK
TDKBest answer
Feb 6, 2024 1:50 PM UTC

Yes, it needs an exclusive access mechanism.

At best, the second call will fail and return HAL_BUSY. At worst, it will mess up the software state machine as __HAL_LOCK is not thread-safe.

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

2 replies

TDK
TDKBest answer
Feb 6, 2024 1:50 PM UTC

Yes, it needs an exclusive access mechanism.

At best, the second call will fail and return HAL_BUSY. At worst, it will mess up the software state machine as __HAL_LOCK is not thread-safe.

"If you feel a post has answered your question, please click ""Accept as Solution""."
ubaldotAuthor
Associate III
Feb 6, 2024 4:26 PM UTC

Thanks. I will lock it with a mutexat OS level then.