Issues using HAL_UARTEx_ReceiveToIdle_DMA(...) and HAL_UARTEx_RxEventCallback(...)
Finally I used the HAL_UARTEx_ReceiveToIdle_DMA(...) function and the associated HAL_UARTEx_RxEventCallback(...) Interruptcallback. It works nice now, but I had some issues, which have been not so easy to explore. So I want to share them here. Maybe, it helps someone in the future.
First was: If you use UARTs and DMA with HAL and CubeMX to create the template of your project check the sequence of init functions. CubeMX puts the MX_DMA_Init(); behind the MX_USARTx_UART_Init() functions. This does not work. Manually change this and call MX_DMA_Init() before MX_USARTx_UART_Init(). Else no interrupt callback is triggered. (This is also true for HAL_UART_Receive_DMA(...) and its callbacks)
Second: UARTEx_RxEventCallback(...) is called with a Size parameter. The doc says "(indicates a position in reception buffer until which, data are available)" This is not true. Size is the position of the first byte in DMABuffer, where no data is available. So the position up which data is available is Size - 1. (So also you will never get a 0 as Size but you will get the length of your DMABuffer as a valid value (which was provided by HAL_UARTEx_ReceiveToIdle_DMA))
And also very important Data is not only available from the start of DMAbuffer up to Size-1, but rather from Size of the last call of UARTEx_RxEventCallback up to Size-1. It is like DMA works
Third: HAL avoids to call UARTEx_RxEventCallback(...) in the the situation of DMAComplete, So if Idle happens, if the DMAbuffer is just full, the callback is only called once. But it doesn't avoid to call the callback in DMA HalfComplete situation. So if Idle and HalfComplete coincide, the callback is called twice (once for HalfComplete and once for Idle). This could mislead your evaluation logic to think, the DMA was written once more at it's full length.
IMHO it also shouldn't be called for HalfComplete, or it should be also called twice at DMAComplete. But the another parameter would be nice in order to be informed about the reaseon of the call.
Nevertheless this kind of reading from UART solved a lot of problems for me. Thak you for that.
