AnsweredAssumed Answered

UART misalign received data after previous receive timeout

Question asked by schperplata on Nov 2, 2017
Latest reply on Nov 6, 2017 by AvaTar


I'm having a problem making my UART communication robust on error. (two STM32F07xx custom boards communicationg through UART3, HAL + CubeMx). I have custom protocol (quite simple), fixed message length + acknowledge.

During normal runtime, I can correctly receive and transmitt data.  If I intentionally (or unintentionally) insert some delay in code (elsewhere, not related to communication part of the project), the receive part of the two boards should:

- get UART receive timeout,

- log an error into error log buffer,

- flush data register and

- continue to receive/send/communicate.


In reality it does everything except that any receive data after first timeout is misaligned. For example, 
during normal communication with no errors, this is received:

0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF

On error, when data is not received and UART driver throws receive timeout (aka HAL_TIMEOUT), all the data is received corectly with additional byte at the beggining, causing data to be misaligned and therefore all wrong:

0x00 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF



What could cause this additional byte in reading data after previous rx timeout?



I receive data in blocking mode, using:

rx_status = HAL_UART_Receive(&huart3, data, MSG_SIZE, UART_BU_TO_CU_RX_TIMEOUT);

I tried to flush data register with all functions I could find (I think HAL documentation is a little bit unclear how to properly use this macros):