Skip to content

Commit 9b14f9b

Browse files
marwaiehm-stkartben
authored andcommitted
drivers: usb: Enable USB and UDC OTGPHY clock
- Reset specific configuration bits in USB1_HS_PHYC->USBPHYC_CR before setting new values. - Set the Frequency Selection (FSEL) bits to operate the USB PHY Control Register at 24 MHz for proper communication. - Enable the OTGPHY1 peripheral clock using LL_AHB5_GRP1_EnableClock. Signed-off-by: IBEN EL HADJ MESSAOUD Marwa <[email protected]>
1 parent ba21058 commit 9b14f9b

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

drivers/usb/device/usb_dc_stm32.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ static const struct gpio_dt_spec ulpi_reset =
103103
#else
104104
#define USB_DC_STM32_FULL_SPEED USB_OTG_SPEED_FULL
105105
#endif
106+
107+
#if DT_HAS_COMPAT_STATUS_OKAY(st_stm32n6_otghs)
108+
#define USB_USBPHYC_CR_FSEL_24MHZ USB_USBPHYC_CR_FSEL_1
109+
#endif
110+
106111
/*
107112
* USB, USB_OTG_FS and USB_DRD_FS are defined in STM32Cube HAL and allows to
108113
* distinguish between two kind of USB DC. STM32 F0, F3, L0 and G4 series
@@ -427,7 +432,19 @@ static int usb_dc_stm32_clock_enable(void)
427432
/* Both OTG HS and USBPHY sleep clock MUST be disabled here at the same time */
428433
LL_AHB2_GRP1_DisableClockStopSleep(LL_AHB2_GRP1_PERIPH_OTG_HS ||
429434
LL_AHB2_GRP1_PERIPH_USBPHY);
430-
#elif !DT_HAS_COMPAT_STATUS_OKAY(st_stm32n6_otghs)
435+
#elif DT_HAS_COMPAT_STATUS_OKAY(st_stm32n6_otghs)
436+
/* Reset specific configuration bits before setting new values */
437+
USB1_HS_PHYC->USBPHYC_CR &= ~USB_USBPHYC_CR_FSEL_Msk;
438+
439+
/* Configure the USB PHY Control Register to operate in the High frequency "24 MHz"
440+
* by setting the Frequency Selection (FSEL) bits 4 and 5 to 10,
441+
* which ensures proper communication.
442+
*/
443+
USB1_HS_PHYC->USBPHYC_CR |= USB_USBPHYC_CR_FSEL_24MHZ;
444+
445+
/* Peripheral OTGPHY clock enable */
446+
LL_AHB5_GRP1_EnableClock(LL_AHB5_GRP1_PERIPH_OTGPHY1);
447+
#else
431448
LL_AHB1_GRP1_DisableClockLowPower(LL_AHB1_GRP1_PERIPH_OTGHSULPI);
432449
#endif
433450

drivers/usb/udc/udc_stm32.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ LOG_MODULE_REGISTER(udc_stm32, CONFIG_UDC_DRIVER_LOG_LEVEL);
6363
#define UDC_STM32_FULL_SPEED USB_OTG_SPEED_FULL
6464
#endif
6565

66+
#if DT_HAS_COMPAT_STATUS_OKAY(st_stm32n6_otghs)
67+
#define USB_USBPHYC_CR_FSEL_24MHZ USB_USBPHYC_CR_FSEL_1
68+
#endif
69+
6670
struct udc_stm32_data {
6771
PCD_HandleTypeDef pcd;
6872
const struct device *dev;
@@ -1142,7 +1146,19 @@ static int priv_clock_enable(void)
11421146
/* Both OTG HS and USBPHY sleep clock MUST be disabled here at the same time */
11431147
LL_AHB2_GRP1_DisableClockStopSleep(LL_AHB2_GRP1_PERIPH_OTG_HS ||
11441148
LL_AHB2_GRP1_PERIPH_USBPHY);
1145-
#elif !DT_HAS_COMPAT_STATUS_OKAY(st_stm32n6_otghs)
1149+
#elif DT_HAS_COMPAT_STATUS_OKAY(st_stm32n6_otghs)
1150+
/* Reset specific configuration bits before setting new values */
1151+
USB1_HS_PHYC->USBPHYC_CR &= ~USB_USBPHYC_CR_FSEL_Msk;
1152+
1153+
/* Configure the USB PHY Control Register to operate in the High frequency "24 MHz"
1154+
* by setting the Frequency Selection (FSEL) bits 4 and 5 to 10,
1155+
* which ensures proper communication.
1156+
*/
1157+
USB1_HS_PHYC->USBPHYC_CR |= USB_USBPHYC_CR_FSEL_24MHZ;
1158+
1159+
/* Peripheral OTGPHY clock enable */
1160+
LL_AHB5_GRP1_EnableClock(LL_AHB5_GRP1_PERIPH_OTGPHY1);
1161+
#else
11461162
LL_AHB1_GRP1_DisableClockLowPower(LL_AHB1_GRP1_PERIPH_OTGHSULPI);
11471163
#endif /* defined(CONFIG_SOC_SERIES_STM32H7X) */
11481164

0 commit comments

Comments
 (0)