Skip to content

Handling of VBUS sensing #886

Closed
Closed
@matthijskooijman

Description

@matthijskooijman

While, reading the code, I was a bit confused by this bit:

#ifdef USE_USB_HS
g_hpcd.Instance = USB_OTG_HS;
g_hpcd.Init.use_dedicated_ep1 = DISABLE;
g_hpcd.Init.dma_enable = DISABLE;
#ifdef USE_USB_HS_IN_FS
g_hpcd.Init.phy_itface = PCD_PHY_EMBEDDED;
#else
g_hpcd.Init.phy_itface = PCD_PHY_ULPI;
#endif
g_hpcd.Init.speed = PCD_SPEED_HIGH;
g_hpcd.Init.vbus_sensing_enable = ENABLE;
g_hpcd.Init.use_external_vbus = DISABLE;
#else /* USE_USB_FS */
#ifdef USB_OTG_FS
g_hpcd.Instance = USB_OTG_FS;
g_hpcd.Init.use_dedicated_ep1 = DISABLE;
g_hpcd.Init.dma_enable = DISABLE;
g_hpcd.Init.vbus_sensing_enable = DISABLE;
g_hpcd.Init.use_external_vbus = DISABLE;
#else
g_hpcd.Instance = USB;
#endif
g_hpcd.Init.phy_itface = PCD_PHY_EMBEDDED;
g_hpcd.Init.speed = PCD_SPEED_FULL;
#endif /* USE_USB_HS */

In particular, IIUC, it sets g_hpcd.Init.vbus_sensing_enable to ENABLE when USE_USB_HS is defined, but to DISABLE when using the OTG_FS peripheral.

Why is this difference there?

It seems it has been there from the start, when HS support was introduced in 861cd07, FS had no VBUS sensing and HS was added with VBUS sensing.

Ultimately, I think think this is something that should be board-specific? If the VBUS line is connected to the VBUS pin, then VBUS sensing should be enabled? If not (which is, I think, recommended only for bus-powered devices where VBUS is always present when the MCU is running).

Maybe it would be useful to enable VBUS sensing by default and have a "USB_ENABLE_VBUS_DETECTION" macro in variant.h for boards that need it?

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions