2025-04-09 2:17 AM - edited 2025-04-09 2:31 AM
Hi,
I created custom board using STM32C071CBT6 MCU and using USB port in device only mode. I have connected VBuS sensing through potential divider circuit to GPIO PA10 of my controller. My device is self powered. I read some USB related articles from STMicro for other controllers and noticed that for self powered devices VBus sensing is mandatory and should be connected to PA9 as this pin has internal functionality of VBus sensing.
In my configuration I have disabled VBus sensing. However, my device is getting detected by host.
Do I have to enable VBus sensing as my device is self powered? If yes, then how it will impact functionality?
Should it be connected to PA9 for STM32C0xx also? Can I use PA10 with some code modifications, as my hardware is already developed?
I checked datasheet and reference manual of this MCU and could not find any reference of VBuS sensing through PA9.
Thanks,
Pradeep
2025-04-09 12:08 PM - edited 2025-04-09 12:12 PM
Hi @PPate.1
According to C071 nucleo schematics, PC0 is used for vbus sensing.
This post should be helpful Details of using USB without VBUS sensing - STMicroelectronics Community
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2025-04-11 8:18 AM
Hi @FBL,
C071 Nucleo has STM31C071RBT6 chip which is a 64 pin chip. This has PC0 pin. I am using STM32C071CBT6 chip which is 48 pin chip and it does not have PC0 pin.
Thanks,
Pradeep
2025-04-11 9:06 AM
My bad @PPate.1 Indeed PC0 is not available on STM32C071CBT6.
So as long you configure PA10 properly as Input and implement USB sensing logic in your firmware, also configure SYSCFG_CFGR1 register properly because pins PA9 and PA10 can be remapped in place of pins PA11 and PA12
it should work!
> about your question : How will it impact USB functionality if VBUS sensing is not enabled?
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2025-04-13 1:53 AM
Hi FBL,
SYSCFG_CFGR1 register is correctly set as my PIN configuration shows following:
Both settings for PA9 and PA10 are unchecked.
How do I enable VBUS sensing? I don't see any configuration for enable/disable of VBuS sensing in cubeMx.
Can I do it directly from the autogenerated code? But it will always be overwritten whenever I will regenerate code!
Please help me with this configuration.
Please also give me some reference for firmware logic to be implemented with VBUS sensing.
Thanks,
Pradeep
2025-04-14 4:20 AM
Hi @PPate.1
It should be dependent on your implementation. This is not covered by CubeMX. CubeMX only supports pins configured by default in USB stack. You can configure an external VBUS sensing pin as EXTI floating input and connect a simple resistor divider. Here is an example of firmware logic
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
if (GPIO_Pin == VBUS_DETECT_Pin)
{
if (HAL_GPIO_ReadPin(VBUS_DETECT_GPIO_Port, VBUS_DETECT_Pin) == GPIO_PIN_SET)
{
MX_USB_Device_Init(); // reinitialize USB
}
else
{
USB_Device_DeInit(); // deinitialize USB
}
}
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2025-04-17 4:59 AM
Hi FBL,
VBUS Detect pin on my custom board is connected to PA10 through potential divider.
I configured PA10 as GPIO_EXTI.
Implemented callback functions:
With above implemented it shows me USB device on PC device manager but If I power off my device with USB cable connected to host and again power ON the device then it does not start USB port. For that I have to plug out and plug in USB cable. This is because USB cable is already connected to Host and hence there is no rising edge of VBUS_DET pin and hence no interrupt and hence no USB initialization. This behavior is not acceptable. Do we have solution to this issue?
Thanks,
Pradeep
2025-04-22 6:24 AM
Hi @PPate.1
You need to keep USB initialization performed during the system startup for example before while loop, not just on the VBUS detection interrupt.
if (HAL_GPIO_ReadPin(VBUS_DETECT_GPIO_Port, VBUS_DETECT_Pin) == GPIO_PIN_SET)
{
MX_USB_Device_Init(); // Initialize USB if VBUS is present
}
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.