Are HAL_UART_RxCpltCallback() and HAL_UART_RxHalfCpltCallback() called to late?
Hello community,
I experienced a strange behavior, when when using the UART-DMA-mechanism.
The MCU is a STM32L051R6T6, and I use CubeIDE with HAL-drivers.
I receive a cyclic telegram of 40 bytes on both USARTs.
The telegram starts with two detection bytes, then a telegram counter byte follows. After this header follows the payload and the last 4 bytes are a CRC32. It runs on 9600 baud, the telegram (oscill. checked) is 40ms long, the a idle time of about 10ms.
Since a DMAbuffer of 40 bytes brought me to the result, that sometimes a telegam is overwitten before I could copy it away in HAL_UART_RxCpltCallback, I now use a 80 bytes DMAbuffer. and both, the HAL_UART_RxCpltCallback and HAL_UART_RxHalfCpltCallback.
In most cases this works: At first I copy away the DMABuffer, then I scan for the header bytes. (In HAL_UART_RxHalfCpltCallback I scan from the middle of the buffercopy, in HAL_UART_RxCpltCallback I scan from the start to the middle). So I should find one telegram, while the UART writes the other one and then pauses for the 10ms gap between the telegrams.
But sometimes it seems, that the callback are called so late, that also the telegram after the next is in write progress. I debugged the dmacopy and I saw it on the telegram counters. Called from HAL_UART_RxHalfCpltCallback in the second part should be the lower telegram counter and in the first part should be the higher telegram counter and called from HAL_UART_RxCpltCallback I should find the lower counter first then the higher counter. Thats not the case sometimes. So I get a CRC Error. (when I manually decremet the counter, the CRC is ok). So it is partly overwritten by the after next one.
This behavior only happens, if I transmit on the UARTS (by interrupt) meanwhile in the maincycle.Without transmitting, everything works without any problem.
Is it possible, that the the Rxcallbacks of the HAL are called to late somehow?
Thank you. I hope you could understand, what I mean.
