Efficient way to process USART-received data and flush RX buffer ?
I have a transmitter over USART and an STM32H7 receiving data. The transmitter always writes N bytes at a slow repetition rate, i.e. every 1 second or more.
Once N data are received by the STM32H7, for example using interrupt, the function HAL_UART_RxCpltCallback() is executed. There I can check the received buffer and parse it. So far, so good.
However, if an extra junk byte is received, the "modulo N" transaction is lost forever, because the next time HAL_UART_RxCpltCallback() will be fired, the RX buffer will be (at least) one-byte shifted and my parsing will fail.
Is there a way of flushing the receive buffer if an inconsistency is detected, thus waiting for the next, hopefully clean, transmission ?
The only solution I've figured out so far is to get alerted when every one single byte is received (calling HAL_UART_Receive_IT(&huart2, rx_buf, 1)), in order to be able to locate my message start byte and process the following bytes accordingly.
Is there any smarter and less time consuming way ?
Thanks a lot in advance,
Marco
