AnsweredAssumed Answered

Why doesn't scheduling buffers for the next usb receive event work for the first packet?

Question asked by Daniel Hillstead on Sep 30, 2013
Latest reply on Nov 8, 2013 by Daniel Hillstead

I am using CW10.2, MQX 4.0.0.

I added functionality to to the MQX USB Device HID driver to receive data on a HID OUT Endpoint.  I used example code from the CDC driver to do this.  AN4345.pdf is one example.  And it works pretty well.  The sample code for the receive callback is the following:

if((event_type == USB_APP_DATA_RECEIVED)&&(start_transactions == TRUE))




     BytesToBeCopied = dp_rcv->data_size;


     for(index = 0; index < BytesToBeCopied; index++)




          g_curr_recv_buf[index] = dp_rcv->data_ptr[index];





     /* Schedule buffer for next receive event */


     USB_Class_CDC_Recv_Data(handle, DIC_BULK_OUT_ENDPOINT, g_curr_recv_buf, DIC_BULK_OUT_ENDP_PACKET_SIZE);



Copying the data_ptr to the local buffer only seems to be needed for the first packet received.  After that the copy is not needed because the USB_Class_CDC_Recv_Data() call passes the g_curr_recv_buf pointer into the MQX driver to receive the data.  So it seems to me that the USB_Class_CDC_Recv_Data() call should be able to be made before the first received packet (say after the enumeration event callback) and then the copy would not be needed.  However when I did this, the callback for the first packet is not called at all.  Is there a reason this doesn't work?  Am I required to copy the data everytime even though the data in g_curr_recv_buf & dp_rcv->data_ptr is equal after the first packet?