cancel
Showing results for 
Search instead for 
Did you mean: 

USB Superspeed Peripherals

liuzhengxiang
New Contributor II

dmaConfig.cb = CyFxUartLpDmaCallback

the CyFxUartLpDmaCallback can not be called for uart rx dma of mode when the rx receive data.The code is as follows:

CyU3PReturnStatus_t
CyCx3AppDebugInit (void)
{
CyU3PUartConfig_t uartConfig;
CyU3PDmaChannelConfig_t dmaConfig;
CyU3PReturnStatus_t status = CY_U3P_SUCCESS;

/* Initialize the UART module */
status = CyU3PUartInit ();
if (status != CY_U3P_SUCCESS)
{
/* Error handling */
CyCx3AppErrorHandler(status);
}

/* 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 */
status = CyU3PUartSetConfig (&uartConfig, CyFxUartLpDmaCallback);
if (status != CY_U3P_SUCCESS )
{
/* Error handling */
CyCx3AppErrorHandler(status);
}

/* Create a DMA Manual channel between UART producer socket
and UART consumer socket */
CyU3PMemSet ((uint8_t *)&dmaConfig, 0, sizeof(dmaConfig));
dmaConfig.size = 16;
dmaConfig.count = 2;
dmaConfig.prodSckId = CY_U3P_LPP_SOCKET_UART_PROD;
dmaConfig.dmaMode = CY_U3P_DMA_MODE_BUFFER;
dmaConfig.notification = CY_U3P_DMA_CB_PROD_EVENT;
dmaConfig.cb = CyFxUartLpDmaCallback;
dmaConfig.prodHeader = 0;
dmaConfig.prodFooter = 0;
dmaConfig.consHeader = 0;
dmaConfig.prodAvailCount = 0;

/* Create the channel */
status = CyU3PDmaChannelCreate (&glUartRxChHandle,
CY_U3P_DMA_TYPE_MANUAL, &dmaConfig);
if (status != CY_U3P_SUCCESS)
{
/* Error handling */
CyCx3AppErrorHandler(status);
}

/* Set UART Tx and Rx transfer Size to infinite */
status = CyU3PUartRxSetBlockXfer(0xFFFFFFFF);
if (status != CY_U3P_SUCCESS)
{
/* Error handling */
CyCx3AppErrorHandler(status);
}

/* Set DMA Channel transfer size */
status = CyU3PDmaChannelSetXfer (&glUartRxChHandle, 0);
if (status != CY_U3P_SUCCESS)
{
/* Error handling */
CyCx3AppErrorHandler(status);
}

/* Initialize the debug application */
status = CyU3PDebugInit (CY_U3P_LPP_SOCKET_UART_CONS, 8);
if (status != CY_U3P_SUCCESS)
{
return status;
}

CyU3PDebugPreamble (CyFalse);

}

void CyFxUartLpDmaCallback (
CyU3PDmaChannel *chHandle, /* Handle to the DMA channel. */
CyU3PDmaCbType_t type, /* Callback type. */
CyU3PDmaCBInput_t *input) /* Callback status. */
{
CyU3PReturnStatus_t status;
gUartRecDataFlag = CyFalse;
if (type == CY_U3P_DMA_CB_PROD_EVENT)
{
/* This is a produce event notification to the CPU. This notification is
* received upon reception of every buffer. The buffer will not be sent
* out unless it is explicitly committed. The call shall fail if there
* is any application error. */

input->buffer_p.buffer[input->buffer_p.size] = '\0';
CyU3PDebugPrint (4, "%s", input->buffer_p.buffer);

status = CyU3PDmaChannelDiscardBuffer (chHandle);

if (status != CY_U3P_SUCCESS)
{
CyCx3AppErrorHandler (status);
}
}
}

The serial IO configuration is correct and the connection is correct. I've tested TX, Rx in register mode.Now I want to use DMA to receive data。but the the Callback function can not be called for uart rx dma of mode when the rx receive data.

0 Likes
1 Solution
YiZ_31
Moderator
Moderator

Hi,

我们SDK中有一个历程USBUart是以Uart到USB的DMA的方式实现的把串口的数据发送到PC,并且在PC端设备枚举为一个串口设备,您可以试一下这个例程观察是否可以收到数据。

View solution in original post

0 Likes
11 Replies
liuzhengxiang
New Contributor II

the system is cx3

0 Likes
JayakrishnaT_76
Moderator
Moderator

Hello,

As per my understanding, you would like to implement a UART loopback application. That is, the data obtained on the UART Rx pin of FX3 should be forwarded to the UART Tx pin of FX3. If this is the requirement, then there is an example project available already for your requirement. This example project comes along with FX3 SDK and can be found in the following location:

C:\Program Files (x86)\Cypress\EZ-USB FX3 SDK\1.3\firmware\serialif_examples\cyfxuartlpdmamode

Even if your application is slightly different with respect to the consumer socket, this example can be used as a reference. Also, it is not recommended to use UART debugging when UART pins are used for other data transfers. Please let me know if you have any queries on this.

Best Regards,
Jayakrishna
0 Likes
liuzhengxiang
New Contributor II

We plan to use Rx to receive the serial data of an external chip, and then transmit the received data through hid to other device.the callback function can not be called yet even if I close the function of debug.

CyU3PReturnStatus_t
CyCx3AppDebugInit (void)
{
CyU3PDmaChannelConfig_t dmaConfig;
CyU3PUartConfig_t uartConfig;
CyU3PReturnStatus_t apiRetStatus = CY_U3P_SUCCESS;

apiRetStatus = CyU3PUartInit ();
if (apiRetStatus != CY_U3P_SUCCESS)
{
CyFxAppErrorHandler(apiRetStatus);
}

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 */

apiRetStatus = CyU3PUartSetConfig (&uartConfig, NULL);
if (apiRetStatus != CY_U3P_SUCCESS )
{
CyFxAppErrorHandler(apiRetStatus);
}

CyU3PMemSet ((uint8_t *)&dmaConfig, 0, sizeof(dmaConfig));
dmaConfig.size = 16;
dmaConfig.count = 4;
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 = CyFxUartLpDmaCallback;
dmaConfig.prodHeader = 0;
dmaConfig.prodFooter = 0;
dmaConfig.consHeader = 0;
dmaConfig.prodAvailCount = 0;
apiRetStatus = CyU3PDmaChannelCreate (&glUartRxChHandle,CY_U3P_DMA_TYPE_MANUAL_IN, &dmaConfig);
if (apiRetStatus != CY_U3P_SUCCESS)
{
CyFxAppErrorHandler(apiRetStatus);
return apiRetStatus;
}

apiRetStatus = CyU3PUartTxSetBlockXfer(0xFFFFFFFF);
if (apiRetStatus != CY_U3P_SUCCESS)
{
CyFxAppErrorHandler(apiRetStatus);
}

apiRetStatus = CyU3PUartRxSetBlockXfer(0xFFFFFFFF);
if (apiRetStatus != CY_U3P_SUCCESS)
{
CyFxAppErrorHandler(apiRetStatus);
}

apiRetStatus = CyU3PDmaChannelSetXfer (&glUartRxChHandle, 0);
if (apiRetStatus != CY_U3P_SUCCESS)
{
return apiRetStatus;
}

#if 0

/* Initialize the debug module. */

apiRetStatus = CyU3PDebugInit (CY_U3P_LPP_SOCKET_UART_CONS, 8);

if (apiRetStatus != CY_U3P_SUCCESS)

{

CyFxAppErrorHandler(apiRetStatus);

}

CyU3PDebugPreamble (CyFalse);

#endif

return apiRetStatus;

}

void CyFxUartLpDmaCallback (
CyU3PDmaChannel *chHandle, /* Handle to the DMA channel. */
CyU3PDmaCbType_t type, /* Callback type. */
CyU3PDmaCBInput_t *input) /* Callback status. */
{
CyU3PReturnStatus_t status;
gUartRecDataFlag = CyFalse;
if (type == CY_U3P_DMA_CB_PROD_EVENT)
{
/* This is a produce event notification to the CPU. This notification is
* received upon reception of every buffer. The buffer will not be sent
* out unless it is explicitly committed. The call shall fail if there
* is any application error. */

//input->buffer_p.buffer[input->buffer_p.size] = '\0';
//CyU3PDebugPrint (4, "%s", input->buffer_p.buffer);

status = CyU3PDmaChannelDiscardBuffer (chHandle);

if (status != CY_U3P_SUCCESS)
{
CyCx3AppErrorHandler (status);
}
}
}

0 Likes
JayakrishnaT_76
Moderator
Moderator

Hello,

Please let us know the following to debug the issue further:

1. The amount of data sent from the UART transmitter to FX3 UART Receiver in bytes.

2. Please share the complete source code for us to check at our end. Please let me know if you want to share the source code privately without posting it in this forum.

Best Regards,
Jayakrishna
0 Likes
liuzhengxiang
New Contributor II

dear:

I found a phenomenon。when I receive the data of imu(another chip,IMU data is also received through interrupt response) , if I change the receive function to inline function,I will receive the uart data by rx.

0 Likes
liuzhengxiang
New Contributor II

dear:

I found a phenomenon。when I receive the data of imu(another chip,IMU data is also received through interrupt response) , if I change the receive function to inline function,the callback function of uart can be called and can receive the uart data by rx.

0 Likes
JayakrishnaT_76
Moderator
Moderator

Hello,

Please let us know what exactly did you mean by the receive function? Is IMU another UART Transmitter connected to FX3?

Also, please let us know your comments to my questions in my previous response.

Best Regards,
Jayakrishna
0 Likes
YiZ_31
Moderator
Moderator

Hi,

我们SDK中有一个历程USBUart是以Uart到USB的DMA的方式实现的把串口的数据发送到PC,并且在PC端设备枚举为一个串口设备,您可以试一下这个例程观察是否可以收到数据。

View solution in original post

0 Likes
liuzhengxiang
New Contributor II

现在已经解决了,谢谢

0 Likes