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

Is it possible to Enable or Disable USB Programmatically during RunTime

Hi,

In our app we would like the USB to change role. For example depending on Scenario and Command over BLE we would like to change the USB Device class or even turn it on or off. At least Enable/Disable of say a Vcom device is right now I'm looking forward to for a POC.

nRF52840-DK is our evaluation platform and we are also using USB Secured DFU Bootloader along with the app. 

Regards

Sougata Das

Parents Reply Children
  • I don’t believe this approach works in debug mode as there are an inordinate number of (probably superfluous) asserts in the usbd-related code that assume state transitions that can easily be violated when trying to disable/enable. Can you recommend a more comprehensive approach or else remove the various assert statements from the sdk?  I think if you try what you’re suggesting in debug you will immediately run into this issue. 

    There are a number of questions on this forum about enabling/disabling usb and none of them are really answered. I believe these assert statements are the root cause and make it almost (completely?) impossible to disable usb in debug. Removing the asserts seems to solve the problem with no obvious adverse side effects. 

Related