AnsweredAssumed Answered

Possible bug in HAL USART Driver

Question asked by holt.andrew on Sep 11, 2016
Latest reply on Sep 24, 2016 by m.anjana
I am experimenting with FreeRTOS and the HAL layer using an STM32F4 DISCO board.

I have two threads.  One reads from the serial port and send the byte read, in a message to a second task.

The second task, blocking on a message reads it and sends the byte out through the same serial port.

What I get is that the second task always get HAL_BUSY.  If my reading of the code is correct this means that the USART is locked. ( ?)

On inspection of the code for HAL_UART_Receive I have noticed that __HAL_LOCK(huart) returns if it can't acquire the lock.  However if it succeeds in acquiring the lock but later times out then a return is made whilst the lock is still held.

Any subsequent call to either HAL_UART_Receive or HAL_UART_Transmit will fail with HAL_BUSY.  I would like to suggest two potential fixes.

1) TX & RX each has it's only lock.  So I can send whilst receive is busy and vice-versa.
2) The receive and transmit routines need restructuring to set a status and return it to the caller AFTER the lock has been released.

or has all this been fixed already and I'm running something old ?