@@ -41,26 +41,39 @@ 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) && \
4851 DT_HAS_COMPAT_STATUS_OKAY(st_stm32_otghs))
4952
5053/**
51- * The following defines are used to map the value of the "maxiumum-speed"
52- * DT property to the corresponding definition used by the STM32 HAL.
54+ * Select the desired speed based on enabled high speed support and phy.
55+ *
56+ * 1. high speed support enabled and hs phy is used
57+ * 1.1 maximum speed is reduced by devicetree configuration
58+ * 1.2 maximum speed is high speed
59+ * 2. high speed phy is used, but high speed support is not enabled
60+ * 3. non-hs capable hardware, but with st_stm32_usb compatible
61+ * 4. everything else
5362 */
54- #if defined(CONFIG_SOC_SERIES_STM32H7X ) || USB_OTG_HS_EMB_PHY
55- #define UDC_STM32_HIGH_SPEED USB_OTG_SPEED_HIGH_IN_FULL
63+ #if CONFIG_UDC_DRIVER_HIGH_SPEED_SUPPORT_ENABLED && \
64+ (USB_OTG_HS_EMB_PHYC || USB_OTG_HS_EMB_PHY || USB_OTG_HS_ULPI_PHY )
65+ /* 'maximum_speed': idx == 2 means 'high-speed' */
66+ #if DT_ENUM_IDX_OR (DT_DRV_INST (0 ), maximum_speed , 2 ) != 2
67+ #define UDC_STM32_SPEED USB_OTG_SPEED_HIGH_IN_FULL
5668#else
57- #define UDC_STM32_HIGH_SPEED USB_OTG_SPEED_HIGH
69+ #define UDC_STM32_SPEED USB_OTG_SPEED_HIGH
5870#endif
59-
60- #if DT_HAS_COMPAT_STATUS_OKAY (st_stm32_usb )
61- #define UDC_STM32_FULL_SPEED PCD_SPEED_FULL
71+ #elif USB_OTG_HS_EMB_PHYC || USB_OTG_HS_EMB_PHY || USB_OTG_HS_ULPI_PHY
72+ #define UDC_STM32_SPEED USB_OTG_SPEED_HIGH_IN_FULL
73+ #elif DT_HAS_COMPAT_STATUS_OKAY (st_stm32_usb )
74+ #define UDC_STM32_SPEED PCD_SPEED_FULL
6275#else
63- #define UDC_STM32_FULL_SPEED USB_OTG_SPEED_FULL
76+ #define UDC_STM32_SPEED USB_OTG_SPEED_FULL
6477#endif
6578
6679#if DT_HAS_COMPAT_STATUS_OKAY (st_stm32n6_otghs )
@@ -85,7 +98,6 @@ struct udc_stm32_config {
8598 uint32_t dram_size ;
8699 uint16_t ep0_mps ;
87100 uint16_t ep_mps ;
88- int speed_idx ;
89101};
90102
91103enum udc_stm32_msg_type {
@@ -986,7 +998,6 @@ static const struct udc_stm32_config udc0_cfg = {
986998 .pma_offset = USB_BTABLE_SIZE ,
987999 .ep0_mps = EP0_MPS ,
9881000 .ep_mps = EP_MPS ,
989- .speed_idx = DT_ENUM_IDX_OR (DT_DRV_INST (0 ), maximum_speed , 1 ),
9901001};
9911002
9921003static void priv_pcd_prepare (const struct device * dev )
@@ -999,7 +1010,7 @@ static void priv_pcd_prepare(const struct device *dev)
9991010 /* Default values */
10001011 priv -> pcd .Init .dev_endpoints = cfg -> num_endpoints ;
10011012 priv -> pcd .Init .ep0_mps = cfg -> ep0_mps ;
1002- priv -> pcd .Init .speed = UTIL_CAT ( UDC_STM32_ , DT_INST_STRING_UPPER_TOKEN ( 0 , maximum_speed )) ;
1013+ priv -> pcd .Init .speed = UDC_STM32_SPEED ;
10031014
10041015 /* Per controller/Phy values */
10051016#if defined(USB )
@@ -1010,13 +1021,13 @@ static void priv_pcd_prepare(const struct device *dev)
10101021 priv -> pcd .Instance = (USB_OTG_GlobalTypeDef * )UDC_STM32_BASE_ADDRESS ;
10111022#endif /* USB */
10121023
1013- #if USB_OTG_HS_EMB_PHY
1024+ #if USB_OTG_HS_EMB_PHYC || USB_OTG_HS_EMB_PHY
10141025 priv -> pcd .Init .phy_itface = USB_OTG_HS_EMBEDDED_PHY ;
10151026#elif USB_OTG_HS_ULPI_PHY
10161027 priv -> pcd .Init .phy_itface = USB_OTG_ULPI_PHY ;
10171028#else
10181029 priv -> pcd .Init .phy_itface = PCD_PHY_EMBEDDED ;
1019- #endif /* USB_OTG_HS_EMB_PHY */
1030+ #endif /* USB_OTG_HS_EMB_PHYC || USB_OTG_HS_EMB_PHY */
10201031}
10211032
10221033static const struct stm32_pclken pclken [] = STM32_DT_INST_CLOCKS (0 );
@@ -1159,7 +1170,7 @@ static int priv_clock_enable(void)
11591170 LL_AHB1_GRP1_DisableClockLowPower (LL_AHB1_GRP1_PERIPH_OTGHSULPI );
11601171#endif /* defined(CONFIG_SOC_SERIES_STM32H7X) */
11611172
1162- #if USB_OTG_HS_EMB_PHY
1173+ #if USB_OTG_HS_EMB_PHYC
11631174#if !DT_HAS_COMPAT_STATUS_OKAY (st_stm32n6_otghs )
11641175 LL_APB2_GRP1_EnableClock (LL_APB2_GRP1_PERIPH_OTGPHYC );
11651176#endif
@@ -1257,9 +1268,9 @@ static int udc_stm32_driver_init0(const struct device *dev)
12571268 data -> caps .rwup = true;
12581269 data -> caps .out_ack = false;
12591270 data -> caps .mps0 = UDC_MPS0_64 ;
1260- if ( cfg -> speed_idx == 2 ) {
1261- data -> caps .hs = true;
1262- }
1271+ # if UDC_STM32_SPEED == USB_OTG_SPEED_HIGH
1272+ data -> caps .hs = true;
1273+ #endif
12631274
12641275 priv -> dev = dev ;
12651276 priv -> irq = UDC_STM32_IRQ ;
0 commit comments