Problem with subsequent calls to WriteEp

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

Problem with subsequent calls to WriteEp

374 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by giedrius on Mon Jul 08 09:18:48 MST 2013
Hi,

I am working with LPC11U37 chip. I have somewhat modified USB CDC example (VCOM removed, more buffering added) and everything is running fine except when two subsequent calls to pUsbApi->hw->WriteEP are made. Calling WriteEP twice one after another causes undefined behavior in the data delivered to the PC - most of the time only the data specified in the second call is received on the PC and other times all data is lost.

Is it incorrect to call WriteEp, do a tiny or no pause, and call it again? If so, how can I check if it is safe to call WriteEp?

Thanks!
0 Kudos
Reply
2 Replies

281 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by giedrius on Tue Jul 09 00:11:44 MST 2013
Thanks, it explains even more than was needed.

Solved!
0 Kudos
Reply

281 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Tsuneo on Mon Jul 08 10:29:32 MST 2013
WriteEP() should not be called again, until the data on the IN endpoint has been sent out.
When the endpoint finishes a transaction, a completion interrupt occurs.
After seeing this interrupt, your firmware calls next WriteEP().

Are you working on USB_ROM_CDC example in this code bundle?
"Sample Code Bundle for LPC11Uxx Peripherals using LPCXpresso"
http://www.lpcware.com/content/nxpfile/sample-code-bundle-lpc11uxx-peripherals-using-lpcxpresso

In this example, VCOM_bulk_in_hdlr() callback is registered as the completion callback of the bulk IN endpoint,
\USB_ROM_CDC\src\main.c

int main (void)
{
      ...
      /* register endpoint interrupt handler */
      ep_indx = (((USB_CDC_EP_BULK_IN & 0x0F) << 1) + 1);
      ret = pUsbApi->core->RegisterEpHandler (hUsb, ep_indx, VCOM_bulk_in_hdlr, &g_vCOM);


You may use this callback to know the timing when the last transaction finishes.
In this example, VCOM_bulk_in_hdlr() is an empty routine.
\USB_ROM_CDC\src\main.c

ErrorCode_t VCOM_bulk_in_hdlr(USBD_HANDLE_T hUsb, void* data, uint32_t event) 
{
  //VCOM_DATA_T* pVcom = (VCOM_DATA_T*) data;
//  Not needed as WriteEP() is called in VCOM_usb_send() immediately.  
//  if (event == USB_EVT_IN) {
//  }
  return LPC_OK;
}


If you wouldn't use g_vCOM.send_fn, you should fill it with some code, like,
a) Send the next and latter packets with WriteEP(), to send a data block (transfer) greater than 64 bytes.
or
b) raise a flag which shows that the endpoint is available again.

Tsuneo
0 Kudos
Reply