USB ROM CDC without UART Bridge

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

USB ROM CDC without UART Bridge

1,369 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by shikarm@identisoft.net on Tue Nov 12 07:59:38 MST 2013
Hi,

I am using the USB ROM echo example for a CDC in Keil.
see http://www.lpcware.com/content/nxpfile/sample-code-bundle-lpc11uxx-peripherals-using-keils-mdk-arm-0

Everything  works fine. I can send and receive data on both the serial port and USB VCOM port. :D

I also managed to integrate my application to work with this example and can receive and send data using the USB API.  Basically, I modified the CDC example to push data received on USB bulk out into my application comms. buffer and then my application uses writeEP and if necessary multiple calls to the VCOM_bulk_in_hdlr interrupt to send data  > 64 bytes.


My problem comes when I try and remove the UART Bridge code. If I comment it out, the compiler complains about the UART_IRQHandler() referencing uart_read() and uart_write(). So I comment out UART_IRQHandler() and the compiler passes the compile and I program my unit.

I have a problem when the device tries to respond with more than 64 bytes of data. I send the first message from PC to device, I get a reply. However, when I attempt to send a second message from PC to device, the VCom port freezes. There is no reply from the device.
If I leave the orginal UART Bridge code in, everything works!  :p

Did anyone else try removing the UART from the example? It's clear to me that the UART routines does something that keeps the USB working continuously. Anyone have any idea how the original example can be modified to work without the UART code?

Thanks,

Shikar

Labels (1)
0 Kudos
Reply
4 Replies

1,258 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by liaochengyi on Thu Nov 21 00:38:46 MST 2013
Hi, Shikar,

Thank you for the response. It's useful.

I found the example http://www.lpcware.com/content/forum/using-writeep-function-usb-rom-drivers-lpcopen

The example is good for write data to host.
The original sample code has some problem when continue to WriteEP.

The VCOM_bulk_in_hdlr() is the callback of write data to host....

Thank you & good luck.
Best regards,
Kevin
0 Kudos
Reply

1,258 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by shikarm@identisoft.net on Sun Nov 17 23:31:45 MST 2013

Quote: liaochengyi
Hi, Shikar

I am using the USB_ROM_CDC example to do something, too.
But I can't understand the functionality of UART_BRIDGE.

What is the different between with or without UART_BRIDGE.
Would you please help to explain that?

Thank you very much.
Best regards,
Kevin


Hi Kevin,

I am also new at this. Basically the example given my NXP allows you to send data on the USB Virtual Comm port and then the same data is echoed out on a UART on the chip. So basically its a "bridge" that allows data to flow between the USB Virtual Comm port and a standard UART port on the processor.

By commenting out the #define UART_BRIDGE, the aim is to remove the need to echo out the data received via USB onto the UART. If you are developing any product with CDC, it's most likely you are only interested in processing data on the USB VCOM port. The UART pins may be used for some other purpose already or you would want to remove the extra code needed to configure and send data on the UART.

I did battle with the USB stack for a week, but eventually it seems to be working with code I posted above to modify the CDC example for the CDC USB ROM driver example. One thing to be careful of, is the example defines USB stack @usb_param.mem_base = 0x10001000 and usb_param.mem_size=0x1000, which is right in the middle of SRAM. Since I was using the LPC11U24FHN, I changed it to mem_base = 0x20004000 and mem_size=0x800, to free up the RAM. Note the USB RAM is only 0x800 only.

If you have the CDC example working on your development then you have a good start. Hope this helps you!

Good luck!
0 Kudos
Reply

1,258 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by liaochengyi on Sun Nov 17 20:54:39 MST 2013
Hi, Shikar

I am using the USB_ROM_CDC example to do something, too.
But I can't understand the functionality of UART_BRIDGE.

What is the different between with or without UART_BRIDGE.
Would you please help to explain that?

Thank you very much.
Best regards,
Kevin
0 Kudos
Reply

1,258 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by shikarm@identisoft.net on Tue Nov 12 08:14:57 MST 2013
Nevermind, my problem was I forget to set pVcom->rxlen = 0 in the send routine. I hope it's right. I will post the functions used for sending. If anyone can confirm I am doing this right?

//------------------------------------------------------------------------
// Name        : sendMessageUSB
// Description : send a message out via the USB

void sendMessageUSB(unsigned char* buf, int len)
{
volatile VCOM_DATA_T* pVcom = &g_vCOM;
int sentBytes;

if (len <= USB_HS_MAX_BULK_PACKET) {
pUsbApi->hw->WriteEP (pVcom->hUsb, USB_CDC_EP_BULK_IN, buf, len); 
pVcom->txlen = 0;
pVcom->rxlen = 0;
}
else {
sentBytes = pUsbApi->hw->WriteEP (pVcom->hUsb, USB_CDC_EP_BULK_IN, buf, USB_HS_MAX_BULK_PACKET); 
pVcom->txBuf = buf + sentBytes;
pVcom->txlen = len - sentBytes;
pVcom->rxlen = 0;
}
}


//------------------------------------------------------------------------
// Name        : VCOM_bulk_in_hdlr
// Description : receive data bulk event for usb

ErrorCode_t VCOM_bulk_in_hdlr(USBD_HANDLE_T hUsb, void* data, uint32_t event)
{
volatile VCOM_DATA_T* pVcom = &g_vCOM;
int len;
int sentBytes;

  if (event == USB_EVT_IN) {

len = pVcom->txlen;
if (len > 0) {
if (len > USB_HS_MAX_BULK_PACKET) len = USB_HS_MAX_BULK_PACKET;
sentBytes =pUsbApi->hw->WriteEP(pVcom->hUsb, USB_CDC_EP_BULK_IN, pVcom->txBuf, len); 
pVcom->txBuf += sentBytes;
pVcom->txlen -= sentBytes;
}
// else{
// pVcom->txlen = 0;
// pVcom->rxlen = 0;
// }
  }
  return LPC_OK;
}


0 Kudos
Reply