I have a project where I need to read in some UART data (in this case, multiple six-byte packets), do some (very minor) processing, then transmit it out on a different UART. I'm having an issue with some of the TX data being corrupted mid-stream sometimes. It basically will send half of packet 1, then half of packet 2. So if packet 1 is ABCDEF, and 2 is UVWXYZ, I get ABCXYZ. I am using STM's HAL for the STM32L0x0 to read it one byte at a time (my packets have a known SOF and EOF byte), with a simple state machine to capture the full six-byte packet in a circular buffer. Note that the circular buffer always seems to have the correct contents; I don't see this corruption there.
The way I am reading the data is basically:
while(1)
{
HAL_UART_Receive_IT(UART, Buffer, 1);
}
However, there isn't really much else going on in the code until I get a full packet, so this function ends up getting called over and over. With a data rate of only 57.6kbps, even one byte takes 174uS with overhead. This function could get called dozens of times in that time period.
I guess what I am asking is what does the processor do when a function like this is repeatedly called? Is it "safe"; does the processor simply re-start the RX process? Older versions of the HAL for my part (STM32L0x0) used to have a bunch of Lock/Unlocks inside these calls, but they're gone in the newer versions.
Either way I plan to move the HAL_UART_Receive_IT(UART, Buffer, 1) call to a callback routine that only fires after successful data reception. I was just curious and Google wasn't giving me the answer I was looking for.