This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

USB Bulk transfers with the app_usbd library

Hi DevZone,

I want to perform USB bulk transmits to a host device while using the app_usbd library. I am using SDK 15.3 and the s140 soft device is enabled.

I have found the app_usbd_ep_transfer() and app_usbd_ep_handled_transfer() functions in the app_usbd.c file at line 1816 and 1831.

Can I use these directly in my user code and does the library have built in scheduling/handling so I don't run into concurrency issues with the end point I am using?
I have not been able to find information on this in the Nordic info center, and I am having a hard time figuring it out by looking in the library code it self Slight smile

Br. Casper

Parents Reply
  • Hi Torbjørn,

    It seems that our use of the driver is very similar. However I am using the "app_usbd_ep_transfer()" to initiate transmits instead of the nrf driver directly.

    I have a question regarding some specific behavior while handling EPTRANSFERs:

    • In line 957-988 you are handling the NRF_DRV_USBD_EVT_EPTRANSFER event in the usbd_event_handler().

    • I have similar code using the APP_USBD_EVT_DRV_EPTRANSFER event instead in the bulk_event_handler().
      Here I am seeing calls to the bulk_event_handler() which I did not initialize with a call to app_usbd_ep_transfer(). I am making sure is directed to EPIN with the NRF_USBD_EPIN_CHECK().  It happens when I connect the device to a host PC.
      • This must mean that somewhere else in the library code USBD transmits are started. Do you know where this might come from?

    Assumptions on equal functionality:

    - NRF_DRV_USBD_EVT_EPTRANSFER  = APP_USBD_EVT_DRV_EPTRANSFER 
    - usbd_event_handler() = bulk_event_handler()
    - nrf_drv_usbd_ep_transfer() =  app_usbd_ep_transfer()

Children
  • Hello,

    Torbjørn is currently out of office.

    I don't know this might come from no, but if you want to setup your own usb class/custom descriptor, I can also recommend looking at the usbd example in the sdk: nRF5_SDK_17.0.2_d674dde/examples/peripheral/usbd

    This uses the driver directly, and exposes most low-level usb specific functionality.

    Also check out the documentation if you haven't already:
    https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.0.2/lib_usbd.html 

    Best regards,
    Kenneth

  • Hi Kenneth,

    Thank you for pointing me to that example.

    I have been looking into the example you suggested. It seems that the functionalities I use from the driver are used in the same way. This must mean that something in my application is causing these unexpected event handler calls.

    Question:

    If I am calling USBD transmits without a host connected is it then possible that they are "stored ready" in the peripheral and then sent as soon as a host is connected? Or maybe in some other way so this behavior is seen?

    Br. Casper

  • Casper Kronborg Pedersen said:
    If I am calling USBD transmits without a host connected is it then possible that they are "stored ready" in the peripheral and then sent as soon as a host is connected? Or maybe in some other way so this behavior is seen?

    It's an interesting question, I guess it's kind of undefined, I suggest to try with a global variable to ensure you don't write to the USBD when it's not connected.

    Kenneth

  • Thanks Kenneth, that is a good idea.

    I am already doing something similar that checks for the presence of a USB VBUS before any transmits can be called.


    The scenario that I have arises when the host PC application is not paired with the USB driver on the embedded side when the USB transfer is started.
    The result is the embedded side never gets a "TX completed event" (APP_USBD_EVT_DRV_EPTRANSFER) and the driver times out waiting for it. Then as soon as the Host PC application is connected I get the APP_USBD_EVT_DRV_EPTRANSFER event. This then looks like a USBD driver transfer was started elsewhere when in reality it was not.


    Of course I could add a "pairing" step to both sides and treat this symptom. But as it is now it is not breaking anything, I would just prefer to not have any unpredicted behavior. But if this is exactly what is happening then I am ok with that. Does it sound plausible to you?

Related