2021-11-05 05:17 AM
I am setting up a STM32G4 based USB self powered device with CubeMX. The CDC/ACM stack nearly runs fine. How shall I implement VBUS handling? The part has no dedicated VBUS pin. So some app notes suggest to connect VBUS to a GPIO-extInt or ADC and implement the VBUS handling from application code. But what needs to be called on VBUS change by application? I did not find an example for an application based VBUS handling.
2021-11-05 05:53 AM
Use any GPIO pin to monitor VBUS. When it's present, initialize the USB, when it goes away, deinitialize the USB.
The USB standard requires that you do not energize the data lines unless VBUS is present, hence the need to monitor VBUS unless your device is strictly powered through it.