AnsweredAssumed Answered

USB device API Interrupt in OS-less Environment

Question asked by penguin007 on Jul 23, 2015
Latest reply on Mar 10, 2016 by Kader.M

I want to implement a basic USB-device firmware on the BF527 processor. RTOS is not used and won't be used. IDE is CCES At the moment the control transfer doesn't work well, because the device doesn't send DATA0 packet (device descriptor) in the data stage. I'm 100% sure, because I verified this via ellisys USB explorer tool. During the SETUP stage 8 bytes is received correclty and acked by the device. During the DATA stage only IN packet from host is measured. Here is the detailed description:


the APIs in main() function:


result = adi_musbmhdrc_Init(&hUsbDevice, &InitData);


//register callback functions, these callback functions are written by me

adi_musbmhdrc_RegisterEpZeroCallback(hUsbDevice, adi_usbdrvd_EpZeroCallback);

adi_musbmhdrc_RegisterEpDataCallback(hUsbDevice, adi_usbdrvd_EpDataCallback);

adi_musbmhdrc_RegisterBusEventCallback(hUsbDevice, adi_usbdrvd_BusEventCallback);


result = adi_musbmhdrc_EP_Open (hUsbDevice, &EP0Descriptor, 0);


result = adi_musbmhdrc_Start((ADI_USB_HANDLE)pUsbData);


At this point I believe that USB communication starts. By setting breakpoints, I noticed that 8 bytes SETUP data is received correctly by the device, and device acknowledged. This is done within the adi_usbdrvd_Ep0Handler() -- case ADI_USB_SETUP_IDLE -- function adi_usbdrv_HandleSetupPacket().


After that adi_usbdrv_DmaHandler() is called. Within adi_usbdrv_Ep0DmaHandler the user defined callback adi_usbdrvd_EpZeroCallback is called.


Then, Immediately after exit adi_usbdrv_DmaHandler(), ISR EP0 is triggered: adi_usbdrvd_Ep0Handler() -- case ADI_USB_SETUP_DATA  -- adi_usbdrv_SetupDataHandler(). The problem is here: I don't have time to fill the URB in EP0. The URB pointer is set to NULL within adi_usbdrv_Ep0DmaHandler. Then after exit DMA ISR, the program immediately enters the EP0 ISR -- DATA  stage, leaving me no time to fill the URB data with device descriptor.


How to solve this problem? May be some interrupt should be disabled before filling URB and enabled after filling URB?


2nd question: DMA ISR seems to be unnecessary here, since the 8 bytes setup data is fetched via the function adi_usbdrv_RcvDataFromFifo() within the adi_usbdrvd_Ep0Handler() -- case ADI_USB_SETUP_IDLE -- function adi_usbdrv_HandleSetupPacket().


3rd question: how to use adi_musbmhdrc_SubmitURB() API? Could ADI engineers write a documentation how to use those USB APIs in OS-less environment, please. It would be best to provide an example requireing no RTOS, one is enough!