cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L431KCUX UART cannot receive more than 49 bytes

MO94
Associate III

Recently I have encountered a strange issue I cannot really explain...

I have a firmware that manages serial UART communication with a callback that has a state machine with 3 states.

In the first state, UART is set to perpetually expect 1 byte of data until a specific value is received. If the value is received, another byte is set to be read via UART_Receive_IT and SM proceeds to the next state.

In the second state, the received byte is considered message length and UART_Receive_IT is set to read the expected amount of bytes.

The third state is supposed to happen when the expected amount of bytes is received and all parsing is done... however, it is never triggered when the serial data is longer than 49 bytes.

I am sending data with RealTerm. Short messages work just fine, but then I need to send 147 bytes. In the debug, I can see from the state of huart2 handler that RxXferCount starts at 147 and decrements until 98. Then, UART_RxISR_8BIT is never called again, the state remains unchanged until firmware's timeout triggers and aborts the reception.

 I tried to look at some other things. RTS and CTS pins are low at the time when timeout happens. The timeout was initially 0.02s, I raised it to 1s with no effect. Overrun flag is low as well. My buffer is larger than the message I am expecting. I tried to use UART_Receive_IT in batches of 32 bytes, but then the first batch is received correctly and the second batch freezes in the similar way as soon as the total amount of received bytes reaches 49. I am not supposed to reset something between UART_Receive_IT calls, correct?

Why UART might just stop receiving data? What else can I do to try debug this?

15 REPLIES 15

Count the number of times your IRQHandler is called vs that of.the callback routine.

Read the UARTs ISR register directly, any other bits flagging?

Check overrun, framing and noise errors.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

In some part of your code, you call: HAL_UART_Receive_IT to enable interruption, how do you call it? how do you configure it?

in some other part of your code should be the  IRQHandler for the Interruption, how do you manage there the bytes and so on? if it is possible to share...

Delaying the characters significantly does not change the outcome.


@MO94 wrote:

Delaying the characters significantly does not change the outcome.


So try adding instrumentation to see what's going on; eg, output to a different UART ...

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.
TDK
Super User

If ORE=0, data probably didn't make it to the peripheral. Put a logic analyzer on the line to find the truth.

If you feel a post has answered your question, please click "Accept as Solution".
MO94
Associate III

Hello everyone, thank you for the participation.

After a couple of tests I found out that Realterm v2.0.0.7 does not send more than 49 bytes in one go for some reason. I used a makeshift python script to send the data and it worked. Good grief, threw me for quite a loop.