2024-06-11 05:21 PM - edited 2024-06-11 05:22 PM
Colleagues,
What should be done in firmware for VBUS detection through a GPIO pin? My device is self-powered, so I have to do VBUS detection. The device is built around STM32G474, and it doesn’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.
I checked the code examples for STM32G4, 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 FAQ on VBUS detection which is a collection of excerpts from AN4879 (and I’ve read the app note too).
[without dedicated hardware VBUS detection pin] Any 5V tolerant pin with external interrupt functionality [...]
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.”
I'd like 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?
Best regards,
- Nick
Solved! Go to Solution.
2024-07-15 08:19 AM
I received several answers from from the ST’s support, and arrived at the solution.
2024-06-25 11:59 AM
Dear @Nick Alexeev
For VBUS detection through a GPIO pin on a self-powered device like your case built around the STM32G474, you will need to implement the VBUS sensing in firmware since your device does not have a dedicated VBUS detection pin. In case of Bus Powered ( it is not required - Obvious as VDD will disappear).
Try to Implement an ISR that will be called when the VBUS presence change is detected.
In the ISR, check the state of the GPIO pin to determine if VBUS is present or not.
Handling VBUS Presence:
Handling VBUS Absence:
Hope it helps you.
STOne-32.
2024-07-15 08:19 AM
I received several answers from from the ST’s support, and arrived at the solution.