CDC_BulkIn in USB CDC Example?

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by ktownsend on Mon Jan 10 03:46:50 MST 2011
I've been trying to get the USB CDC example working dependably, and the only way I've found so far is a shameless hack that's too slow and ugly for production use.

The board instantiates properly as a USB CDC device, and receiving data on the LPC1343 works fine (CDC_BulkOut in cdcuser.c), but CDC_BulkIn never seems to get called by itself to send buffered data out. The only 'solution' I've found is the following, which requires a huge delay to work:

extern void usbcdcSendByte(uint8_t c)
  // Massive ugly delay required
  uint32_t i, delay;
  delay = ((CFG_CPU_CCLK/SCB_SYSAHBCLKDIV) / 25000);
  for ( i = 0; i < delay; i++ )
  // Send byte to EP
  USB_WriteEP (CDC_DEP_IN, (unsigned char *)&c, 1);
  CDC_DepInEmpty = 1;

Without the delay and manually writing to the EP, the output drops about 80% of the characters, but with the delay it's too hopelessly slow to do anything useful. Is there something evident I should be doing to get CDC_BulkIn to fire automatically, check the buffer and send data out by itself?

I would have expected to just make a buffer (instead of UART in the sample code), write to the buffer as required, and BulkIn would fire to output the buffered data on a regular basis. Obviously I've completely misunderstood how CDC_BulkIn works, but where should this method be called from then or when would be the appropriate time to check and empty buffered data into the EP?