Free-Running RX eDMA on K22 using SDK 2.8.2

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Free-Running RX eDMA on K22 using SDK 2.8.2

1,182 Views
whata
Contributor III

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!

 

Labels (1)
0 Kudos
7 Replies

1,144 Views
nxf56274
NXP Employee
NXP Employee

Hi,

You can try this function, EDMA_AbortTransfer.

/*!
* brief eDMA aborts transfer.
*
* This function disables the channel request and clear transfer status bits.
* Users can submit another transfer after calling this API.
*
* param handle DMA handle pointer.
*/
void EDMA_AbortTransfer(edma_handle_t *handle)

Have a great day,
TIC

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

- We are following threads for 7 days after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos

1,135 Views
whata
Contributor III

Hi,

I've already tried with EDMA_Abort.. and EDMA_Stop.. they didn't work

0 Kudos

1,121 Views
nxf56274
NXP Employee
NXP Employee

Hi,

If possible, I want to get your code to test.

Have a great day,
TIC

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

- We are following threads for 7 days after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos

1,114 Views
whata
Contributor III

Sent as PM

0 Kudos

1,089 Views
nxf56274
NXP Employee
NXP Employee

Please see the PM.

0 Kudos

1,101 Views
nxf56274
NXP Employee
NXP Employee

Hi,

Try this. In function UART_SendEDMA, Add this code  after function EDMA_SubmitTransfer.

The code is 'DMA0->TCD[Your tx channel].DLAST_SGA = -1 * (xfer->dataSize);'

Have a great day,
TIC

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

- We are following threads for 7 days after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos

1,070 Views
whata
Contributor III

This did not work, I don't see any change.

0 Kudos