receive unknown length frames with UART
Hello everyone,
I’m working on an embedded project where I need to receive a variable-length stream of bytes via UART on an MCU STM32H750. The key points are:
All bytes are payload, no start or stop bytes, no protocol framing.
The number of bytes is undefined and variable.
The byte stream starts when the MCU is ready.
I need to calculate CRC (Ethernet CRC32) over all received bytes.
After receiving all data, I must output the CRC via UART.
The UART baud rate is very high (greater than 900,000 baud).
My current approach:
I use UART interrupts to receive bytes one by one.
I update the CRC continuously with every received byte inside the interrupt handler.
This works fine for small data, and CRC calculation seems correct.
However, when I try to receive a large file or big data stream, the CRC isnt correct, the crc will be outputed before the whole data recieved.
I suspect the problem is related to handling the continuous stream without any start/stop or length information, and possibly buffer management or interrupt handling at such a high baud rate.
My questions:
How can I reliably receive an undefined-length UART stream without framing or start/stop bytes?
What techniques can I use to detect the end of transmission if there is no protocol?
Are there best practices for handling UART reception and CRC calculation in an interrupt-driven system at very high baud rates?
How can I avoid losing bytes or corruption when the incoming data size is large?
Any example code snippets or references for a similar use case would be great!
I try to use dma (ping pong buffer and update crc but it dosent work because i cant find the best time and place to calculate crc...)
Thanks a lot for your help!
