drivers: usb: make USB VBUS sensing configurable for STM32 devices
Vbus detection is required by self-powered, with external non-USB supply, devices to have an operational USB peripheral. The voltage sensing, when enabled, is performed via a designated pin (PA9 is the most common). For greater details see section 2.6, ST application note AN4879. Signed-off-by: Raul Pando <raul.pando@bytegrity.co.uk>
This commit is contained in:
parent
313049e325
commit
cd1d7e4bb8
1 changed files with 19 additions and 7 deletions
|
@ -36,15 +36,27 @@ LOG_MODULE_REGISTER(usb_dc_stm32);
|
|||
#error "Only one interface should be enabled at a time, OTG FS or OTG HS"
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Vbus sensing is determined based on the presence of the hardware detection
|
||||
* pin(s) in the device tree. E.g: pinctrl-0 = <&usb_otg_fs_vbus_pa9 ...>;
|
||||
*
|
||||
* The detection pins are dependent on the enabled USB driver and the physical
|
||||
* interface(s) offered by the hardware. These are mapped to PA9 and/or PB13
|
||||
* (subject to MCU), being the former the most widespread option.
|
||||
*/
|
||||
#if DT_HAS_COMPAT_STATUS_OKAY(st_stm32_otghs)
|
||||
#define DT_DRV_COMPAT st_stm32_otghs
|
||||
#define USB_IRQ_NAME otghs
|
||||
#define DT_DRV_COMPAT st_stm32_otghs
|
||||
#define USB_IRQ_NAME otghs
|
||||
#define USB_VBUS_SENSING (DT_NODE_EXISTS(DT_CHILD(DT_NODELABEL(pinctrl), usb_otg_hs_vbus_pa9)) || \
|
||||
DT_NODE_EXISTS(DT_CHILD(DT_NODELABEL(pinctrl), usb_otg_hs_vbus_pb13)))
|
||||
#elif DT_HAS_COMPAT_STATUS_OKAY(st_stm32_otgfs)
|
||||
#define DT_DRV_COMPAT st_stm32_otgfs
|
||||
#define USB_IRQ_NAME otgfs
|
||||
#define DT_DRV_COMPAT st_stm32_otgfs
|
||||
#define USB_IRQ_NAME otgfs
|
||||
#define USB_VBUS_SENSING DT_NODE_EXISTS(DT_CHILD(DT_NODELABEL(pinctrl), usb_otg_fs_vbus_pa9))
|
||||
#elif DT_HAS_COMPAT_STATUS_OKAY(st_stm32_usb)
|
||||
#define DT_DRV_COMPAT st_stm32_usb
|
||||
#define USB_IRQ_NAME usb
|
||||
#define DT_DRV_COMPAT st_stm32_usb
|
||||
#define USB_IRQ_NAME usb
|
||||
#define USB_VBUS_SENSING false
|
||||
#endif
|
||||
|
||||
#define USB_BASE_ADDRESS DT_INST_REG_ADDR(0)
|
||||
|
@ -402,7 +414,7 @@ static int usb_dc_stm32_init(void)
|
|||
usb_dc_stm32_state.pcd.Init.phy_itface = PCD_PHY_EMBEDDED;
|
||||
#endif
|
||||
usb_dc_stm32_state.pcd.Init.ep0_mps = USB_OTG_MAX_EP0_SIZE;
|
||||
usb_dc_stm32_state.pcd.Init.vbus_sensing_enable = DISABLE;
|
||||
usb_dc_stm32_state.pcd.Init.vbus_sensing_enable = USB_VBUS_SENSING ? ENABLE : DISABLE;
|
||||
|
||||
#ifndef CONFIG_SOC_SERIES_STM32F1X
|
||||
usb_dc_stm32_state.pcd.Init.dma_enable = DISABLE;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue