cancel
Showing results for 
Search instead for 
Did you mean: 

VBus Sensing for self powered USB device using STM32C071CBT6

PPate.1
Associate III

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

 

7 REPLIES 7
FBL
ST Employee

Hi @PPate.1 

According to C071 nucleo schematics, PC0 is used for vbus sensing.

FBL_1-1744225914812.png

 

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.


PPate.1
Associate III

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.

PPate1_0-1744384682728.png

Thanks,

Pradeep

FBL
ST Employee

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?

  1. Disabling VBUS sensing can lead to non-compliance with the USB specification, as the device may keep the DP pull-up enabled when VBUS is removed.
  2. The device may not properly detect when the USB cable is removed, leading to potential issues with the device's state management (e.g., incorrectly handling suspend and resume events and unable to reconnect unless you reset the MCU).
  3. There is a risk of current flowing into the USB host through the pull-up resistor when VBUS is not present, which can cause unintended behavior/damage.

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.


PPate.1
Associate III

Hi FBL,

SYSCFG_CFGR1 register is correctly set as my PIN configuration shows following:

PPate1_0-1744533759414.png

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. 

PPate1_2-1744534254880.png

 

Can I do it directly from the autogenerated code? But it will always be overwritten whenever I will regenerate code!

PPate1_1-1744534152401.png

Please help me with this configuration.

Please also give me some reference for firmware logic to be implemented with VBUS sensing.

Thanks,

Pradeep

FBL
ST Employee

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.


PPate.1
Associate III

Hi FBL,

VBUS Detect pin on my custom board is connected to PA10 through potential divider.

PPate1_0-1744890754193.pngPPate1_1-1744890838812.png

I configured PA10 as GPIO_EXTI.

PPate1_2-1744890921562.png

Implemented callback functions:

PPate1_3-1744891011765.png

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

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.