Skip to content

Commit 01143bd

Browse files
committed
gpio: fix USB D+ pin cannot disable pullup
Internally, disable usb serial jtag DP pin's pullup when calling gpio_ll_pullup_dis and rtcio_ll_pullup_disable At usb serial jtag setup/install, re-enable DP pin's pullup Closes #9495
1 parent 1669a5d commit 01143bd

File tree

9 files changed

+110
-0
lines changed

9 files changed

+110
-0
lines changed

components/driver/usb_serial_jtag.c

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <stdbool.h>
99
#include "esp_log.h"
1010
#include "hal/usb_serial_jtag_ll.h"
11+
#include "hal/usb_phy_ll.h"
1112
#include "freertos/FreeRTOS.h"
1213
#include "freertos/semphr.h"
1314
#include "freertos/ringbuf.h"
@@ -112,6 +113,9 @@ esp_err_t usb_serial_jtag_driver_install(usb_serial_jtag_driver_config_t *usb_se
112113
goto _exit;
113114
}
114115

116+
// Configure PHY
117+
usb_phy_ll_int_jtag_enable(&USB_SERIAL_JTAG);
118+
115119
usb_serial_jtag_ll_clr_intsts_mask(USB_SERIAL_JTAG_INTR_SERIAL_IN_EMPTY|
116120
USB_SERIAL_JTAG_INTR_SERIAL_OUT_RECV_PKT);
117121
usb_serial_jtag_ll_ena_intr_mask(USB_SERIAL_JTAG_INTR_SERIAL_IN_EMPTY|

components/hal/esp32c3/include/hal/gpio_ll.h

+6
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ static inline void gpio_ll_pullup_en(gpio_dev_t *hw, uint32_t gpio_num)
5151
*/
5252
static inline void gpio_ll_pullup_dis(gpio_dev_t *hw, uint32_t gpio_num)
5353
{
54+
// The pull-up value of the USB pins are controlled by the pins’ pull-up value together with USB pull-up value
55+
// USB DP pin is default to PU enabled
56+
if (gpio_num == USB_DP_GPIO_NUM) {
57+
SET_PERI_REG_MASK(USB_SERIAL_JTAG_CONF0_REG, USB_SERIAL_JTAG_PAD_PULL_OVERRIDE);
58+
CLEAR_PERI_REG_MASK(USB_SERIAL_JTAG_CONF0_REG, USB_SERIAL_JTAG_DP_PULLUP);
59+
}
5460
REG_CLR_BIT(GPIO_PIN_MUX_REG[gpio_num], FUN_PU);
5561
}
5662

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#pragma once
8+
9+
#include "soc/usb_serial_jtag_struct.h"
10+
11+
#ifdef __cplusplus
12+
extern "C" {
13+
#endif
14+
15+
/**
16+
* @brief Configures the internal PHY for USB_Serial_JTAG
17+
*
18+
* @param hw Start address of the USB Serial_JTAG registers
19+
*/
20+
static inline void usb_phy_ll_int_jtag_enable(usb_serial_jtag_dev_t *hw)
21+
{
22+
// USB_Serial_JTAG use internal PHY
23+
hw->conf0.phy_sel = 0;
24+
// Disable software control USB D+ D- pullup pulldown (Device FS: dp_pullup = 1)
25+
hw->conf0.pad_pull_override = 0;
26+
// Enable USB D+ pullup
27+
hw->conf0.dp_pullup = 1;
28+
// Enable USB pad function
29+
hw->conf0.usb_pad_enable = 1;
30+
}
31+
32+
#ifdef __cplusplus
33+
}
34+
#endif
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#pragma once
8+
9+
#include "soc/usb_serial_jtag_struct.h"
10+
11+
#ifdef __cplusplus
12+
extern "C" {
13+
#endif
14+
15+
/**
16+
* @brief Configures the internal PHY for USB_Serial_JTAG
17+
*
18+
* @param hw Start address of the USB Serial_JTAG registers
19+
*/
20+
static inline void usb_phy_ll_int_jtag_enable(usb_serial_jtag_dev_t *hw)
21+
{
22+
// USB_Serial_JTAG use internal PHY
23+
hw->conf0.phy_sel = 0;
24+
// Disable software control USB D+ D- pullup pulldown (Device FS: dp_pullup = 1)
25+
hw->conf0.pad_pull_override = 0;
26+
// Enable USB D+ pullup
27+
hw->conf0.dp_pullup = 1;
28+
// Enable USB pad function
29+
hw->conf0.usb_pad_enable = 1;
30+
}
31+
32+
#ifdef __cplusplus
33+
}
34+
#endif

components/hal/esp32h2/include/rev1/hal/gpio_ll.h

+6
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ static inline void gpio_ll_pullup_en(gpio_dev_t *hw, uint32_t gpio_num)
5151
*/
5252
static inline void gpio_ll_pullup_dis(gpio_dev_t *hw, uint32_t gpio_num)
5353
{
54+
// The pull-up value of the USB pins are controlled by the pins’ pull-up value together with USB pull-up value
55+
// USB DP pin is default to PU enabled
56+
if (gpio_num == USB_DP_GPIO_NUM) {
57+
SET_PERI_REG_MASK(USB_SERIAL_JTAG_CONF0_REG, USB_SERIAL_JTAG_PAD_PULL_OVERRIDE);
58+
CLEAR_PERI_REG_MASK(USB_SERIAL_JTAG_CONF0_REG, USB_SERIAL_JTAG_DP_PULLUP);
59+
}
5460
REG_CLR_BIT(GPIO_PIN_MUX_REG[gpio_num], FUN_PU);
5561
}
5662

components/hal/esp32h2/include/rev2/hal/gpio_ll.h

+6
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ static inline void gpio_ll_pullup_en(gpio_dev_t *hw, uint32_t gpio_num)
5151
*/
5252
static inline void gpio_ll_pullup_dis(gpio_dev_t *hw, uint32_t gpio_num)
5353
{
54+
// The pull-up value of the USB pins are controlled by the pins’ pull-up value together with USB pull-up value
55+
// USB DP pin is default to PU enabled
56+
if (gpio_num == USB_DP_GPIO_NUM) {
57+
SET_PERI_REG_MASK(USB_SERIAL_JTAG_CONF0_REG, USB_SERIAL_JTAG_PAD_PULL_OVERRIDE);
58+
CLEAR_PERI_REG_MASK(USB_SERIAL_JTAG_CONF0_REG, USB_SERIAL_JTAG_DP_PULLUP);
59+
}
5460
REG_CLR_BIT(GPIO_PIN_MUX_REG[gpio_num], FUN_PU);
5561
}
5662

components/hal/esp32s3/include/hal/gpio_ll.h

+8
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ static inline void gpio_ll_pullup_en(gpio_dev_t *hw, uint32_t gpio_num)
5252
*/
5353
static inline void gpio_ll_pullup_dis(gpio_dev_t *hw, uint32_t gpio_num)
5454
{
55+
// The pull-up value of the USB pins are controlled by the pins’ pull-up value together with USB pull-up value
56+
// USB DP pin is default to PU enabled
57+
// Note that from esp32s3 ECO1, USB_EXCHG_PINS feature has been supported. If this efuse is burnt, the gpio pin
58+
// which should be checked is USB_DM_GPIO_NUM instead.
59+
if (gpio_num == USB_DP_GPIO_NUM) {
60+
SET_PERI_REG_MASK(USB_SERIAL_JTAG_CONF0_REG, USB_SERIAL_JTAG_PAD_PULL_OVERRIDE);
61+
CLEAR_PERI_REG_MASK(USB_SERIAL_JTAG_CONF0_REG, USB_SERIAL_JTAG_DP_PULLUP);
62+
}
5563
REG_CLR_BIT(GPIO_PIN_MUX_REG[gpio_num], FUN_PU);
5664
}
5765

components/hal/esp32s3/include/hal/rtc_io_ll.h

+10
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#include "soc/rtc_io_struct.h"
1818
#include "hal/rtc_io_types.h"
1919
#include "hal/gpio_types.h"
20+
#include "soc/io_mux_reg.h"
21+
#include "soc/usb_serial_jtag_reg.h"
2022

2123
#ifdef __cplusplus
2224
extern "C" {
@@ -181,6 +183,14 @@ static inline void rtcio_ll_pullup_enable(int rtcio_num)
181183
*/
182184
static inline void rtcio_ll_pullup_disable(int rtcio_num)
183185
{
186+
// The pull-up value of the USB pins are controlled by the pins’ pull-up value together with USB pull-up value
187+
// USB DP pin is default to PU enabled
188+
// Note that from esp32s3 ECO1, USB_EXCHG_PINS feature has been supported. If this efuse is burnt, the gpio pin
189+
// which should be checked is USB_DM_GPIO_NUM instead.
190+
if (rtcio_num == USB_DP_GPIO_NUM) {
191+
SET_PERI_REG_MASK(USB_SERIAL_JTAG_CONF0_REG, USB_SERIAL_JTAG_PAD_PULL_OVERRIDE);
192+
CLEAR_PERI_REG_MASK(USB_SERIAL_JTAG_CONF0_REG, USB_SERIAL_JTAG_DP_PULLUP);
193+
}
184194
if (rtc_io_desc[rtcio_num].pullup) {
185195
CLEAR_PERI_REG_MASK(rtc_io_desc[rtcio_num].reg, rtc_io_desc[rtcio_num].pullup);
186196
}

components/hal/esp32s3/include/hal/usb_phy_ll.h

+2
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ static inline void usb_phy_ll_int_jtag_enable(usb_serial_jtag_dev_t *hw)
5959
hw->conf0.phy_sel = 0;
6060
// Disable software control USB D+ D- pullup pulldown (Device FS: dp_pullup = 1)
6161
hw->conf0.pad_pull_override = 0;
62+
// Enable USB D+ pullup
63+
hw->conf0.dp_pullup = 1;
6264
// Enable USB pad function
6365
hw->conf0.usb_pad_enable = 1;
6466
// phy_sel is controlled by the following register value

0 commit comments

Comments
 (0)