HAL_UART_Receive_* causes active transmission to stall
tl;dr - HAL_UART_Receive_XXX, HAL_UART_Transmit_XXX == happiness; HAL_UART_Transmit_XXX, HAL_UART_Receive_XXX == misery. The call to HAL_UART_Receive_XXX causes the transmission started by HAL_UART_Transmit_XXX to stall in both interrupt and DMA modes.
Longer story:
This affects both interrupt-driven and DMA operation, which is why I've added the DMA label.
I am using FreeRTOS, and implementing a serial protocol that, while practically half-duplex in behavior, is written in a full-duplex form. What I mean is the protocol doesn't really expect both sides to be transmitting at the same time, but the code isn't written to prevent it. Theoretically parts of the protocol could overlap.
The typical behavior for a transmission is to first call HAL_UART_Receive_DMA(..) to prime the receiver for a response, and then call HAL_UART_Transmit_DMA(..) to send a message.
When the calls occur in that order, everything works perfectly.
Unfortunately, sometimes the task responsible for calling HAL_UART_Receive_DMA is preempted by the task which calls HAL_UART_Transmit_DMA, reversing the order of the calls.
This predictably leads to the transmission stalling. This happens whether I'm using interrupt-driven or DMA transmission.
With interrupt-driven transmission, I was able to instrument the UART IRQ handler and discover that transmission stalled because the TXEIE bit wasn't set, so the TXE interrupt didn't fire and the IRQ handler didn't feed more data to the TX FIFO. With DMA operation, I haven't uncovered the cause of the stall but I expect it's something similar.
My hypothesis is that something in the HAL_UART_Receive_* code leads to TXEIE being cleared (or similar for DMA), although reading the library code, I don't see where it would happen (but the effect is observable; the TXEIE bit is not set when it should be).
I think I've successfully coded around the problem, using state variables to ensure the TX and RX calls happen in the correct order (tests are underway as I write), but...I shouldn't have to do that, should I? Is there a reason I should expect HAL_UART_Receive_* to cause an active transmission to stall? Can I call this a HAL bug?
