Skip to content

Commit 7707094

Browse files
nandojvekartben
authored andcommitted
dts: phy: Add clock-reference prop in stm32u5-otghs-phy
The OTG_HS PHY from stm32u5a5xx device require the correct reference clock frequency selction in SYSCFG_OTGHSPHYCR. The current default is hard coded to 16Mhz (which matches the development board crystal). However, a custom board my require a different crystal and then the USB will not work. This add a required field in the st,stm32u5-otghs-phy binding to force user to select the correct clock reference. The current nucleo_u5a5zj_q baord was updated to reflect the mandatory field. Signed-off-by: BUDKE Gerson Fernando <[email protected]>
1 parent ad0f411 commit 7707094

File tree

6 files changed

+47
-1
lines changed

6 files changed

+47
-1
lines changed

boards/st/nucleo_u5a5zj_q/nucleo_u5a5zj_q.dts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,7 @@ zephyr_udc0: &usbotg_hs {
8383
pinctrl-names = "default";
8484
status = "okay";
8585
};
86+
87+
&otghs_phy {
88+
clock-reference = "SYSCFG_OTG_HS_PHY_CLK_16MHz";
89+
};

boards/st/stm32u5a9j_dk/stm32u5a9j_dk.dts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,10 @@ zephyr_udc0: &usbotg_hs {
257257
status = "okay";
258258
};
259259

260+
&otghs_phy {
261+
clock-reference = "SYSCFG_OTG_HS_PHY_CLK_16MHz";
262+
};
263+
260264
&flash0 {
261265
partitions {
262266
compatible = "fixed-partitions";

boards/st/stm32u5g9j_dk1/stm32u5g9j_dk1.dts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,10 @@ zephyr_udc0: &usbotg_hs {
257257
status = "okay";
258258
};
259259

260+
&otghs_phy {
261+
clock-reference = "SYSCFG_OTG_HS_PHY_CLK_16MHz";
262+
};
263+
260264
&flash0 {
261265
partitions {
262266
compatible = "fixed-partitions";

boards/st/stm32u5g9j_dk2/stm32u5g9j_dk2.dts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,10 @@ zephyr_udc0: &usbotg_hs {
296296
status = "okay";
297297
};
298298

299+
&otghs_phy {
300+
clock-reference = "SYSCFG_OTG_HS_PHY_CLK_16MHz";
301+
};
302+
299303
&flash0 {
300304
partitions {
301305
compatible = "fixed-partitions";

drivers/usb/udc/udc_stm32.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,17 @@ LOG_MODULE_REGISTER(udc_stm32, CONFIG_UDC_DRIVER_LOG_LEVEL);
6767
#define USB_USBPHYC_CR_FSEL_24MHZ USB_USBPHYC_CR_FSEL_1
6868
#endif
6969

70+
#if DT_HAS_COMPAT_STATUS_OKAY(st_stm32_otghs) && defined(CONFIG_SOC_SERIES_STM32U5X)
71+
static const int syscfg_otg_hs_phy_clk[] = {
72+
SYSCFG_OTG_HS_PHY_CLK_SELECT_1, /* 16Mhz */
73+
SYSCFG_OTG_HS_PHY_CLK_SELECT_2, /* 19.2Mhz */
74+
SYSCFG_OTG_HS_PHY_CLK_SELECT_3, /* 20Mhz */
75+
SYSCFG_OTG_HS_PHY_CLK_SELECT_4, /* 24Mhz */
76+
SYSCFG_OTG_HS_PHY_CLK_SELECT_5, /* 26Mhz */
77+
SYSCFG_OTG_HS_PHY_CLK_SELECT_6, /* 32Mhz */
78+
};
79+
#endif
80+
7081
struct udc_stm32_data {
7182
PCD_HandleTypeDef pcd;
7283
const struct device *dev;
@@ -1063,7 +1074,9 @@ static int priv_clock_enable(void)
10631074

10641075
/* Set the OTG PHY reference clock selection (through SYSCFG) block */
10651076
LL_APB3_GRP1_EnableClock(LL_APB3_GRP1_PERIPH_SYSCFG);
1066-
HAL_SYSCFG_SetOTGPHYReferenceClockSelection(SYSCFG_OTG_HS_PHY_CLK_SELECT_1);
1077+
HAL_SYSCFG_SetOTGPHYReferenceClockSelection(
1078+
syscfg_otg_hs_phy_clk[DT_ENUM_IDX(DT_NODELABEL(otghs_phy), clock_reference)]
1079+
);
10671080
/* Configuring the SYSCFG registers OTG_HS PHY : OTG_HS PHY enable*/
10681081
HAL_SYSCFG_EnableOTGPHY(SYSCFG_OTG_HS_PHY_ENABLE);
10691082
#elif DT_HAS_COMPAT_STATUS_OKAY(st_stm32n6_otghs)

dts/bindings/phy/st,stm32u5-otghs-phy.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,20 @@ properties:
3636
/* PLL1_P_CK/2 */
3737
clocks = <&rcc STM32_CLOCK(AHB2, 15U)>,
3838
<&rcc (STM32_SRC_PLL1_P | STM32_CLOCK_DIV(2)) OTGHS_SEL(3)>;
39+
40+
clock-reference:
41+
type: string
42+
required: true
43+
enum:
44+
- "SYSCFG_OTG_HS_PHY_CLK_16MHz"
45+
- "SYSCFG_OTG_HS_PHY_CLK_19.2MHz"
46+
- "SYSCFG_OTG_HS_PHY_CLK_20MHz"
47+
- "SYSCFG_OTG_HS_PHY_CLK_24MHz"
48+
- "SYSCFG_OTG_HS_PHY_CLK_26MHz"
49+
- "SYSCFG_OTG_HS_PHY_CLK_32MHz"
50+
description: |
51+
OTG_HS PHY reference clock frequency selection.
52+
53+
This value selects the reference clock frequency to be used in the OTG_HS PHY PLL
54+
in the SYSCFG OTG_HS PHY register (SYSCFG_OTGHSPHYCR). The selection of this value
55+
should take in consideration the OTGHSSEL dependency to avoid miss configurations.

0 commit comments

Comments
 (0)