UART_SendEDMA sends only one byte

cancel
Showing results for 
Search instead for 
Did you mean: 

UART_SendEDMA sends only one byte

417 Views
RodrigoCesardaS
Contributor I

I'm using a MK60DN512VLL10 in a project with KSDK 2.0 and MCUXpresso 10.1.

My first attempt was a interrupt mode with ringbuffer, but I was getting RxHardwareOverrun with some frequency. Now I'm trying to use DMA. That's the code:

    //Init UART

    uart_config_t uart_cfg;
    UART_GetDefaultConfig(&uart_cfg);
    uart_cfg.baudRate_Bps = baudrate;
    uart_cfg.parityMode = parity;
    uart_cfg.enableRx = true;
    uart_cfg.enableTx = true;
    uart_cfg.rxFifoWatermark = 1;
    uart_cfg.txFifoWatermark = 1;
    UART_Init(UART4, &uart_cfg, srcClock_Hz);

    // Set up the DMA
    DMAMUX_Init(DMAMUX0);
    DMAMUX_SetSource(DMAMUX0, 1, kDmaRequestMux0UART4Tx);
    DMAMUX_EnableChannel(DMAMUX0, 1);
    DMAMUX_SetSource(DMAMUX0, 0, kDmaRequestMux0UART4Rx);
    DMAMUX_EnableChannel(DMAMUX0, 0);

    edma_config_t dma_cfg;
    EDMA_GetDefaultConfig(&dma_cfg);
    EDMA_Init(DMA0, &dma_cfg);

    // Create EDMA handle.
    EDMA_CreateHandle(&g_RxDmaHandle, DMA0, 0);
    EDMA_CreateHandle(&g_TxDmaHandle, DMA0, 1);
    UART_TransferCreateHandleEDMA(UART4, &g_uartDmaHandle, UART_UserCallback, NULL, &g_TxDmaHandle, &g_RxDmaHandle);

...

     //Send message

    sendXfer.data = txBuffer;
    sendXfer.dataSize = txsize;
    txFinished = 0;
    if(UART_SendEDMA(HMI_UART, &g_uartDmaHandle, &sendXfer) != kStatus_Success)
        return 0;
    return 1;

...

//UART Callback

void UART_UserCallback(UART_Type *base, uart_edma_handle_t *handle, status_t status, void *userData)
{
    userData = userData;
    if (kStatus_UART_TxIdle == status)
    {
        txFinished = 1;
    }
    else if (kStatus_UART_RxIdle == status)
    {
        rxFinished = 1;
    }

}

The problem is that is send only the first byte of the message.

Labels (1)
Tags (1)
0 Kudos
2 Replies

108 Views
danielchen
NXP TechSupport
NXP TechSupport

Hi Rodrigo:

I would suggest you refer to NXP DMA transfer demo, this demo shows how to use uart driver with edma.

SDK_2.0_FRDM-K64F\boards\frdmk64f\driver_examples\uart\edma_transfer

Regards

Daniel

108 Views
RodrigoCesardaS
Contributor I

Thanks. The example is basically the same code I've written. The problem with my code was the TX Fifo Watermark set to 1. I set it to 0 and starts to send normally.

0 Kudos