Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions boards/st/nucleo_n657x0_q/doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,36 @@ Supported Features

.. zephyr:board-supported-hw::

USB
===

The USB pin assignments on the STM32N657XX microcontroller are immutable. This means that the specific
pins designated for USB functionality are fixed and cannot be changed or reassigned to other functions,
ensuring consistent and reliable USB communication.

USB PIN (IOs)
=============

+------------------+--------------------------------------+
| Name | Description |
+==================+======================================+
| OTG1_HSDM | USB OTG1 High-Speed Data- (negative) |
+------------------+--------------------------------------+
| OTG1_HSDP | USB OTG1 High-Speed Data+ (positive) |
+------------------+--------------------------------------+
| OTG1_ID | USB OTG1 ID Pin |
+------------------+--------------------------------------+
| OTG1_TXRTUNE | USB OTG1 Transmit Retune |
+------------------+--------------------------------------+
| OTG2_HSDM | USB OTG2 High-Speed Data- (negative) |
+------------------+--------------------------------------+
| OTG2_HSDP | USB OTG2 High-Speed Data+ (positive) |
+------------------+--------------------------------------+
| OTG2_ID | USB OTG2 ID Pin |
+------------------+--------------------------------------+
| OTG2_TXRTUNE | USB OTG2 Transmit Retune |
+------------------+--------------------------------------+

Connections and IOs
===================

Expand Down
9 changes: 9 additions & 0 deletions boards/st/nucleo_n657x0_q/nucleo_n657x0_q_common.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@
};
};

&clk_hse {
hse-div2;
clock-frequency = <DT_FREQ_M(48)>;
status = "okay";
};

&clk_hsi {
hsi-div = <1>;
status = "okay";
Expand Down Expand Up @@ -174,6 +180,9 @@
pinctrl-0 = <&usart3_tx_pd8 &usart3_rx_pd9>;
pinctrl-names = "default";
current-speed = <115200>;
};

zephyr_udc0: &usbotg_hs1 {
status = "okay";
};

Expand Down
2 changes: 2 additions & 0 deletions boards/st/nucleo_n657x0_q/twister.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ supported:
- gpio
- spi
- uart
- usb_device
- usbd
vendor: st
variants:
nucleo_n657x0_q/stm32n657xx:
Expand Down
30 changes: 30 additions & 0 deletions boards/st/stm32n6570_dk/doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,36 @@ Supported Features

.. zephyr:board-supported-hw::

USB
===

The USB pin assignments on the STM32N657XX microcontroller are immutable. This means that the specific
pins designated for USB functionality are fixed and cannot be changed or reassigned to other functions,
ensuring consistent and reliable USB communication.

USB PIN (IOs)
=============

+------------------+--------------------------------------+
| Name | Description |
+==================+======================================+
| OTG1_HSDM | USB OTG1 High-Speed Data- (negative) |
+------------------+--------------------------------------+
| OTG1_HSDP | USB OTG1 High-Speed Data+ (positive) |
+------------------+--------------------------------------+
| OTG1_ID | USB OTG1 ID Pin |
+------------------+--------------------------------------+
| OTG1_TXRTUNE | USB OTG1 Transmit Retune |
+------------------+--------------------------------------+
| OTG2_HSDM | USB OTG2 High-Speed Data- (negative) |
+------------------+--------------------------------------+
| OTG2_HSDP | USB OTG2 High-Speed Data+ (positive) |
+------------------+--------------------------------------+
| OTG2_ID | USB OTG2 ID Pin |
+------------------+--------------------------------------+
| OTG2_TXRTUNE | USB OTG2 Transmit Retune |
+------------------+--------------------------------------+

Connections and IOs
===================

Expand Down
9 changes: 9 additions & 0 deletions boards/st/stm32n6570_dk/stm32n6570_dk_common.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@
};
};

&clk_hse {
hse-div2;
clock-frequency = <DT_FREQ_M(48)>;
status = "okay";
};

&clk_hsi {
hsi-div = <1>;
status = "okay";
Expand Down Expand Up @@ -191,6 +197,9 @@
pinctrl-0 = <&usart2_tx_pd5 &usart2_rx_pf6>;
pinctrl-names = "default";
current-speed = <115200>;
};

zephyr_udc0: &usbotg_hs1 {
status = "okay";
};

Expand Down
2 changes: 2 additions & 0 deletions boards/st/stm32n6570_dk/twister.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ supported:
- memc
- spi
- uart
- usb_device
- usbd
variants:
stm32n6570_dk/stm32n657xx:
twister: false
Expand Down
22 changes: 16 additions & 6 deletions drivers/usb/device/usb_dc_stm32.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,11 @@ LOG_MODULE_REGISTER(usb_dc_stm32);

static const struct stm32_pclken pclken[] = STM32_DT_INST_CLOCKS(0);

#if !DT_HAS_COMPAT_STATUS_OKAY(st_stm32n6_otghs)
PINCTRL_DT_INST_DEFINE(0);
static const struct pinctrl_dev_config *usb_pcfg =
PINCTRL_DT_INST_DEV_CONFIG_GET(0);
#endif

#define USB_OTG_HS_EMB_PHYC (DT_HAS_COMPAT_STATUS_OKAY(st_stm32_usbphyc) && \
DT_HAS_COMPAT_STATUS_OKAY(st_stm32_otghs))
Expand Down Expand Up @@ -339,6 +341,14 @@ static int usb_dc_stm32_phy_specific_clock_enable(const struct device *const clk
* with LL_PWR_EnableVDDUSB function (higher case)
*/
LL_PWR_EnableVDDUSB();
#elif DT_HAS_COMPAT_STATUS_OKAY(st_stm32n6_otghs)
/* Enable Vdd USB voltage monitoring */
LL_PWR_EnableVddUSBMonitoring();
while (__HAL_PWR_GET_FLAG(PWR_FLAG_USB33RDY)) {
/* Wait for VDD33USB ready */
}
/* Enable VDDUSB */
LL_PWR_EnableVddUSB();
#endif

if (DT_INST_NUM_CLOCKS(0) > 1) {
Expand Down Expand Up @@ -417,13 +427,15 @@ static int usb_dc_stm32_clock_enable(void)
/* Both OTG HS and USBPHY sleep clock MUST be disabled here at the same time */
LL_AHB2_GRP1_DisableClockStopSleep(LL_AHB2_GRP1_PERIPH_OTG_HS ||
LL_AHB2_GRP1_PERIPH_USBPHY);
#else
#elif !DT_HAS_COMPAT_STATUS_OKAY(st_stm32n6_otghs)
LL_AHB1_GRP1_DisableClockLowPower(LL_AHB1_GRP1_PERIPH_OTGHSULPI);
#endif

#if USB_OTG_HS_EMB_PHYC
#if !DT_HAS_COMPAT_STATUS_OKAY(st_stm32n6_otghs)
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_OTGPHYC);
#endif
#endif
#endif /* USB_OTG_HS_ULPI_PHY */

return 0;
Expand Down Expand Up @@ -464,11 +476,7 @@ static int usb_dc_stm32_init(void)
usb_dc_stm32_state.pcd.Init.ep0_mps = PCD_EP0MPS_64;
usb_dc_stm32_state.pcd.Init.low_power_enable = 0;
#else /* USB_OTG_FS || USB_OTG_HS */
#if DT_HAS_COMPAT_STATUS_OKAY(st_stm32_otghs)
usb_dc_stm32_state.pcd.Instance = USB_OTG_HS;
#else
usb_dc_stm32_state.pcd.Instance = USB_OTG_FS;
#endif
usb_dc_stm32_state.pcd.Instance = (USB_OTG_GlobalTypeDef *)USB_BASE_ADDRESS;
usb_dc_stm32_state.pcd.Init.dev_endpoints = USB_NUM_BIDIR_ENDPOINTS;
#if USB_OTG_HS_EMB_PHYC || USB_OTG_HS_EMB_PHY
usb_dc_stm32_state.pcd.Init.phy_itface = USB_OTG_HS_EMBEDDED_PHY;
Expand Down Expand Up @@ -511,12 +519,14 @@ static int usb_dc_stm32_init(void)
}
#endif

#if !DT_HAS_COMPAT_STATUS_OKAY(st_stm32n6_otghs)
LOG_DBG("Pinctrl signals configuration");
ret = pinctrl_apply_state(usb_pcfg, PINCTRL_STATE_DEFAULT);
if (ret < 0) {
LOG_ERR("USB pinctrl setup failed (%d)", ret);
return ret;
}
#endif

LOG_DBG("HAL_PCD_Init");
status = HAL_PCD_Init(&usb_dc_stm32_state.pcd);
Expand Down
38 changes: 25 additions & 13 deletions drivers/usb/udc/udc_stm32.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,16 @@ LOG_MODULE_REGISTER(udc_stm32, CONFIG_UDC_DRIVER_LOG_LEVEL);
#define UDC_STM32_IRQ_NAME usb
#endif

#define UDC_STM32_BASE_ADDRESS DT_INST_REG_ADDR(0)
#define UDC_STM32_IRQ DT_INST_IRQ_BY_NAME(0, UDC_STM32_IRQ_NAME, irq)
#define UDC_STM32_IRQ_PRI DT_INST_IRQ_BY_NAME(0, UDC_STM32_IRQ_NAME, priority)

#define USB_OTG_HS_EMB_PHY (DT_HAS_COMPAT_STATUS_OKAY(st_stm32_usbphyc) && \
DT_HAS_COMPAT_STATUS_OKAY(st_stm32_otghs))

#define USB_OTG_HS_ULPI_PHY (DT_HAS_COMPAT_STATUS_OKAY(usb_ulpi_phy) && \
DT_HAS_COMPAT_STATUS_OKAY(st_stm32_otghs))

/**
* The following defines are used to map the value of the "maxiumum-speed"
* DT property to the corresponding definition used by the STM32 HAL.
Expand Down Expand Up @@ -962,12 +969,6 @@ static const struct udc_api udc_stm32_api = {
#define USB_BTABLE_SIZE 0
#endif /* USB */

#define USB_OTG_HS_EMB_PHY (DT_HAS_COMPAT_STATUS_OKAY(st_stm32_usbphyc) && \
DT_HAS_COMPAT_STATUS_OKAY(st_stm32_otghs))

#define USB_OTG_HS_ULPI_PHY (DT_HAS_COMPAT_STATUS_OKAY(usb_ulpi_phy) && \
DT_HAS_COMPAT_STATUS_OKAY(st_stm32_otghs))

static struct udc_stm32_data udc0_priv;

static struct udc_data udc0_data = {
Expand Down Expand Up @@ -1001,12 +1002,8 @@ static void priv_pcd_prepare(const struct device *dev)
priv->pcd.Instance = USB;
#elif defined(USB_DRD_FS)
priv->pcd.Instance = USB_DRD_FS;
#elif defined(USB_OTG_FS) || defined(USB_OTG_HS)
#if DT_HAS_COMPAT_STATUS_OKAY(st_stm32_otghs)
priv->pcd.Instance = USB_OTG_HS;
#else
priv->pcd.Instance = USB_OTG_FS;
#endif
#elif DT_HAS_COMPAT_STATUS_OKAY(st_stm32_otgfs) || DT_HAS_COMPAT_STATUS_OKAY(st_stm32_otghs)
priv->pcd.Instance = (USB_OTG_GlobalTypeDef *)UDC_STM32_BASE_ADDRESS;
#endif /* USB */

#if USB_OTG_HS_EMB_PHY
Expand Down Expand Up @@ -1061,6 +1058,15 @@ static int priv_clock_enable(void)
HAL_SYSCFG_SetOTGPHYReferenceClockSelection(SYSCFG_OTG_HS_PHY_CLK_SELECT_1);
/* Configuring the SYSCFG registers OTG_HS PHY : OTG_HS PHY enable*/
HAL_SYSCFG_EnableOTGPHY(SYSCFG_OTG_HS_PHY_ENABLE);
#elif DT_HAS_COMPAT_STATUS_OKAY(st_stm32n6_otghs)
/* Enable Vdd USB voltage monitoring */
LL_PWR_EnableVddUSBMonitoring();
while (__HAL_PWR_GET_FLAG(PWR_FLAG_USB33RDY)) {
/* Wait FOR VDD33USB ready */
}

/* Enable VDDUSB */
LL_PWR_EnableVddUSB();
#elif defined(PWR_USBSCR_USB33SV) || defined(PWR_SVMCR_USV)
/*
* VDDUSB independent USB supply (PWR clock is on)
Expand Down Expand Up @@ -1136,13 +1142,15 @@ static int priv_clock_enable(void)
/* Both OTG HS and USBPHY sleep clock MUST be disabled here at the same time */
LL_AHB2_GRP1_DisableClockStopSleep(LL_AHB2_GRP1_PERIPH_OTG_HS ||
LL_AHB2_GRP1_PERIPH_USBPHY);
#else
#elif !DT_HAS_COMPAT_STATUS_OKAY(st_stm32n6_otghs)
LL_AHB1_GRP1_DisableClockLowPower(LL_AHB1_GRP1_PERIPH_OTGHSULPI);
#endif /* defined(CONFIG_SOC_SERIES_STM32H7X) */

#if USB_OTG_HS_EMB_PHY
#if !DT_HAS_COMPAT_STATUS_OKAY(st_stm32n6_otghs)
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_OTGPHYC);
#endif
#endif
#elif defined(CONFIG_SOC_SERIES_STM32H7X) && DT_HAS_COMPAT_STATUS_OKAY(st_stm32_otgfs)
/* The USB2 controller only works in FS mode, but the ULPI clock needs
* to be disabled in sleep mode for it to work.
Expand Down Expand Up @@ -1171,9 +1179,11 @@ static int priv_clock_disable(void)
static struct udc_ep_config ep_cfg_in[DT_INST_PROP(0, num_bidir_endpoints)];
static struct udc_ep_config ep_cfg_out[DT_INST_PROP(0, num_bidir_endpoints)];

#if !DT_HAS_COMPAT_STATUS_OKAY(st_stm32n6_otghs)
PINCTRL_DT_INST_DEFINE(0);
static const struct pinctrl_dev_config *usb_pcfg =
PINCTRL_DT_INST_DEV_CONFIG_GET(0);
#endif

#if USB_OTG_HS_ULPI_PHY
static const struct gpio_dt_spec ulpi_reset =
Expand Down Expand Up @@ -1256,11 +1266,13 @@ static int udc_stm32_driver_init0(const struct device *dev)
IRQ_CONNECT(UDC_STM32_IRQ, UDC_STM32_IRQ_PRI, udc_stm32_irq,
DEVICE_DT_INST_GET(0), 0);

#if !DT_HAS_COMPAT_STATUS_OKAY(st_stm32n6_otghs)
err = pinctrl_apply_state(usb_pcfg, PINCTRL_STATE_DEFAULT);
if (err < 0) {
LOG_ERR("USB pinctrl setup failed (%d)", err);
return err;
}
#endif

#ifdef SYSCFG_CFGR1_USB_IT_RMP
/*
Expand Down
21 changes: 21 additions & 0 deletions dts/arm/st/n6/stm32n6.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,27 @@
#size-cells = <0>;
status = "disabled";
};

usbotg_hs1: otghs@58040000 {
compatible = "st,stm32n6-otghs", "st,stm32-otghs";
reg = <0x58040000 0x2000>;
interrupts = <177 0>;
interrupt-names = "otghs";
num-bidir-endpoints = <9>;
ram-size = <4096>;
maximum-speed = "high-speed";
clocks = <&rcc STM32_CLOCK(AHB5, 26)>,
<&rcc STM32_SRC_HSE OTGPHY1CKREF_SEL(1)>;
phys = <&usbphyc1>;
status = "disabled";
};

usbphyc1: usbphyc@5803fc00 {
compatible = "st,stm32-usbphyc";
reg = <0x5803FC00 0x400>;
clocks = <&rcc STM32_CLOCK(AHB5, 27)>;
#phy-cells = <0>;
};
};
};

Expand Down
27 changes: 27 additions & 0 deletions dts/bindings/usb/st,stm32-otghs-common.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright (c) 2025, STMicroelectronics
# SPDX-License-Identifier: Apache-2.0

# Common fields for STM32 OTGHS controller

include: [usb-ep.yaml, pinctrl-device.yaml]

properties:
reg:
required: true

interrupts:
required: true

ram-size:
type: int
required: true
description: |
Size of USB dedicated RAM. STM32 SOC's reference
manual defines a shared FIFO size.

phys:
type: phandle
description: PHY provider specifier

clocks:
required: true
Loading