cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with "HAL_UARTEx_ReceiveToIdle_DMA"

areyzummo
Associate II

Hi,

I am using the HAL function "HAL_UARTEx_ReceiveToIdle_DMA" as follows:

void HAL_UARTEx_ReceiveToIdle_DMA(UART_HandleTypeDef *huart, uint16_t Size) {

//my actions

HAL_UARTEx_ReceiveToIdle_DMA(peripheral, buffer, COMMAND_MAXIMUM_LENGTH);

__HAL_DMA_DISABLE_IT(peripheral_dma, DMA_IT_HT);

}

It always works fine after I power up the MCU. I was continuously sending UART frames from my computer to the MCU for 2 days and it worked fine. The idle interruption was always detected.

But when I stop sending frames and then start sending them again (by disconnecting and reconnecting the TX wire), the IDLE interruption is no longer detected… until I turn off and power up the MCU again.

 

Why?

 

 

7 REPLIES 7
TDK
Guru

Probably a bug in your code. Debug the code, pause, and examine the state of the software state machine in huart. Also look for error flags in the UART registers.

> by disconnecting and reconnecting the TX wire

So the TX line floats? Perhaps triggering a frame error. Do you check for and clear those?

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

The UART registers look nice. Indeed, the ‘HAL_UARTEx_ReceiveToIdle_DMA’ returned HAL_OK the last time before disconnecting.

The TX is not floating.

The interrupt just disables itself. This is because if I put this code inside the while(1) loop:

HAL_UARTEx_ReceiveToIdle_DMA(peripheral, buffer, COMMAND_MAXIMUM_LENGTH);

__HAL_DMA_DISABLE_IT(peripheral_dma, DMA_IT_HT);

It works perfectly...

 

Why interruption is disable itself?

Bob S
Principal

> Why interruption is disable itself?

It doesn't.  Some code somewhere is disabling it.  Do you have an error callback function - HAL_UART_ErrorCallback()?  You should.  That will show you if you get errors as mentioned by @TDK

EDIT: The HAL UART code will disable the UART (and interrupts) when it detects an error.  That error callback it the way you detect that this has happened

> The UART registers look nice.

What does this even mean? "Nice" is not objective. Show them, do they indicate an error, do they indicate a transfer in progress? Show the contents of the huart structure. Same questions.

Likely this mystery could be solved within a few minutes of looking into those structures when the problem happens.

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

When I say that I disconnect the transmission, it means that I am disconnecting the wire. All the frames I see on my logic analyzer and oscilloscope are correct, with no glitches or noise.

However, you are right. When I disconnect, my code enters the function HAL_UART_ErrorCallback() and displays sometimes:

HAL_UART_ERROR_FE 0x00000004U /*!< Frame error */.

and other times:

HAL_UART_ERROR_DMA 0x00000010U /*!< DMA transfer error */

I don’t know what causes that error, because it always happens, even sometimes when I disconnect while no frames are being transmitted.

Okay, thank you. I didn’t know about that ErrorCall function. I was debugging by looking at the Huart structure, but since I always stop inside my code, the error code was always correct.

Thank you very much

 

If a frame error is being flagged, the data is likely not as glitchless and noise-free as you are interpreting. Note that a logic analyzer typically may only interpret based on edges.

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

What @TDK said.  When you disconnect the wire, does the RX line into the STM32 go low?  That would definitely cause a framing error (which means the line is still low at the "stop" bit, i.e. 9.5 bit times after the "start" bit or initial falling edge).