Showing results for 
Search instead for 
Did you mean: 

How to detect USB connection for STM32462 with VUSB connected via PA9

Kent Swan

Using CubeMX to implement USB CDC on a self powered STM32462 with VUSB connected via PA9 via a resistor divider for automatic bus detection. I have confirmed that I have 3.3V on PA9 when VUSB connected and 0V when it's not. The USB class is CDC and works fine. I need to use PCD (charger detection) which means that I need to detect the presence of VUSB in order to invoke HAL_PCDEx_BCD_VBUSDetect().

My question is what calls or setup or direct access do I use to detect VUSB as the the state of PA9. Is it availible as an EXTI interrupt or a IO status register read or a HAL function.


What is STM32462 ?

Generally, there are two entirely different USB incarnations in the various STM32 families/models - the complex Synopsys OTG, and the simpler device-only. In the former case, VBUS=PA9 is connected to the USB machine (PHY) and its state thus can be observed through the USB registers, as part of the OTG role-selecting mechanisms, HNP/SRP. In the latter case, AFAIK, there's no dedicated hardware for this, and you have to use the generic EXTI interrupt or a comparator (if available on given pin) or simply poll the input state of the pin in the main loop.


Thanks for you feedback. The STM32L462 is a USB FS device only with no OTG. Can the STM32L462 VBUS state which is input on PA9 be determined by an internal register read or interrupt or what. If so what registers and bits?

As in 'L462 PA9 has no special functionality with regard to USB, treat it as a normal digital input - poll its state in GPIOA_IDR in main loop, or use the EXTI module for the input to raise an interrupt.


Thanks. I guess that explains the lack of any corresponding information on the L462 though it does not answer a related question of how the version 92 internal bootloader performs its DFU detection of USB. Given that I've been singularly unsuccessful getting the DFU to work and when I did some some schematic research on the ST STM32L series ST boards, those boards seem to imply that the internal bootloaders of the non OTG cpus also use PA9 as VUSB detection. This would makes sense as a DFU commonality for OTG and non OTG usb cpu's.

On the other hand, Is there any way I can download the actual bootloader source code for thee L462 to actually do a code read verify?

AN2606 does not mention PA9 and I believe the DFU bootloader starts by detecting RESET state on the USB bus.

The bootloader sources are not available.


Kent Swan

that's a clue. Thanks.