Skip to main content
Associate III
February 6, 2024
Solved

Does HAL_UART_Transmit/HAL_UART_Receive needs a semaphore?

  • February 6, 2024
  • 2 replies
  • 2849 views

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.
Best answer by TDK

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.

2 replies

TDK
TDKBest answer
February 6, 2024

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
February 6, 2024

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