CyU3PDmaChannelSetupRecvBuffer API problem

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

Hi guys:

     I am developing with FX3.I am using UART DMA mode for data transfer.Now I want to store the data received by the UART in my own buffer.I queried through the API guide that the CyU3PDmaChannelSetupRecvBuffer API might be able to fulfill my needs.But this function always return ERROR message.I try to make some change in my code,but its error message will also change.

Frequent mistakes:

     -CY_U3P_ERROR_NULL_POINTER

or

     -CY_U3P_ERROR_BAD_ARGUMENT

or

     -CY_U3P_ERROR_ALREADY_STARTED

Here is my source code:

CyU3PDmaChannel glUartRXChHandle;

CyU3PDmaBuffer_t* glRxBuffer;

uint8_t glRXDataBuffer[16];

void ReceivedDataCallBack(

CyU3PDmaChannel   *chHandle, /* Handle to the DMA channel. */

        CyU3PDmaCbType_t  type,      /* Callback type.             */

        CyU3PDmaCBInput_t *input)

{

     CyU3PReturnStatus_t status;

     glRxBuffer->buffer = glRXDataBuffer;

     glRxBuffer->count = 16;

     glRxBuffer->size = 16;

     glRxBuffer->status = NULL;

     if(type == CY_U3P_DMA_CB_PROD_EVENT)

     {

     //status = CyU3PDmaChannelGetBuffer(&glUartRXChHandle, glRxBuffer, 0);    

         status = CyU3PDmaChannelSetupRecvBuffer(&glUartRXChHandle, glRxBuffer);

         if (status == CY_U3P_SUCCESS)

         {

              testBuffer[0] = 0x01;

              SendData(glRxBuffer->buffer, 16);

              //SendData(testBuffer, 16);

         }

          else

          {

               DPRINT("RXData ERROR : %d",status);

          }

     }

     CyU3PDmaChannelDiscardBuffer(&glUartRXChHandle);

}    

CyFxUartLpApplnInit (void)

{

    CyU3PUartConfig_t uartConfig;

    CyU3PDmaChannelConfig_t dmaConfig;

    CyU3PReturnStatus_t apiRetStatus = CY_U3P_SUCCESS;

    glTxBuffer = (CyU3PDmaBuffer_t*)CyU3PDmaBufferAlloc (16);

    glRxBuffer = (CyU3PDmaBuffer_t*)CyU3PDmaBufferAlloc (16);

    CyU3PMemSet(glRXDataBuffer,1,16);

    /* Initialize the UART module */

    apiRetStatus = CyU3PUartInit ();

    if (apiRetStatus != CY_U3P_SUCCESS)

    {

        /* Error handling */

        CyFxAppErrorHandler(apiRetStatus);

    }

    /* Configure the UART

       Baudrate = 115200, One stop bit, No parity, Hardware flow control enabled.

     */

    CyU3PMemSet ((uint8_t *)&uartConfig, 0, sizeof(uartConfig));

    uartConfig.baudRate = CY_U3P_UART_BAUDRATE_115200;

    uartConfig.stopBit = CY_U3P_UART_ONE_STOP_BIT;

    uartConfig.parity = CY_U3P_UART_NO_PARITY;

    uartConfig.flowCtrl = CyFalse;

    uartConfig.txEnable = CyTrue;

    uartConfig.rxEnable = CyTrue;

    uartConfig.isDma = CyTrue; /* DMA mode */

    /* Set the UART configuration */

    apiRetStatus = CyU3PUartSetConfig (&uartConfig, NULL);

    if (apiRetStatus != CY_U3P_SUCCESS )

    {

        /* Error handling */

        CyFxAppErrorHandler(apiRetStatus);

    }

    /* Create a DMA Manual channel between UART producer socket

       and UART consumer socket */

    CyU3PMemSet ((uint8_t *)&dmaConfig, 0, sizeof(dmaConfig));

    dmaConfig.size = CY_FX_UART_DMA_BUF_SIZE;

    dmaConfig.count = 1;

    dmaConfig.prodSckId = CY_U3P_LPP_SOCKET_UART_PROD;

    dmaConfig.consSckId = CY_U3P_CPU_SOCKET_CONS;

    dmaConfig.dmaMode = CY_U3P_DMA_MODE_BYTE;

    dmaConfig.notification = CY_U3P_DMA_CB_PROD_EVENT;

    dmaConfig.cb = ReceivedDataCallBack;

    dmaConfig.prodHeader = 0;

    dmaConfig.prodFooter = 0;

    dmaConfig.consHeader = 0;

    dmaConfig.prodAvailCount = 0;

    /* Create the channel */

    apiRetStatus = CyU3PDmaChannelCreate (&glUartRXChHandle,

    CY_U3P_DMA_TYPE_MANUAL_IN, &dmaConfig);

    if (apiRetStatus != CY_U3P_SUCCESS)

    {

        /* Error handling */

        CyFxAppErrorHandler(apiRetStatus);

    }

    dmaConfig.size = CY_FX_UART_DMA_BUF_SIZE;

    dmaConfig.count = 1;

    dmaConfig.prodSckId = CY_U3P_CPU_SOCKET_PROD;

    dmaConfig.consSckId = CY_U3P_LPP_SOCKET_UART_CONS;

    dmaConfig.dmaMode = CY_U3P_DMA_MODE_BYTE;

    dmaConfig.notification = 0;

    dmaConfig.cb = NULL;

    dmaConfig.prodHeader = 0;

    dmaConfig.prodFooter = 0;

    dmaConfig.consHeader = 0;

    dmaConfig.prodAvailCount = 0;

    /* Create the channel */

    apiRetStatus = CyU3PDmaChannelCreate (&glUartTXChHandle,

    CY_U3P_DMA_TYPE_MANUAL_OUT, &dmaConfig);

    if (apiRetStatus != CY_U3P_SUCCESS)

    {

        /* Error handling */

        CyFxAppErrorHandler(apiRetStatus);

    }

    /* Set UART Tx and Rx transfer Size to infinite */

    apiRetStatus = CyU3PUartTxSetBlockXfer(0xFFFFFFFF);

    if (apiRetStatus != CY_U3P_SUCCESS)

    {

        /* Error handling */

        CyFxAppErrorHandler(apiRetStatus);

    }

    apiRetStatus = CyU3PUartRxSetBlockXfer(0xFFFFFFFF);

    if (apiRetStatus != CY_U3P_SUCCESS)

    {

        /* Error handling */

        CyFxAppErrorHandler(apiRetStatus);

    }

    apiRetStatus = CyU3PDmaChannelSetXfer (&glUartRXChHandle, 0);

    if (apiRetStatus != CY_U3P_SUCCESS)

    {

            /* Error handling */

    CyFxAppErrorHandler(apiRetStatus);

    }

    /* Set DMA Channel transfer size */

    apiRetStatus = CyU3PDmaChannelSetXfer (&glUartTXChHandle, 0);

    if (apiRetStatus != CY_U3P_SUCCESS)

    {

        /* Error handling */

        CyFxAppErrorHandler(apiRetStatus);

    }

}

     Please give me some help! Thank you !

0 Likes
1 Solution
KandlaguntaR_36
Moderator
Moderator
Moderator
25 solutions authored 10 solutions authored 5 solutions authored

CyU3PDmaChannelSetupRecvBuffer should be used in DMA Override. Please refer FlashProg example provided here (Cypress\EZ-USB FX3 SDK\1.3\firmware\basic_examples\cyfxflashprog\cyfxflashprog.c) for this.

Use CyU3PDmaChannelGetBuffer in your case. This serves the purpose.

View solution in original post

0 Likes
4 Replies
KandlaguntaR_36
Moderator
Moderator
Moderator
25 solutions authored 10 solutions authored 5 solutions authored

CyU3PDmaChannelSetupRecvBuffer should be used in DMA Override. Please refer FlashProg example provided here (Cypress\EZ-USB FX3 SDK\1.3\firmware\basic_examples\cyfxflashprog\cyfxflashprog.c) for this.

Use CyU3PDmaChannelGetBuffer in your case. This serves the purpose.

0 Likes
Anonymous
Not applicable

Hi :

     Thank you for your reply.I have solved this problem.But I have a doubt.

     Callback function is triggered for why it must receive a minimum of 16 bytes of data?I have tried to set a smaller buffer size such as

dmaConfig.size = 8 and send smaller size data, modified initialization and memory allocation,but it didn't work.

     In other word,can I trandfer only 8 words or smaller datas with the UART (DMA mode )of the FX3?

Best regards,

Luca L

0 Likes

This is the DMA requirement.

The size of the DMA buffers should be in multiples of 16 bytes

Refer 5.5.4 DMA Buffer of FX3 TRM.

0 Likes
Anonymous
Not applicable

Hi:

     I know,Thanks a lot!

Best regards,

Luca L

0 Likes