How to start/stop USB with change in application state?
I am building a test application on the P-NUCLEO-WB55-Nucleo and would like to switch between two application states with the push of a button:
- In the first state, the application writes to an attached microSD card using FatFS.
- In the second state, the application acts as a USB mass storage device allowing access to the contents of the microSD card.
I've been able to implement both states in separate applications. However, in order to do this in one application, I will need to start/stop USB functionality when the application state changes.
How would I start/stop USB in my application code so that the board does not enumerate if plugged in while in the first state, but shows up as a USB mass storage device if plugged in while in the second state? The CubeMX generated code seems well-adapted for an application which initializes USB once and then leaves it running until the application shuts down, but I haven't been able to figure out a good way to start/stop USB while the application is running.
Thanks for your help!