Content originally posted in LPCWare by [email protected] on Thu Aug 13 03:55:00 MST 2015 Hi,
I currently can communicate via Endpoint 1, 2 and 4 but have a problem receiving data via the Endpoint 3 using the LPC1837 with its USB stack.
I do see the endpoint interrupt getting triggered on the USB_EVT_OUT_NAK event but never on the USB_EVT_OUT event.
Only when I manually insert a "USBD_API->hw->ReadReqEP(pUSB->hUsb, EPC, ptyRxData->pucDataBuf, 0x400);" instruction in the interrupt handler on the USB_EVT_OUT_NAK event, I will get the USB_EVT_OUT event.
I tried to manually enable and reset the endpoint but it didn't help.
Does someone know why the USB stack doesn't automatically send the read request? What does it depend on?
This is my initialisation code:
int init_usb(uint32_t memBase, uint32_t memSize) { USBD_API_INIT_PARAM_T usb_param; USB_CORE_DESCS_T desc; ErrorCode_t ret = LPC_OK; USB_CORE_CTRL_T *pCtrl;
/* enable clocks and USB PHY/pads */ Chip_USB0_Init();
/* Init USB API structure */ g_pUsbApi = (const USBD_API_T *) LPC_ROM_API->usbdApiBase;
/* Set the USB descriptors */ desc.device_desc = (uint8_t *) USB_DeviceDescriptor; desc.string_desc = (uint8_t *) USB_StringDescriptor; desc.high_speed_desc = USB_HsConfigDescriptor; desc.full_speed_desc = USB_FsConfigDescriptor; desc.device_qualifier = (uint8_t *) USB_DeviceQualifier;
/* USB Initialization */ ret = USBD_API->hw->Init(&g_lusb.hUsb, &desc, &usb_param); if (ret == LPC_OK) { /*WORKAROUND for artf45032 ROM driver BUG: Due to a race condition there is the chance that a second NAK event will occur before the default endpoint0 handler has completed its preparation of the DMA engine for the first NAK event. This can cause certain fields in the DMA descriptors to be in an invalid state when the USB controller reads them, thereby causing a hang. */ pCtrl = (USB_CORE_CTRL_T *) g_lusb.hUsb; // convert the handle to control structure g_Ep0BaseHdlr = pCtrl->ep_event_hdlr[0]; // retrieve the default EP0_OUT handler pCtrl->ep_event_hdlr[0] = EP0_patch; // set our patch routine as EP0_OUT handler
/* register WCID handler */ ret = USBD_API->core->RegisterClassHandler(g_lusb.hUsb, WCID_hdlr, &g_lusb); if (ret == LPC_OK) { // register EPA interrupt handler ret = USBD_API->core->RegisterEpHandler(g_lusb.hUsb, 2, EPA_Hdlr, &g_lusb); //EPA = 0x01 => (2 x 1) if (ret == LPC_OK) { // register EPB interrupt handler ret = USBD_API->core->RegisterEpHandler(g_lusb.hUsb, 5, EPB_Hdlr, &g_lusb); //EPB = 0x02 => (2 x 2) + 1 if (ret == LPC_OK) { // register EPC interrupt handler ret = USBD_API->core->RegisterEpHandler(g_lusb.hUsb, 6, EPC_Hdlr, &g_lusb); //EPC = 0x03 => (2 x 3) if (ret == LPC_OK) { // register EPD interrupt handler ret = USBD_API->core->RegisterEpHandler(g_lusb.hUsb, 9, EPD_Hdlr, &g_lusb); //EPD = 0x04 => (2 x 4) + 1 if (ret == LPC_OK) { NVIC_EnableIRQ(LPC_USB_IRQ);/* enable USB interrrupts */