Skip to content

Commit dfcc0b2

Browse files
Merge branch 'fix/periodic_fs_usb_on_p4' into 'master'
fix(usb/host): Fixed Full Speed periodic transfers on ESP32-P4 Closes IDF-11988 See merge request espressif/esp-idf!36560
2 parents 7d1d949 + 125a3f0 commit dfcc0b2

File tree

6 files changed

+61
-16
lines changed

6 files changed

+61
-16
lines changed

components/hal/usb_dwc_hal.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,8 @@ void usb_dwc_hal_chan_set_ep_char(usb_dwc_hal_context_t *hal, usb_dwc_hal_chan_t
395395
} else {
396396
tokens_per_frame = 8; // 1 token every microframe
397397
}
398+
} else {
399+
tokens_per_frame = 8;
398400
}
399401
usb_dwc_ll_hctsiz_set_sched_info(chan_obj->regs, tokens_per_frame, ep_char->periodic.offset);
400402
}

components/soc/esp32p4/usb_dwc_periph.c

Lines changed: 10 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,17 @@ 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
45+
.supported_phys = USB_PHY_INST_UTMI_0,
3946
.irq = ETS_USB_OTG_INTR_SOURCE,
4047
.irq_2nd_cpu = ETS_USB_OTG_ENDP_MULTI_PROC_INTR_SOURCE,
4148
},
4249
// Full-Speed USB-DWC
4350
[1] = {
4451
.fsls_signals = NULL,
4552
.otg_signals = &dwc_fs_otg_signals,
53+
.internal_phy_io = &internal_phy_io,
54+
.supported_phys = USB_PHY_INST_FSLS_INTERN_0,
4655
.irq = ETS_USB_OTG11_CH0_INTR_SOURCE,
4756
.irq_2nd_cpu = -1,
4857
},

components/soc/esp32s2/usb_dwc_periph.c

Lines changed: 9 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,20 @@ 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,
55+
.supported_phys = USB_PHY_INST_FSLS_INTERN_0,
5056
.irq = ETS_USB_INTR_SOURCE,
5157
.irq_2nd_cpu = -1,
5258
},
@@ -55,6 +61,7 @@ const usb_dwc_info_t usb_dwc_info = {
5561

5662
/* ------------------------------- Deprecated ------------------------------- */
5763

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

components/soc/esp32s3/usb_dwc_periph.c

Lines changed: 9 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,20 @@ 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,
55+
.supported_phys = USB_PHY_INST_FSLS_INTERN_0,
5156
.irq = ETS_USB_INTR_SOURCE,
5257
.irq_2nd_cpu = -1,
5358
},
@@ -56,6 +61,7 @@ const usb_dwc_info_t usb_dwc_info = {
5661

5762
/* ------------------------------- Deprecated ------------------------------- */
5863

64+
#include "soc/usb_periph.h"
5965
/*
6066
Note: These IO pins are deprecated. When connecting USB OTG to an external FSLS
6167
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: 28 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" {
@@ -21,6 +16,16 @@ extern "C" {
2116

2217
/* ---------------------------------- Types --------------------------------- */
2318

19+
/**
20+
* @brief USB PHY Instance Type
21+
*/
22+
typedef enum {
23+
USB_PHY_INST_FSLS_INTERN_0 = (1 << 0),
24+
USB_PHY_INST_FSLS_INTERN_1 = (1 << 1),
25+
USB_PHY_INST_UTMI_0 = (1 << 2),
26+
USB_PHY_INST_EXTERN = (1 << 3),
27+
} usb_phy_inst_t;
28+
2429
/**
2530
* @brief USB PHY FSLS Serial Interface Signals
2631
*
@@ -65,15 +70,30 @@ typedef struct {
6570
int dischrgvbus;
6671
} usb_otg_signal_conn_t;
6772

73+
/**
74+
* @brief Internal USB PHY IO
75+
*
76+
* Structure to store the IO numbers for a particular internal USB PHY
77+
*/
78+
typedef struct {
79+
int dp;
80+
int dm;
81+
} usb_internal_phy_io_t;
82+
6883
/**
6984
* @brief USB Controller Information
7085
*
7186
* Structure to store information for all USB-DWC instances
87+
*
88+
* For targets with multiple USB controllers, we support only fixed mapping of the PHYs.
89+
* This is a software limitation; the hardware supports swapping Controllers and PHYs.
7290
*/
7391
typedef struct {
7492
struct {
7593
const usb_fsls_serial_signal_conn_t * const fsls_signals; // Must be set if external PHY is supported by controller
7694
const usb_otg_signal_conn_t * const otg_signals;
95+
const usb_internal_phy_io_t * const internal_phy_io; // Must be set for internal FSLS PHY(s)
96+
const usb_phy_inst_t supported_phys; // Bitmap of supported PHYs by this controller
7797
const int irq;
7898
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
7999
} controllers [SOC_USB_OTG_PERIPH_NUM];
@@ -85,6 +105,8 @@ extern const usb_dwc_info_t usb_dwc_info;
85105

86106
/* ------------------------------- Deprecated ------------------------------- */
87107
/* Todo: Remove in ESP-IDF v6.0 (IDF-9052) */
108+
#include <stdint.h>
109+
#include "soc/periph_defs.h"
88110

89111
#if SOC_USB_OTG_SUPPORTED
90112

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)