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 Children
  • Hi Torbjørn,

    Thanks for getting back to me. I will have a look at your example.

    Br. Casper

  • 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()

  • 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

Related