USB-CDC to UART bridge application for PSoC6

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

cross mob
riteshEB
Level 1
Level 1
First like received 5 replies posted 10 sign-ins

Is there any sample application available for PSoC6 device in Modus Toolbox IDE which demonstrate USB-CDC to UART bridge functionality.

I have created an application and its working but I am facing reliability issues with higher frame size and higher data transmission rate. 

How to use SCB UART with RX DMA when receive frame size is not fixed? 

Can i use emUSB-device cdc with DMA? 

 

0 Likes
6 Replies
Ekta_N
Moderator
Moderator
Moderator
750 replies posted First like given 250 solutions authored

Hi @riteshEB 

We do not have a combined application with both USB-CDC and UART functionality in the same application but there are separate code examples for each of them:

1. https://github.com/Infineon/mtb-example-psoc6-usb-cdc-echo
2. https://github.com/Infineon/mtb-example-psoc6-uart-transmit-receive-dma

Could you provide more information regarding your application? I guess as per your question that you would be receiving data via USB port (using CDC class) and are transferring that data to the UART FIFO.

Is the size of data coming via USB variable? How is it decided that the data needs to be transferred to the UART fifo?

What is the issue you are facing with higher frame size and data rates? Based on this we could suggest possible solutions to the issue?

How to use SCB UART with RX DMA when receive frame size is not fixed: Based on the appliation it might be possible to configure the chain two DMAs to do byte by byte when we have data in the UART FIFO and disable the DMA when the data is not there.

Can i use emUSB-device cdc with DMA?
Do you mean if you could use the PSoC 6 USB device (configured for CDC class) with DMA - yes it is possible to do so.


Best Regards
Ekta

 

 

0 Likes

Hi @Ekta_N ,

Thanks for the reply.

My application is like 2x USB to UART bridge. USB is configured with 2 CDC instances. Each USB CDC instance is associated with one UART port for bridge application. Receiving data via USB port (using CDC class) and are transferring that data to the UART FIFO and vice versa. So data coming from USB as well as UART is variable. 


configure the chain two DMAs to do byte by byte when we have data in the UART FIFO and disable the DMA when the data is not there.

How can i check whether data is not there? enable a timer and check dma register? It would be nice if you could share some code snippet? 

use the PSoC 6 USB device (configured for CDC class) with DMA - yes it is possible to do so.

Can you share some detail how to configure? As there is not additional configuration available for emUSB-Device driver.  Can I use DMA directly for USB CDC RX to UART TX and UART RX to USB CDC TX?

riteshEB_2-1672641222168.png

0 Likes
RodolfoGL
Employee
Employee
250 solutions authored 250 sign-ins 5 comments on KBA

Can you elaborate a bit more about your "reliability issues" with higher frame size and higher data transmission rate?

The emUSB-device CDC is limited to 64 bytes, so if the host sends a packet with more than 64 bytes, the driver will split it in chunks of 64 bytes.

Because of that, it might not be worth to use the DMA, since the time it takes to setup the DMA and trigger it, will be the same as writing/reading a few bytes to/from the UART FIFO.

The USB will be probably the bottle neck in your application, specially if you are transmitting with UART at higher than 1Mbps. 

0 Likes

Hi @RodolfoGL ,

Test case I am using to evaluate my Dual USB to UART bridge driver application: 

EVKCY8CKIT-062S2-43012

USB Configuration: 2 CDC interface (emUSB-Device library) (Connected USB port of EVK to host PC)

USB Tx API: USBD_CDC_Write(usb_cdcHandle[port], pData, length, -1);

USB Rx API: USBD_CDC_Receive(usb_cdcHandle[port], pData, length, -1):

UART Configuration: 2 UART port SCB0 & SCB1 (115200 baud) (Connected with host PC using 2 USB to UART module)

UART Tx using DMA

UART Rx API: Cy_SCB_UART_GetArray(UART_0_HW, pData, length);

Host PC : 2 USB CDC COM ports and 2 UART COM ports are open in PC using serial terminal applications. Each CDC port is associated with single UART port for bridge application.

Test Scenarios:

  1. Single byte transfer using teraterm:  Working Fine
  2. Sending 4KB file using Hercules terminal app: Working fine
  3. Modbus Master Slave communication:
    1. both UART com port as Modbus master & both USB CDC com port as Modbus Slave: Working Fine
      • Reading 125 Holding register with 1ms scan rate (255 Bytes)
      • UART Rx 8 Bytes
        USB Tx 8 Bytes
           
        USB Rx 255 Bytes
        UART Tx 255 Bytes
    2. both USB CDC com port as Modbus Master & both UART com port as Modbus Slave: Having Issues
      • Issue 1: Reading 10 Holding register with 100ms scan rate (25 Bytes). sometimes getting timeout for Modbus request. (1 timeout in 20-30 request). At timeout condition, USBD_CDC_Write() seems not transmitting any data. I have verified this using serial port analyzer tool.
      • USB Rx 8 Bytes
        UART Tx 8 Bytes
           
        UART Rx 25 Bytes
        USB Tx 25 Bytes
      • Issue 2: Reading 30-125 Holding Register  (65 to 255 Bytes): MCU soft reset or CDC port hangs (not getting any CDC Rx or Tx data)

I have tried various CDC blocking not blocking APIs also added WaitFor() APIs but getting the same  behaviors. 

Let me know if you want any further clarification. 

0 Likes
RodolfoGL
Employee
Employee
250 solutions authored 250 sign-ins 5 comments on KBA

At least on the original mtb-example-usb-device-cdc-echo, I find that sending more than 64 bytes make the device irresponsive. After some debugging, we need to place some overflow check on the write buffer.

Perhaps review your code to see if any overflow condition on the write buffer is occurring. 

I internally filed a ticket to get the code example fixed.

0 Likes

I have already checking  'if (USBD_CDC_GetNumBytesRemToWrite(usb_cdcHandle[port]) == 0)' before 'USBD_CDC_Write(usb_cdcHandle[port], pData, length, -1); '

Is there any other checks i need to add?

 

I have another question. 

My application end goal is to have 4 USB CDC interfaces and 4 UARTs. So each pair of USB and UART will work as a bridge application on CY8CKIT-062S2-43012 EVK. 
 
But according to our findings PSoC62 only supports 8 data endpoints and one control endpoint. One CDC interface requires 3 USB endpoints - one interrupt IN endpoint, one bulk OUT and one bulk IN, meaning i can initialize maximum two CDC interfaces. Can you confirm this?
If i try to add more than 2 CDC interfaces i am getting below error.
0:000 PANIC: Could not allocate endpoint (you can increase USB_NUM_EPS)
Another approach would be to use Vendor Specific Class (VSC), with 4 Bulk OUT Endpoints & 4 Bulk IN Endpoints instead of CDC class. This should be technically supported by the PSoC62 USB controller as 8 Endpoints are available. but we are able to create a maximum of 3 VSC interfaces. If I try to add a 4th Interface, I am getting the below error. 
0:000 PANIC: Could not allocate endpoint (you can increase USB_NUM_EPS)

Is there any way that i can get have 4 Bulk OUT Endpoints & 4 Bulk IN Endpoints in PSoC62 using emUSB-device?

0 Likes