Skip to content

Commit 0488d6d

Browse files
committed
usb device: stm32: fix logic which selects the usb speed
#86922 changed the logic how the usb speed gets chosen. unfortunately due to an error in the macros, USB_OTG_SPEED_HIGH_IN_FULL is always selected as the condition is always true (macro is always defined). also sync the logic between usb and usb_next stack. Issue: #89831 Signed-off-by: Martin Gysel <[email protected]>
1 parent b61fa28 commit 0488d6d

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

drivers/usb/device/usb_dc_stm32.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ static const struct gpio_dt_spec ulpi_reset =
9191
* The following defines are used to map the value of the "maxiumum-speed"
9292
* DT property to the corresponding definition used by the STM32 HAL.
9393
*/
94-
#if defined(CONFIG_SOC_SERIES_STM32H7X) || defined(USB_OTG_HS_EMB_PHYC) || \
95-
defined(USB_OTG_HS_EMB_PHY)
94+
#if DT_ENUM_IDX(DT_DRV_INST(0), maximum_speed) == 1 && \
95+
(defined(CONFIG_SOC_SERIES_STM32H7X) || USB_OTG_HS_EMB_PHYC || USB_OTG_HS_EMB_PHY)
9696
#define USB_DC_STM32_HIGH_SPEED USB_OTG_SPEED_HIGH_IN_FULL
9797
#else
9898
#define USB_DC_STM32_HIGH_SPEED USB_OTG_SPEED_HIGH

drivers/usb/udc/udc_stm32.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ LOG_MODULE_REGISTER(udc_stm32, CONFIG_UDC_DRIVER_LOG_LEVEL);
4141
#define UDC_STM32_IRQ DT_INST_IRQ_BY_NAME(0, UDC_STM32_IRQ_NAME, irq)
4242
#define UDC_STM32_IRQ_PRI DT_INST_IRQ_BY_NAME(0, UDC_STM32_IRQ_NAME, priority)
4343

44-
#define USB_OTG_HS_EMB_PHY (DT_HAS_COMPAT_STATUS_OKAY(st_stm32_usbphyc) && \
44+
#define USB_OTG_HS_EMB_PHYC (DT_HAS_COMPAT_STATUS_OKAY(st_stm32_usbphyc) && \
45+
DT_HAS_COMPAT_STATUS_OKAY(st_stm32_otghs))
46+
47+
#define USB_OTG_HS_EMB_PHY (DT_HAS_COMPAT_STATUS_OKAY(st_stm32u5_otghs_phy) && \
4548
DT_HAS_COMPAT_STATUS_OKAY(st_stm32_otghs))
4649

4750
#define USB_OTG_HS_ULPI_PHY (DT_HAS_COMPAT_STATUS_OKAY(usb_ulpi_phy) && \
@@ -51,7 +54,8 @@ LOG_MODULE_REGISTER(udc_stm32, CONFIG_UDC_DRIVER_LOG_LEVEL);
5154
* The following defines are used to map the value of the "maxiumum-speed"
5255
* DT property to the corresponding definition used by the STM32 HAL.
5356
*/
54-
#if defined(CONFIG_SOC_SERIES_STM32H7X) || defined(USB_OTG_HS_EMB_PHY)
57+
#if DT_ENUM_IDX(DT_DRV_INST(0), maximum_speed) == 1 && \
58+
(defined(CONFIG_SOC_SERIES_STM32H7X) || USB_OTG_HS_EMB_PHYC || USB_OTG_HS_EMB_PHY)
5559
#define UDC_STM32_HIGH_SPEED USB_OTG_SPEED_HIGH_IN_FULL
5660
#else
5761
#define UDC_STM32_HIGH_SPEED USB_OTG_SPEED_HIGH
@@ -1006,13 +1010,13 @@ static void priv_pcd_prepare(const struct device *dev)
10061010
priv->pcd.Instance = (USB_OTG_GlobalTypeDef *)UDC_STM32_BASE_ADDRESS;
10071011
#endif /* USB */
10081012

1009-
#if USB_OTG_HS_EMB_PHY
1013+
#if USB_OTG_HS_EMB_PHYC || USB_OTG_HS_EMB_PHY
10101014
priv->pcd.Init.phy_itface = USB_OTG_HS_EMBEDDED_PHY;
10111015
#elif USB_OTG_HS_ULPI_PHY
10121016
priv->pcd.Init.phy_itface = USB_OTG_ULPI_PHY;
10131017
#else
10141018
priv->pcd.Init.phy_itface = PCD_PHY_EMBEDDED;
1015-
#endif /* USB_OTG_HS_EMB_PHY */
1019+
#endif /* USB_OTG_HS_EMB_PHYC || USB_OTG_HS_EMB_PHY */
10161020
}
10171021

10181022
static const struct stm32_pclken pclken[] = STM32_DT_INST_CLOCKS(0);
@@ -1146,7 +1150,7 @@ static int priv_clock_enable(void)
11461150
LL_AHB1_GRP1_DisableClockLowPower(LL_AHB1_GRP1_PERIPH_OTGHSULPI);
11471151
#endif /* defined(CONFIG_SOC_SERIES_STM32H7X) */
11481152

1149-
#if USB_OTG_HS_EMB_PHY
1153+
#if USB_OTG_HS_EMB_PHYC
11501154
#if !DT_HAS_COMPAT_STATUS_OKAY(st_stm32n6_otghs)
11511155
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_OTGPHYC);
11521156
#endif

0 commit comments

Comments
 (0)