This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

usb_dev_bulk: need to re-register BulkTickHandler?

Other Parts Discussed in Thread: AM1808

Questions about the library code - AM1808 StarterWare 1.00.03.03 example application usb_dev_bulk

Summary

  • InternalUSBRegisterTickHandler() is called before USBDCDinit()
  • thus, no tick handlers are registered
  • why does this still work?? (i.e., is this a "benign" bug, or am I missing something?)

Details

Control flow in StarterWare

  1. main() invokes usbdbulk.c / USBDBulkInit()
  2. USBDBulkInit() invokes usbdbulk.c / USBDBulkCompositeInit()
  3. USBDBulkCompositeInit() invokes usbtick.c / InternalUSBRegisterTickHandler()
  4. InternalUSBRegisterTickHandler(USB_TICK_HANDLER_DEVICE, BulkTickHandler, psDevice)
    - this registers usbdbulk.c / BulkTickHandler() as the device mode tick handler
  5. USBDBulkCompositeInit() returns.
  6. USBDBulkInit() invokes usbdenum.c / USBDCDInit()
  7. USBDCDInit() invokes usbtick.c / InternalUSBTickInit()
  8. InternalUSBTickInit() erases the tick handler table, g_pfTickHandlers!

Why does this code still work correctly??  I am running the USB bulk device with usb_bulk_example.exe, and my PC and development board are communicating correctly...Is the tick handler just required to handle some exceptional cases that I'm not seeing with this simple test?  See http://processors.wiki.ti.com/index.php/StarterWare_USB#Running_the_Example_Application

The source code even states (usbdbulk.c / USBDBulkCompositeInit())
    //
    // Register our tick handler (this must be done after USBDCDInit).
    //
    InternalUSBRegisterTickHandler(USB_TICK_HANDLER_DEVICE,
                                   BulkTickHandler,
                                   (void *)psDevice);

Further examination of usbdbulk.c / BulkTickHandler(): the only non-trivial operation is to invoke g_sBulkDevice.pfnRxCallback == usbbuffer.c / USBBufferEventCallback() in the event of a "deferred receive".  Why is it okay to neglect this?  I guess I'm not encountering any deferred receives during testing, but will this remain true in a production scenario?

Thank you!!

Reference
http://processors.wiki.ti.com/index.php/StarterWare_USB#Bulk_Device_Enumeration

  • Hi Jonathan Chen,

    Thank you for the observation. This bug will be fixed in the next release.

    Regards

    Sirish

  • Could this be why the USB stack hangs if the USBbuffer rx buffer is full when a packet comes in?

    Gerry Belanger

  • Gerard Belanger1 said:

    Could this be why the USB stack hangs if the USBbuffer rx buffer is full when a packet comes in?

    Gerry Belanger

    I take that back.  Using Starterware 2.00.00.07, it looks like for the bulk device, the call to InternalUSBTickInit was removed,  so no wipeout.

    No class specific tick handler was registered, so no issue there, but no timer recovery either.

     However,  InternalUSBStartOfFrameTick is still called every 5 SOFs, without the arrays being ever initialized.  Tsk, Tsk.

    No SOF handler may be why the timer never kicks my app to read more data from the buffer.

    Other problems with the USB stack:

    SOF comes at 125us in High speed - so InternalUSBStartOfFrameTick is called every 625us instead of 5 ms, messing up timing assumptions.

    It would be nice if I could find an API call to force Full Speed during initialization, or query the core to find out what speed the device is running at.

    If there are calls for this, I must not be looking hard enough.

    Lastly, it is unclear to me what is supposed to happen in the usbbuffer module if the buffer is full when more data come into the receive FIFO.

    Ah What fun!

    Gerry Belanger

  • I found the answer to one more of my questions. 

    Defining USB_MODE_FULLSPEED,  when building UsbphyGS70.c will force Full Speed.

    The SOF timer now behaves as needed.

    It looks like that define is also used in cppi41dma.h, .c.

    USB_MODE_FULLSPEED is referenced in the documentation only in the context of MSC host use.  Since I was only interested in the Bulk Device implementation, I did not originally notice it.

    Gerry Belanger