Hi,
I'm using MK22F51212 and just recently upgraded to a latest SDK 2.8.2 and I'm experiencing some issues with free-running rx dma on uart 0 where rx dma path seemingly does not abort currently running rx transfer when explicitly asked to do so.
The behavior I'm targeting is as follows:
My tx/rx function is as follows:
void uart_write (uint8_t uart, const uint8_t *str, size_t len)
{
uart_transfer_t tx;
uart_rx_start (uart, true);
if (len > 0)
{
uarts[uart].txDone = false;
tx.data = (uint8_t*)str;
tx.dataSize = len;
UART_SendEDMA(uartParams[uart].base, &uarts[uart].handle, &tx);
while (!uarts[uart].txDone);
}
}
static void uart_rx_start (uint8_t uart, bool clear)
{
uart_transfer_t rx;
UART_TransferAbortReceiveEDMA(uartParams[uart].base, &uarts[uart].handle);
if (clear)
memset (&uarts[uart].buffer[0], 0, UART_BUF_SIZE);
rx.data = &uarts[uart].buffer[0];
rx.dataSize = UART_BUF_SIZE;
UART_ReceiveEDMA(uartParams[uart].base, &uarts[uart].handle, &rx);
}
Basic premise is that every time I call uart_write, currently ongoing rx transfer should be terminated and restarted. So rx dma transfer ideally should start re-filling the same buffer from head. What happens is for every call to uart_write rx transfer never terminates so my buffer keeps on filling up.
I don't remember seeing this behavior on SDK 2.5.0 on a previous project so obviously something has changed (there I was targeting UART2).
To illustrate:
I'm sending a 9 byte command and expect ~31 bytes response ( command echo + response), so after very first call to uart_write the buffer looks like this:
2000041c = 61 74 2b 63 65 72 65 67 3f 0d 0d 0a 2b 43 45 52
2000042c = 45 47 3a 20 30 2c 30 0d 0a 0d 0a 4f 4b 0d 0a
Second call to uart_write with the same command and results in the following buffer contents (ideally I would expect the same result as above):
2000041c = 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
2000042c = 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 61
2000043c = 74 2b 63 65 72 65 67 3f 0d 0d 0a 2b 43 45 52 45
2000044c = 47 3a 20 30 2c 30 0d 0a 0d 0a 4f 4b 0d 0a
But for some reason rx dma transfer thinks that I have recieved 62 bytes (I did, but I have terminated the transfer with a call to UART_TransferAbortReceiveEDMA and explicitly started a new transfer, so the new count should be 31) and new data must be placed at the beginning of the buffer.
So my question is why doesn't my call to UART_TransferAbortReceiveEDMA actually aborts an ongoing transfer? And what can be done to fix this?
Thanks!