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;
}