STM32F415RG missing bytes on UART RX
Hi,
I have a board containing an STM32F415RG and another board containing an MCU from another manufacturer. Both boards are supposed to communicate with each other using RS-232 transceivers. The communication is running at 9600 baud and working well for some minutes, after which the STM32 seems to miss received bytes.
I work in IAR, but I have configured the STM32 using CubeMX with Firmware package F4 V1.25.0. My application is running on CMSISv2/freeRTOS. I use the HAL API for all module accesses.
Communication is always initiated by the STM32 by sending 64 bytes of data to the slave MCU. The STM32 expects always 64 bytes in return. It does not matter if I use the _IT or _DMA implementations of the StartRX/TX methods, I have checked both. Every data packet ends with a 16 bit checksum.
I implemented a RX timeout using a semaphore which works fine, the timeout is long enough to accept some delay between the request and the response. When a timeout occurs, I abort the transfer (either by caling AbortReceive_IT() or DmaStop(), I have tried both). I put a breakpoint here, and I can see in my register view that the corresponding DMA data length register (NDTR) is non-zero, and the RX buffer array is not full. The missing bytes are somwhere in the middle because the checksum bytes are visible in the buffer, but not at its end where they should be.
So, I connected an oscilloscope to the RS-232 signals and also to the UART signals right before the STM32. Also, I connected a logic analyzer to the same signals. In the logic analyzer output, I see that all bytes are transmitted correctly. I also cannot observe any signal distortion on the analog side. But the STM32 keeps missing bytes, even if the transfer seems OK for the analyzer.
When a byte loss occurs, the following transmissions are most likely to be corrupted also. This keeps going for a while (minutes), after which the transmissions are working fine again. I have read that the HAL API is prone to race conditions, but since I have only one task accessing the UART peripheral, I don't think this a problem here.
Has anyone encountered this problem before, or do you have a suggestion?
