lpuart_edma_transfer example code stuck receiving for rt1020

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

lpuart_edma_transfer example code stuck receiving for rt1020

1,623 Views
theRockyRaccoon31
Contributor I

I'm pretty new to MCUxpresso and embedded programming, but I'm currently working on testing out UART EDMA communications for my club. To do so, I imported the lpuart_edma_transfer example code for my MIMXRT1020-EVK board. I didn't make any major modifications to this code except for adding some checks and PRINTF statements (I selected the semihost option on my project) and the only connection on my board I have right now is a wire connecting the UART1RX  pin to the UART1TX pin. 

The problem I seem to be having is that even though the LPUART_ReceiveEDMA function returns a "kStatus_Success"" status, it doesn't appear to be receiving any data. Additionally, the "LPUART_USER_CALLBACK" function is never called to set rxOnGoing to false so the while(1) loop at the end just runs forever without actually going into any of the if statements. I'm pasting my code and debug output below. Please let me know if there are any suggestions/ideas about what the issue might be.

********************CODE START*********************************************

/*
* Copyright (c) 2015, Freescale Semiconductor, Inc.
* Copyright 2016-2017 NXP
* All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/

#include "pin_mux.h"
#include "clock_config.h"
#include "board.h"
#include "fsl_lpuart_edma.h"
#if defined(FSL_FEATURE_SOC_DMAMUX_COUNT) && FSL_FEATURE_SOC_DMAMUX_COUNT
#include "fsl_dmamux.h"
#include "fsl_debug_console.h"
#endif
/*******************************************************************************
* Definitions
******************************************************************************/
#define DEMO_LPUART LPUART1
#define DEMO_LPUART_CLK_FREQ BOARD_DebugConsoleSrcFreq()
#define LPUART_TX_DMA_CHANNEL 0U
#define LPUART_RX_DMA_CHANNEL 1U
#define LPUART_TX_DMA_REQUEST kDmaRequestMuxLPUART1Tx
#define LPUART_RX_DMA_REQUEST kDmaRequestMuxLPUART1Rx
#define EXAMPLE_LPUART_DMAMUX_BASEADDR DMAMUX
#define EXAMPLE_LPUART_DMA_BASEADDR DMA0
#define ECHO_BUFFER_LENGTH 8

/*******************************************************************************
* Prototypes
******************************************************************************/

/* LPUART user callback */
void LPUART_UserCallback(LPUART_Type *base, lpuart_edma_handle_t *handle, status_t status, void *userData);

/*******************************************************************************
* Variables
******************************************************************************/

lpuart_edma_handle_t g_lpuartEdmaHandle;
edma_handle_t g_lpuartTxEdmaHandle;
edma_handle_t g_lpuartRxEdmaHandle;
AT_NONCACHEABLE_SECTION_INIT(uint8_t g_tipString[]) =
"LPUART EDMA example\r\nSend back received data\r\nEcho every 8 characters\r\n";
AT_NONCACHEABLE_SECTION_INIT(uint8_t g_txBuffer[ECHO_BUFFER_LENGTH]) = {0};
AT_NONCACHEABLE_SECTION_INIT(uint8_t g_rxBuffer[ECHO_BUFFER_LENGTH]) = {0};
volatile bool rxBufferEmpty = true;
volatile bool txBufferFull = false;
volatile bool txOnGoing = false;
volatile bool rxOnGoing = false;

/*******************************************************************************
* Code
******************************************************************************/
/* LPUART user callback */
void LPUART_UserCallback(LPUART_Type *base, lpuart_edma_handle_t *handle, status_t status, void *userData)
{
   PRINTF("In UserCallback function\r\n");
   userData = userData;

   if (kStatus_LPUART_TxIdle == status)
   {
      PRINTF("Tx in user callback function done and idle now\r\n");
      txBufferFull = false;
      txOnGoing = false;
   }

   if (kStatus_LPUART_RxIdle == status)
   {
      PRINTF("Rx in user callback function done and idle now\r\n");
      rxBufferEmpty = false;
      rxOnGoing = false;
   }
}

/*!
* @brief Main function
*/
int main(void)
{
   PRINTF("STARTING CODE\r\n");
   lpuart_config_t lpuartConfig;
   edma_config_t config;
   lpuart_transfer_t xfer;
   lpuart_transfer_t sendXfer;
   lpuart_transfer_t receiveXfer;

   BOARD_ConfigMPU();
   BOARD_InitPins();
   BOARD_BootClockRUN();

   /* Initialize the LPUART. */
   /*
   * lpuartConfig.baudRate_Bps = 115200U;
   * lpuartConfig.parityMode = kLPUART_ParityDisabled;
   * lpuartConfig.stopBitCount = kLPUART_OneStopBit;
   * lpuartConfig.txFifoWatermark = 0;
   * lpuartConfig.rxFifoWatermark = 0;
   * lpuartConfig.enableTx = false;
   * lpuartConfig.enableRx = false;
   */
   LPUART_GetDefaultConfig(&lpuartConfig);
   lpuartConfig.baudRate_Bps = BOARD_DEBUG_UART_BAUDRATE;
   lpuartConfig.enableTx = true;
   lpuartConfig.enableRx = true;

   LPUART_Init(DEMO_LPUART, &lpuartConfig, DEMO_LPUART_CLK_FREQ);

#if defined(FSL_FEATURE_SOC_DMAMUX_COUNT) && FSL_FEATURE_SOC_DMAMUX_COUNT)
   /* Init DMAMUX */
   DMAMUX_Init(EXAMPLE_LPUART_DMAMUX_BASEADDR);
   /* Set channel for LPUART */
   DMAMUX_SetSource(EXAMPLE_LPUART_DMAMUX_BASEADDR,           LPUART_TX_DMA_CHANNEL, LPUART_TX_DMA_REQUEST);
   DMAMUX_SetSource(EXAMPLE_LPUART_DMAMUX_BASEADDR,         LPUART_RX_DMA_CHANNEL, LPUART_RX_DMA_REQUEST);
   DMAMUX_EnableChannel(EXAMPLE_LPUART_DMAMUX_BASEADDR,     LPUART_TX_DMA_CHANNEL);
    DMAMUX_EnableChannel(EXAMPLE_LPUART_DMAMUX_BASEADDR,       LPUART_RX_DMA_CHANNEL);

#endif
   /* Init the EDMA module */
   EDMA_GetDefaultConfig(&config);
   EDMA_Init(EXAMPLE_LPUART_DMA_BASEADDR, &config);
   EDMA_CreateHandle(&g_lpuartTxEdmaHandle,         EXAMPLE_LPUART_DMA_BASEADDR, LPUART_TX_DMA_CHANNEL);
   EDMA_CreateHandle(&g_lpuartRxEdmaHandle,     EXAMPLE_LPUART_DMA_BASEADDR, LPUART_RX_DMA_CHANNEL);

#if defined(FSL_FEATURE_EDMA_HAS_CHANNEL_MUX) &&       FSL_FEATURE_EDMA_HAS_CHANNEL_MUX

   EDMA_SetChannelMux(EXAMPLE_LPUART_DMA_BASEADDR,     LPUART_TX_DMA_CHANNEL, DEMO_LPUART_TX_EDMA_CHANNEL);
    EDMA_SetChannelMux(EXAMPLE_LPUART_DMA_BASEADDR,     LPUART_RX_DMA_CHANNEL, DEMO_LPUART_RX_EDMA_CHANNEL);
#endif
   /* Create LPUART DMA handle. */
   LPUART_TransferCreateHandleEDMA(DEMO_LPUART, &g_lpuartEdmaHandle,       LPUART_UserCallback, NULL, &g_lpuartTxEdmaHandle,
   &g_lpuartRxEdmaHandle);

   /* Send g_tipString out. */
   xfer.data = g_tipString;
   xfer.dataSize = sizeof(g_tipString) - 1;
   txOnGoing = true;
   status_t sendStatus = LPUART_SendEDMA(DEMO_LPUART,        &g_lpuartEdmaHandle, &xfer);
   if(sendStatus == kStatus_Success){
      PRINTF("Initial sending of all data successful :)\r\n");
   }
   else{
      PRINTF("Initial sending of all data UNsuccessful :(\r\n");
   }

   /* Wait send finished */
   while (txOnGoing)
   {
   }

   /* Start to echo. */
   sendXfer.data = g_txBuffer;
   sendXfer.dataSize = ECHO_BUFFER_LENGTH;
   receiveXfer.data = g_rxBuffer;
   receiveXfer.dataSize = ECHO_BUFFER_LENGTH;

   while (1)
  {
      PRINTF("START OF WHILE LOOP\r\n");
      /* If RX is idle and g_rxBuffer is empty, start to read data to g_rxBuffer. */
      if ((!rxOnGoing) && rxBufferEmpty)
      {
         rxOnGoing = true;
         status_t recvStatus = LPUART_ReceiveEDMA(DEMO_LPUART,       &g_lpuartEdmaHandle, &receiveXfer);
         if(recvStatus == kStatus_Success){
            PRINTF("Receiving of eight characters hopefully successful :)\r\n");
            for (int i = 0; i < 8; i++){
               PRINTF("DATA RECEIVED: %c\r\n", receiveXfer.data[i]);
            }
          }
          else{
             PRINTF("Receiving of eight characters UNsuccessful :(\r\n");
          }
     }

      /* If TX is idle and g_txBuffer is full, start to send data. */
      if ((!txOnGoing) && txBufferFull)
      {
         PRINTF("txBuffer is full so getting ready to echo characters nice\r\n");
         txOnGoing = true;
         LPUART_SendEDMA(DEMO_LPUART, &g_lpuartEdmaHandle, &sendXfer);
      }

      /* If g_txBuffer is empty and g_rxBuffer is full, copy g_rxBuffer to g_txBuffer. */
      if ((!rxBufferEmpty) && (!txBufferFull))
      {
         PRINTF("rxBuffer is full so copying over its values to txBuffer so it can     echo\r\n");
         memcpy(g_txBuffer, g_rxBuffer, ECHO_BUFFER_LENGTH);
         rxBufferEmpty = true;
         txBufferFull = true;
      }
   }
}

********************CODE END************************************************

 

********************DEBUG OUTPUT START*********************************

[MCUXpresso Semihosting Telnet console for 'evkmimxrt1020_testingEDMAUart_lpuart_edma_transfer LinkServer Debug' started on port #### @ ###.#.#.#]

STARTING CODE
In UserCallback function
Tx in user callback function done and idle now
Initial sending of all data successful
START OF WHILE LOOP
Receiving of eight characters hopefully successful
DATA RECEIVED:

DATA RECEIVED:

DATA RECEIVED:

DATA RECEIVED:

DATA RECEIVED:

DATA RECEIVED:

DATA RECEIVED:

DATA RECEIVED:

START OF WHILE LOOP

START OF WHILE LOOP

(continues like this ...)

********************DEBUG OUTPUT END*************************************

 

 

 

 

 

0 Kudos
Reply
3 Replies

1,616 Views
jeremyzhou
NXP Employee
NXP Employee

Hi,
Thank you for your interest in NXP Semiconductor products and for the opportunity to serve you.
Before answering your question, I was wondering if you can list the code modification you did and the test steps.
In further, I'd like to suggest you upload the demo project, as I can help me to figure it out.
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 weeks 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
Reply

1,614 Views
theRockyRaccoon31
Contributor I

Sure, I've attached my project to this post.

As for the modifications, all I did was add PRINTF statements to the code and also changed lines like "LPUART_SendEDMA(DEMO_LPUART, &g_lpuartEdmaHandle, &xfer)" to "status_t sendStatus = LPUART_SendEDMA(DEMO_LPUART, &g_lpuartEdmaHandle, &xfer)" so I could check the values of return values with an if/else.

The test steps were:

1. Connect the UART1RX and UART1TX of my 1020 board together. I've attached a picture of my test setup if you would like to take a look. 

 

2. Debug the project and observe the debug output

 

Please let me know if there is any other information you need from me and thanks in advance!

0 Kudos
Reply

1,599 Views
jeremyzhou
NXP Employee
NXP Employee

Hi,
Thanks for your reply.
In the evkmimxrt1020_lpuart_edma_transfer, it will use the LPUART1 (GPIO_AD_B0_06 and GPIO_AD_B0_07), PRINTF also use the above LPUART1 to out the string, they shouldn't work together actually.
In my opinion, please follow the readme.txt to test the evkmimxrt1020_lpuart_edma_transfer demo.

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 weeks 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
Reply