Skip to content

Commit 1844e98

Browse files
marwaiehm-stkartben
authored andcommitted
drivers: usb: Enhance USB and UDC drivers for STM32 OTG configurations
- Unified the handling of USB OTG HS and USB OTG FS by removing redundant preprocessor conditionals. - Introduced a new macro `UDC_STM32_BASE_ADDRESS` to dynamically set the USB base address. Signed-off-by: IBEN EL HADJ MESSAOUD Marwa <marwa.ibenelhadjmessaoud-ext@st.com>
1 parent 6f005fd commit 1844e98

File tree

2 files changed

+10
-17
lines changed

2 files changed

+10
-17
lines changed

drivers/usb/device/usb_dc_stm32.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -476,11 +476,7 @@ static int usb_dc_stm32_init(void)
476476
usb_dc_stm32_state.pcd.Init.ep0_mps = PCD_EP0MPS_64;
477477
usb_dc_stm32_state.pcd.Init.low_power_enable = 0;
478478
#else /* USB_OTG_FS || USB_OTG_HS */
479-
#if DT_HAS_COMPAT_STATUS_OKAY(st_stm32_otghs)
480-
usb_dc_stm32_state.pcd.Instance = USB_OTG_HS;
481-
#else
482-
usb_dc_stm32_state.pcd.Instance = USB_OTG_FS;
483-
#endif
479+
usb_dc_stm32_state.pcd.Instance = (USB_OTG_GlobalTypeDef *)USB_BASE_ADDRESS;
484480
usb_dc_stm32_state.pcd.Init.dev_endpoints = USB_NUM_BIDIR_ENDPOINTS;
485481
#if USB_OTG_HS_EMB_PHYC || USB_OTG_HS_EMB_PHY
486482
usb_dc_stm32_state.pcd.Init.phy_itface = USB_OTG_HS_EMBEDDED_PHY;

drivers/usb/udc/udc_stm32.c

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,16 @@ LOG_MODULE_REGISTER(udc_stm32, CONFIG_UDC_DRIVER_LOG_LEVEL);
3737
#define UDC_STM32_IRQ_NAME usb
3838
#endif
3939

40+
#define UDC_STM32_BASE_ADDRESS DT_INST_REG_ADDR(0)
4041
#define UDC_STM32_IRQ DT_INST_IRQ_BY_NAME(0, UDC_STM32_IRQ_NAME, irq)
4142
#define UDC_STM32_IRQ_PRI DT_INST_IRQ_BY_NAME(0, UDC_STM32_IRQ_NAME, priority)
4243

44+
#define USB_OTG_HS_EMB_PHY (DT_HAS_COMPAT_STATUS_OKAY(st_stm32_usbphyc) && \
45+
DT_HAS_COMPAT_STATUS_OKAY(st_stm32_otghs))
46+
47+
#define USB_OTG_HS_ULPI_PHY (DT_HAS_COMPAT_STATUS_OKAY(usb_ulpi_phy) && \
48+
DT_HAS_COMPAT_STATUS_OKAY(st_stm32_otghs))
49+
4350
/**
4451
* The following defines are used to map the value of the "maxiumum-speed"
4552
* DT property to the corresponding definition used by the STM32 HAL.
@@ -962,12 +969,6 @@ static const struct udc_api udc_stm32_api = {
962969
#define USB_BTABLE_SIZE 0
963970
#endif /* USB */
964971

965-
#define USB_OTG_HS_EMB_PHY (DT_HAS_COMPAT_STATUS_OKAY(st_stm32_usbphyc) && \
966-
DT_HAS_COMPAT_STATUS_OKAY(st_stm32_otghs))
967-
968-
#define USB_OTG_HS_ULPI_PHY (DT_HAS_COMPAT_STATUS_OKAY(usb_ulpi_phy) && \
969-
DT_HAS_COMPAT_STATUS_OKAY(st_stm32_otghs))
970-
971972
static struct udc_stm32_data udc0_priv;
972973

973974
static struct udc_data udc0_data = {
@@ -1001,12 +1002,8 @@ static void priv_pcd_prepare(const struct device *dev)
10011002
priv->pcd.Instance = USB;
10021003
#elif defined(USB_DRD_FS)
10031004
priv->pcd.Instance = USB_DRD_FS;
1004-
#elif defined(USB_OTG_FS) || defined(USB_OTG_HS)
1005-
#if DT_HAS_COMPAT_STATUS_OKAY(st_stm32_otghs)
1006-
priv->pcd.Instance = USB_OTG_HS;
1007-
#else
1008-
priv->pcd.Instance = USB_OTG_FS;
1009-
#endif
1005+
#elif DT_HAS_COMPAT_STATUS_OKAY(st_stm32_otgfs) || DT_HAS_COMPAT_STATUS_OKAY(st_stm32_otghs)
1006+
priv->pcd.Instance = (USB_OTG_GlobalTypeDef *)UDC_STM32_BASE_ADDRESS;
10101007
#endif /* USB */
10111008

10121009
#if USB_OTG_HS_EMB_PHY

0 commit comments

Comments
 (0)