LPC4357 Bulk IN Endpoint Hangs

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

LPC4357 Bulk IN Endpoint Hangs

497 Views
davebyman
Contributor I

I am using libusbdev on a custom board with the LPC4357.  I am using USB0 with one Bulk IN endpoint and one Bulk OUT endpoint.  Sometimes the USB will run fine and send data continuously for several days but randomly I experience a hang.  I call libusbdev_QueueSendReq() to send a packet on the IN endpoint and it returns LPC_OK.  After this I check libusbdev_QueueSendDone() continuously until it returns 0.  (My code for these functions is shown below.)  When the hang occurs pUSB->txBuffLen is never changed from the initial packet size of 880 bytes, indicating the packet was never sent.  

I have also confirmed with a USB analyzer that the last packet attempted before the hang was never sent.  The analyzer sees the normal number on NAKs after the last successful packet and then goes silent with no reported errors or further NAKs.

Because the USB ROM code is not easily accessible for debugging I am at a loss for where to look next.

libisbdev_QueueSendReq:

/* Queue the given buffer for transmision to USB host application. */
ErrorCode_t libusbdev_QueueSendReq(uint8_t *pBuf, uint32_t buf_len)
{
     LUSB_CTRL_T *pUSB = (LUSB_CTRL_T *) &g_lusb;
     ErrorCode_t ret = ERR_FAILED;

     /* Check if a write request is pending */
     if (pUSB->pTxBuf == 0) {
          /* Queue the write request */
          pUSB->pTxBuf = pBuf;
          pUSB->txBuffLen = buf_len;

          uint32_t bytes_written = USBD_API->hw->WriteEP(pUSB->hUsb, LUSB_IN_EP, pBuf, buf_len);
          if( bytes_written == buf_len )
          {
               ret = LPC_OK;
          }
     }

     return ret;
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

libusbdev_QueueSendDone:

/* Check if queued send is done. */
int32_t libusbdev_QueueSendDone(void)
{
LUSB_CTRL_T *pUSB = (LUSB_CTRL_T *) &g_lusb;
/* return remaining length */
return pUSB->txBuffLen;
}

App Code:

// queue send request 
if(libusbdev_QueueSendReq((uint8_t*)(usb_tx_buffer), g.txUSBPacket[g.txUSBTail].sz) == LPC_OK)
{
     while(libusbdev_QueueSendDone() != 0) osThreadYield(); // <--- hangs here as libusbdev_QueueSendDone() always returns 880 bytes
}

USB0 Registers after the hang (in case this is useful)

usb0_peripheral.png

Labels (4)
0 Kudos
1 Reply

326 Views
jeremyzhou
NXP Employee
NXP Employee

Hi Dave Byman,

Thank you for your interest in NXP Semiconductor products and 
for the opportunity to serve you.
I was wondering if you can share the testing demo and exemplify the steps of replicating the issue.
It can help me to figure the root cause of the issue.
I'm looking forward to your reply.
Have a great day,

TIC

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos