HAL UART Receive short reads - corrupt data
I am trying to implement a UART Rx using a typical
start-byte, length, payload
pattern.
I spin read on 1 character until it is my start byte. Then I read 2 bytes, shift them into a 16 bit length and read the remainder of the payload.
The trouble is, the second read for 2 bytes gives me garbage. It looks like the data stream has rewound 2 bytes.
I created a fresh project, enabled UART2 and UART6 only, connected the repeating test stream on UART6 Rx and read 1 byte at a time, immediately writing the one byte out on UART2 (The STM vCOM port).
The data is corrupted. It replays the same block of garbage and never advances.
Reading 2 bytes results in much the same.
Reading 4 bytes and the stream starts to track, but has drop outs and corruption.
Reading 50 bytes at a time and the stream is fine.
I looked through many examples, but have not found one that reads such short buffers. Most read larger buffers of at least 8 chars.
Is there a limitation or buffer alignment "gotcha" with the HAL uart functions? Is there a minimum read length? Is this just an artifact of using the blocking calls and creating too much overhead?
MCU: STM32F411RE (Nucleo-64 board)
UART Transmittor: ESP8266 using hardware Serial 0.
UART: 8bit, no parity, 1 stop bit, 115200baud
UART stream has been verified on the wire by a logic analyser and is clean.
Test "packet"
~(0x2E)(0x00)TEST_TOPIC/+/#/TOPIC THIS IS A 25 BYTE PAYLOAD
Repeated once a second.
Any ideas?
