2020-01-05 04:34 PM
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:
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!
2020-02-02 01:43 PM
I think I've found an answer to my own question.
Initialization code for the peripheral libraries can be controlled by opening the device configuration tool, going to "Project Manager", then "Advanced Settings", then checking/unchecking the box under "Not Generate Function Call". When this box is checked, the initialization function for that peripheral will not be called, and it can then be called where needed.
For USB in particular, I get good results if I initialize USB by calling:
MX_USB_Device_Init();
And de-initialize it by calling:
USBD_Stop(&hUsbDeviceFS);