STM32. What should be done in firmware for VBUS detection through a GPIO pin?

kender

Advanced Member level 4
Joined
Jun 19, 2005
Messages
1,428
Helped
138
Reputation
276
Reaction score
39
Trophy points
1,328
Location
Stanford, SF Bay Peninsula, California, Earth, Sol
Activity points
10,069
I've got a is self-powered USB device, which means that I have to do VBUS detection. The device is built around STM32G474. Unlike some other STM32s, the STM32G4 don't have a dedicated pin for VBUS detection, so I have to do it through a GPIO pin and firmware. VBUS is connected to the GPIO pin PA10 through a 2x 100kΩ divider. What should be done in firmware for VBUS detection through a GPIO pin?

I checked the code examples for STM32G4s, but I couldn’t find examples for USB. If somebody could point me to a code example, that would be great.

I’ve read this knowledgebase article on VBUS detection which is a collection of excerpts from AN4879 (and I’ve read the app note too).

Any 5V tolerant pin with external interrupt functionality... [from knowledgebase article]

Does the VBUS detection have to be done in an interrupt? Or can it be done in the main loop? If it can be done in the main loop, then are there timing constraints?

However, the disadvantage of this solution is that the software handling of VBUS presence event needs to be implemented by the user. This is not managed within our STM32 USB library for the time being. [from the same knowledgebase article]

I have to pick up where that knowledgebase article left off. What should the firmware do when it detects that VBUS (re)appeared? What should the firmware do when VBUS has disappeared?
 

You can detect VBUS in either the main loop or an interrupt. Using an interrupt is more responsive.
 

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…