What could be causing the STM32L152 UART Rx interrupt to intermittently not fire when data arrives and interrupts are correctly configured?
Hello all,
First off, I apologize that I am not able to provide code as everything I have been able to do reproduce this problem is proprietary. Given that, I am looking for advance debugging techniques for diagnosing this intermittent failure of the UART interrupt to fire.
The overall problem is that we noted the device would appear to "drop" tens of bytes at a time which appears to be caused by the UART Rx interrupt not firing even though a tap on the UART line shows the data arriving.
Overview of the device and setup in question:
I am working with a legacy device that runs an STM32L152 running Keil RTX. All logic levels are 3.3V, UART is clocked at 16MHz, system clock 32MHz, and the baud rate is 115200. The UART Rx interrupt has the highest priority available to the RTX implementation and the UART interrupt is configured to trigger on errors and received data.
When data is received on the UART Rx line it is read from the data register, placed in a circular buffer, then a signal is sent to a high priority RTOS task to parse the data. If an error flag is detected the interrupt flag is cleared via a read of the flag, then a read of the data register.
What has been tried thus far:
This set up works perfectly 99% of the time, but we notice large chunks of bytes being dropped. Using Keil's event viewer, we can see that even when the RTOS is in idle mode (i.e. it is not in handler mode), the UART Rx interrupt will sometimes not fire.
The NVIC does not appear to be servicing any other interrupt and the only flags set in the UART status register are the TXE and TC from the previously sent frame. Additionally, tracking the state of the configuration registers, we've confirmed that the enabled interrupts configuration is not changing.
We have confirmed that the data arrives on the Rx line of the device via an FTDI UART/USB tap we have placed on the board trace. We have verified that the issue persists regardless of the RTOS tasks running, if an error (framing, overflow, etc.) occurs, or the baud rate (we have observed the behavior with a baud rate of 9600). The amount of data being transferred via UART when this happens is usually a few tens of bytes.
It is not a buffer overflow as we have greatly expanded the size of the circular buffer and ensured that code checking for a buffer overflow does not return true in these situations.
We have also observed this behavior in all of the device we have produced, not just the one I am developing with, and it appears isolated to USART2 even though UARTs 1-4 are used.
I have found nothing in the RTX documentation that I thought could be causing this and am thoroughly out of ideas. In leu of any concrete solution, I've simply had to make our "we've missed something so retry last command" patch more robust.
If anyone has any ideas, thoughts, resources, or avenues I should investigate, please do not hesitate to let me know. I will also be pursuing this question with Keil and U-Blox.
Thank you in advance for any time and thought you put into this,
-Brian
