AnsweredAssumed Answered

Want to implement UART free running DMA receiver that can be read asynchronously

Question asked by Swapnil Pendhare on May 10, 2017
Latest reply on Mar 13, 2018 by Carl Norman

I am working on K22 controller, 

 

My requirement is, 

1. An application layer reads data at regular interval for with 256 bytes to be read. 

2. UART driver should have a respective read API, where it checks for available number of bytes in read DMA buffer, Read those many bytes and return read function, with number of read bytes from DMA as an return value.

 

We have been using Kinetis SDK and utilizing APIs provided in fsl_dma_manager.c for dma managment & fsl_uart_edma.c API for uart dma handles. 

 

We checked that UART_ReceiveEDMA() function checks if DMA buffer has requested number of bytes and if available it reads them and returns. If requested number of bytes are not available it returns with no data, as this is non-blocking API. 

 

Now, 

We tried to use UART_TransferGetReceiveCountEDMA() to identify number of bytes available in DMA read buffer. and tried to call UART_ReceiveEDMA() with request length equal to available bytes count provided by UART_TransferGetReceiveCountEDMA() API. 

 

But this functionality does not work correctly.? Please provide your suggestions. 

 

Code sniped : 

 

uint32_t readCount = 0;

uint8_t g_newRxBuffer[256];

uint8_t g_txBuffer[256];

while (true)

{
   delayms(100);
   LPUART_TransferGetReceiveCountEDMA(DEMO_LPUART, &g_lpuartEdmaHandle, &readCount) ;
   if (readCount > 0  )
   {

       receiveXfer.data = g_newRxBuffer;
       receiveXfer.dataSize = readCount;
       LPUART_ReceiveEDMA(DEMO_LPUART, &g_lpuartEdmaHandle, &receiveXfer);

 

       memcpy(g_txBuffer, g_newRxBuffer, readCount);
       /* Start to echo. */
       sendXfer.data = g_txBuffer;
       sendXfer.dataSize = readCount;
       LPUART_SendEDMA(DEMO_LPUART, &g_lpuartEdmaHandle, &sendXfer);

    }

}

Outcomes