Skip to content

Commit ce59bd4

Browse files
fix(usb): Fixed missing GPIO drive capability on ESP32-P4
All USB PHYs that share their IOs with GPIOs must set the GPIO's drive capability to maximum.
1 parent 91f0cb4 commit ce59bd4

File tree

5 files changed

+44
-16
lines changed

5 files changed

+44
-16
lines changed

components/soc/esp32p4/usb_dwc_periph.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -28,6 +28,11 @@ static const usb_otg_signal_conn_t dwc_fs_otg_signals = {
2828
.dischrgvbus = USB_SRP_DISCHRGVBUS_PAD_OUT_IDX,
2929
};
3030

31+
static const usb_internal_phy_io_t internal_phy_io = {
32+
.dp = 27,
33+
.dm = 26,
34+
};
35+
3136
/* --------------------------------- Public --------------------------------- */
3237

3338
const usb_dwc_info_t usb_dwc_info = {
@@ -36,13 +41,15 @@ const usb_dwc_info_t usb_dwc_info = {
3641
[0] = {
3742
.fsls_signals = NULL,
3843
.otg_signals = NULL,
44+
.internal_phy_io = NULL, // HS PHY is not mapped to any GPIO
3945
.irq = ETS_USB_OTG_INTR_SOURCE,
4046
.irq_2nd_cpu = ETS_USB_OTG_ENDP_MULTI_PROC_INTR_SOURCE,
4147
},
4248
// Full-Speed USB-DWC
4349
[1] = {
4450
.fsls_signals = NULL,
4551
.otg_signals = &dwc_fs_otg_signals,
52+
.internal_phy_io = &internal_phy_io,
4653
.irq = ETS_USB_OTG11_CH0_INTR_SOURCE,
4754
.irq_2nd_cpu = -1,
4855
},

components/soc/esp32s2/usb_dwc_periph.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
/*
2-
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

77
#include "soc/gpio_sig_map.h"
8-
#include "soc/usb_periph.h"
98
#include "soc/interrupts.h"
109
#include "soc/usb_dwc_periph.h"
1110

@@ -40,13 +39,19 @@ static const usb_otg_signal_conn_t otg_signals = {
4039
.dischrgvbus = USB_SRP_DISCHRGVBUS_IDX,
4140
};
4241

42+
static const usb_internal_phy_io_t internal_phy_io = {
43+
.dp = 20,
44+
.dm = 19,
45+
};
46+
4347
/* --------------------------------- Public --------------------------------- */
4448

4549
const usb_dwc_info_t usb_dwc_info = {
4650
.controllers = {
4751
[0] = {
4852
.fsls_signals = &fsls_signals,
4953
.otg_signals = &otg_signals,
54+
.internal_phy_io = &internal_phy_io,
5055
.irq = ETS_USB_INTR_SOURCE,
5156
.irq_2nd_cpu = -1,
5257
},
@@ -55,6 +60,7 @@ const usb_dwc_info_t usb_dwc_info = {
5560

5661
/* ------------------------------- Deprecated ------------------------------- */
5762

63+
#include "soc/usb_periph.h"
5864
/*
5965
Note: These IO pins are deprecated. When connecting USB OTG to an external FSLS
6066
PHY, the FSLS Serial Interface signals can be routed to any GPIO via the GPIO

components/soc/esp32s3/usb_dwc_periph.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
/*
2-
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
#include <stddef.h>
87
#include "soc/gpio_sig_map.h"
9-
#include "soc/usb_periph.h"
108
#include "soc/interrupts.h"
119
#include "soc/usb_dwc_periph.h"
1210

@@ -41,13 +39,19 @@ static const usb_otg_signal_conn_t otg_signals = {
4139
.dischrgvbus = USB_SRP_DISCHRGVBUS_IDX,
4240
};
4341

42+
static const usb_internal_phy_io_t internal_phy_io = {
43+
.dp = 20,
44+
.dm = 19,
45+
};
46+
4447
/* --------------------------------- Public --------------------------------- */
4548

4649
const usb_dwc_info_t usb_dwc_info = {
4750
.controllers = {
4851
[0] = {
4952
.fsls_signals = &fsls_signals,
5053
.otg_signals = &otg_signals,
54+
.internal_phy_io = &internal_phy_io,
5155
.irq = ETS_USB_INTR_SOURCE,
5256
.irq_2nd_cpu = -1,
5357
},
@@ -56,6 +60,7 @@ const usb_dwc_info_t usb_dwc_info = {
5660

5761
/* ------------------------------- Deprecated ------------------------------- */
5862

63+
#include "soc/usb_periph.h"
5964
/*
6065
Note: These IO pins are deprecated. When connecting USB OTG to an external FSLS
6166
PHY, the FSLS Serial Interface signals can be routed to any GPIO via the GPIO

components/soc/include/soc/usb_dwc_periph.h

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
/*
2-
* SPDX-FileCopyrightText: 2020-2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2020-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

77
#pragma once
88

9-
#include <stdint.h>
10-
#include <stdbool.h>
11-
#include "soc/soc_pins.h"
129
#include "soc/soc_caps.h"
13-
#include "soc/periph_defs.h"
14-
#include "soc/gpio_sig_map.h"
1510

1611
#ifdef __cplusplus
1712
extern "C" {
@@ -65,15 +60,29 @@ typedef struct {
6560
int dischrgvbus;
6661
} usb_otg_signal_conn_t;
6762

63+
/**
64+
* @brief Internal USB PHY IO
65+
*
66+
* Structure to store the IO numbers for a particular internal USB PHY
67+
*/
68+
typedef struct {
69+
int dp;
70+
int dm;
71+
} usb_internal_phy_io_t;
72+
6873
/**
6974
* @brief USB Controller Information
7075
*
7176
* Structure to store information for all USB-DWC instances
77+
*
78+
* For targets with multiple USB controllers, we support only fixed mapping of the PHYs.
79+
* This is a software limitation; the hardware supports swapping Controllers and PHYs.
7280
*/
7381
typedef struct {
7482
struct {
7583
const usb_fsls_serial_signal_conn_t * const fsls_signals; // Must be set if external PHY is supported by controller
7684
const usb_otg_signal_conn_t * const otg_signals;
85+
const usb_internal_phy_io_t * const internal_phy_io; // Must be set for internal FSLS PHY(s)
7786
const int irq;
7887
const int irq_2nd_cpu; // The USB-DWC can provide 2nd interrupt so each CPU can have its own interrupt line. Set to -1 if not supported
7988
} controllers [SOC_USB_OTG_PERIPH_NUM];
@@ -85,6 +94,8 @@ extern const usb_dwc_info_t usb_dwc_info;
8594

8695
/* ------------------------------- Deprecated ------------------------------- */
8796
/* Todo: Remove in ESP-IDF v6.0 (IDF-9052) */
97+
#include <stdint.h>
98+
#include "soc/periph_defs.h"
8899

89100
#if SOC_USB_OTG_SUPPORTED
90101

components/usb/usb_phy.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -369,12 +369,11 @@ esp_err_t usb_new_phy(const usb_phy_config_t *config, usb_phy_handle_t *handle_r
369369
}
370370

371371
// For FSLS PHY that shares pads with GPIO peripheral, we must set drive capability to 3 (40mA)
372-
#if !CONFIG_IDF_TARGET_ESP32P4 // TODO: We must set drive capability for FSLS PHY for P4 too, to pass Full Speed eye diagram test
373372
if (phy_target == USB_PHY_TARGET_INT) {
374-
gpio_set_drive_capability(USBPHY_DM_NUM, GPIO_DRIVE_CAP_3);
375-
gpio_set_drive_capability(USBPHY_DP_NUM, GPIO_DRIVE_CAP_3);
373+
assert(usb_dwc_info.controllers[otg11_index].internal_phy_io);
374+
gpio_set_drive_capability(usb_dwc_info.controllers[otg11_index].internal_phy_io->dm, GPIO_DRIVE_CAP_3);
375+
gpio_set_drive_capability(usb_dwc_info.controllers[otg11_index].internal_phy_io->dp, GPIO_DRIVE_CAP_3);
376376
}
377-
#endif
378377

379378
*handle_ret = (usb_phy_handle_t) phy_context;
380379
if (phy_target == USB_PHY_TARGET_EXT) {

0 commit comments

Comments
 (0)