NOTICE: This website will be shut down in the near future. Product content has moved to Forum content and FAQs have been moved to We encourage you to create a user account on to use the new community forums and access NXP microcontroller content. We greatly appreciate your contributions and look forward to seeing you at our new web location.


USB ROM API bulk OUT endpoint problem

1 reply [Last post]
Joined: 2012-08-27
Posts: 71

Having ported an application from NXPUSBLib to the USB ROM API runs me into trouble when transferring large amounts of data from the host (PC) to the device (LPC4357) using bulk transfers.

I set up a read request using :

int32_t libusbdev_Read_DataEp(uint8_t *pBuf, uint32_t buf_len)
    int32_t ret = -1;

    /* Queue read request  */
    if (libusbdev_QueueReadReq_DataEp(pBuf, buf_len) == LPC_OK) {
        /* wait for Rx to complete */
        while ( (ret = libusbdev_QueueReadDone()) == -1) {
            /* Sleep until next IRQ happens */

    return ret;

ErrorCode_t libusbdev_QueueReadReq_DataEp(uint8_t *pBuf, uint32_t buf_len)
    LUSB_CTRL_T *pUSB = (LUSB_CTRL_T *) &g_lusb;
    ErrorCode_t ret = ERR_FAILED;

    /* Check if a read request is pending */
    if (pUSB->pRxBuf == 0) {
        /* Queue the read request */
        pUSB->pRxBuf = pBuf;
        pUSB->rxBuffLen = buf_len;
        USBD_API->hw->ReadReqEP(pUSB->hUsb, LUSB_DATAOUT_EP, pBuf, buf_len);
        ret = LPC_OK;

    return ret;

int32_t libusbdev_QueueReadDone(void)
	LUSB_CTRL_T *pUSB = (LUSB_CTRL_T *) &g_lusb;

	/* A read request is pending */
	if (pUSB->pRxBuf) {
		return -1;
	/* if data received return the length */
	return pUSB->rxBuffLen;

And the endpoint handler looks like this:

ErrorCode_t lusb_BulkDataOUT_Hdlr(USBD_HANDLE_T hUsb, void *data, uint32_t event)
    LUSB_CTRL_T *pUSB = (LUSB_CTRL_T *) data;
    int32_t receivedBytes;

    /* We received a transfer from the USB host. */
    if (event == USB_EVT_OUT) {
        pUSB->rxBuffLen = USBD_API->hw->ReadEP(hUsb, LUSB_DATAOUT_EP, pUSB->pRxBuf);
        pUSB->pRxBuf = 0;
    return LPC_OK;

The host tries to send data continioulsy (or at least untill all data is send). The problem is that it can send data without having to wait for the device to be ready to receive the next data chunk. Using NXPUSBLib this was no problem at all. How can I prevent the host from sending, e.g. locking the device from receiving data?

Maybe good te mention: the SysTick_Handler is doing a read request every 1ms but for another endpoint (a command endpoint). This is probably not relevant for the problem.

How can I solve this? The USB ROM documentatin is very minimal.

Your rating: None

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
SeleneSW's picture
Joined: 2012-06-19
Posts: 16

Hi wlamers,

In your lusb_BulkDataOUT_Hdlr function you do an USBD_API->hw->ReadEP call, this call empties the USB peripheral buffer, and so it will be ready to recieve new data.
You could do a check if you already read the data in the pUSB->pRxBuf buffer, and if not, you could skip the USBD_API->hw->ReadEP call for now, and you'll do it later when you are ready to recieve.