USB ROM API bulk OUT endpoint problem

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

USB ROM API bulk OUT endpoint problem

891件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by wlamers on Tue Jun 03 07:17:47 MST 2014
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 */
            __WFI();
        }
    }

    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.

ラベル(1)
  • USB

0 件の賞賛
返信
1 返信

760件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by SeleneSW on Wed Dec 30 09:38:39 MST 2015
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.
0 件の賞賛
返信