cancel
Showing results for 
Search instead for 
Did you mean: 

Does HAL_UART_Transmit/HAL_UART_Receive needs a semaphore?

ubaldot
Senior

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.  

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

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".

View solution in original post

2 REPLIES 2
TDK
Guru

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".
ubaldot
Senior

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