2024-02-22 8:36 AM
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?
2024-02-22 8:43 AM - edited 2024-02-22 8:45 AM
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?
2024-02-22 9:36 AM
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?
2024-02-22 1:18 PM - edited 2024-02-22 1:20 PM
> 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
2024-02-22 2:27 PM
> 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.
2024-02-23 1:00 AM
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
2024-02-23 6:39 AM
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.
2024-02-23 2:25 PM
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).
We’re moving the ST Community to a new platform to give you a better and more reliable community experience.