Hello
I have programmed a custom USB interface for a LPC1778. To send and receive data I used bulk transfer. Actually, everything works fine, but I have problems when receiving data packets > USB_FS_MAX_BULK_PACKET (= 64) bytes. A complete message can then consist of several 64 byte USB data packets. My problem is, that I do not know when the complete USB message was received and can be processed. In most cases, the length of the last data packet will be != 64 bytes and the data can be concatenated until then. But this works only as long as the whole package is not a multiple of 64.
Does anyone have any idee?
/* USB bulk EP_OUT endpoint handler */
ErrorCode_t lusb_BulkOUT_Hdlr(USBD_HANDLE_T hUsb, void *data, uint32_t event)
{
/* We received a transfer from the USB host. */
switch (event)
{
case USB_EVT_OUT:
usb_rx_length = USBD_API->hw->ReadEP(hUsb, LUSB_OUT_EP, usb_rx_buffer + usb_rx_byte_counter);
if (usb_rx_length < USB_FS_MAX_BULK_PACKET){ // only works if total packet size is not nultiple of 64!
usb_rx_bulk_out_ready = 1;
}
usb_rx_byte_counter += usb_rx_length;
usb_rx_bulk_counter++;
break;
case USB_EVT_OUT_NAK:
break;
}
return LPC_OK;
}