Skip to content

Commit 55951b7

Browse files
authored
Merge pull request #2789 from hathach/enhance-disconect-connect-esp32
dwc2: for esp32 force disconnect/connect using USB_WRAP otg pad overr…
2 parents 4349e99 + 0bb7b99 commit 55951b7

File tree

5 files changed

+43
-30
lines changed

5 files changed

+43
-30
lines changed

.github/actions/setup_toolchain/action.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ runs:
3939
TOOLCHAIN_JSON='{
4040
"aarch64-gcc": "https://developer.arm.com/-/media/Files/downloads/gnu-a/10.3-2021.07/binrel/gcc-arm-10.3-2021.07-x86_64-aarch64-none-elf.tar.xz",
4141
"arm-clang": "https://github.com/ARM-software/LLVM-embedded-toolchain-for-Arm/releases/download/release-17.0.1/LLVMEmbeddedToolchainForArm-17.0.1-Linux-x86_64.tar.xz",
42-
"arm-iar": "",
43-
"arm-gcc": "",
4442
"msp430-gcc": "http://software-dl.ti.com/msp430/msp430_public_sw/mcu/msp430/MSPGCC/9_2_0_0/export/msp430-gcc-9.2.0.50_linux64.tar.bz2",
4543
"riscv-gcc": "https://github.com/xpack-dev-tools/riscv-none-elf-gcc-xpack/releases/download/v13.2.0-2/xpack-riscv-none-elf-gcc-13.2.0-2-linux-x64.tar.gz",
4644
"rx-gcc": "http://gcc-renesas.com/downloads/get.php?f=rx/8.3.0.202004-gnurx/gcc-8.3.0.202004-GNURX-ELF.run"

.github/actions/setup_toolchain/espressif/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ inputs:
55
description: 'Toolchain name'
66
required: true
77
toolchain_version:
8-
description: 'Toolchain URL or version'
8+
description: 'Toolchain version'
99
required: true
1010

1111
runs:

src/common/tusb_mcu.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@
336336
//--------------------------------------------------------------------+
337337
#elif TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3)
338338
#define TUP_USBIP_DWC2
339+
#define TUP_USBIP_DWC2_ESP32
339340
#define TUP_DCD_ENDPOINT_MAX 6
340341

341342
#elif TU_CHECK_MCU(OPT_MCU_ESP32, OPT_MCU_ESP32C2, OPT_MCU_ESP32C3, OPT_MCU_ESP32C6, OPT_MCU_ESP32H2)

src/portable/synopsys/dwc2/dcd_dwc2.c

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343

4444
#if defined(TUP_USBIP_DWC2_STM32)
4545
#include "dwc2_stm32.h"
46-
#elif TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3)
46+
#elif defined(TUP_USBIP_DWC2_ESP32)
4747
#include "dwc2_esp32.h"
4848
#elif TU_CHECK_MCU(OPT_MCU_GD32VF103)
4949
#include "dwc2_gd32.h"
@@ -667,12 +667,34 @@ void dcd_remote_wakeup(uint8_t rhport) {
667667
void dcd_connect(uint8_t rhport) {
668668
(void) rhport;
669669
dwc2_regs_t* dwc2 = DWC2_REG(rhport);
670+
671+
#ifdef TUP_USBIP_DWC2_ESP32
672+
usb_wrap_otg_conf_reg_t conf = USB_WRAP.otg_conf;
673+
conf.pad_pull_override = 0;
674+
conf.dp_pullup = 0;
675+
conf.dp_pulldown = 0;
676+
conf.dm_pullup = 0;
677+
conf.dm_pulldown = 0;
678+
USB_WRAP.otg_conf = conf;
679+
#endif
680+
670681
dwc2->dctl &= ~DCTL_SDIS;
671682
}
672683

673684
void dcd_disconnect(uint8_t rhport) {
674685
(void) rhport;
675686
dwc2_regs_t* dwc2 = DWC2_REG(rhport);
687+
688+
#ifdef TUP_USBIP_DWC2_ESP32
689+
usb_wrap_otg_conf_reg_t conf = USB_WRAP.otg_conf;
690+
conf.pad_pull_override = 1;
691+
conf.dp_pullup = 0;
692+
conf.dp_pulldown = 1;
693+
conf.dm_pullup = 0;
694+
conf.dm_pulldown = 1;
695+
USB_WRAP.otg_conf = conf;
696+
#endif
697+
676698
dwc2->dctl |= DCTL_SDIS;
677699
}
678700

src/portable/synopsys/dwc2/dwc2_esp32.h

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -32,60 +32,52 @@
3232
extern "C" {
3333
#endif
3434

35+
#include "freertos/task.h"
36+
3537
#include "esp_intr_alloc.h"
3638
#include "soc/periph_defs.h"
37-
//#include "soc/usb_periph.h"
38-
#include "freertos/task.h"
39+
#include "soc/usb_wrap_struct.h"
3940

4041
#define DWC2_REG_BASE 0x60080000UL
4142
#define DWC2_EP_MAX 6 // USB_OUT_EP_NUM. TODO ESP32Sx only has 5 tx fifo (5 endpoint IN)
4243

43-
static const dwc2_controller_t _dwc2_controller[] =
44-
{
44+
static const dwc2_controller_t _dwc2_controller[] = {
4545
{ .reg_base = DWC2_REG_BASE, .irqnum = 0, .ep_count = DWC2_EP_MAX, .ep_fifo_size = 1024 }
4646
};
4747

4848
static intr_handle_t usb_ih;
4949

50-
static void dcd_int_handler_wrap(void* arg)
51-
{
52-
(void) arg;
50+
static void dcd_int_handler_wrap(void* arg) {
51+
(void)arg;
5352
dcd_int_handler(0);
5453
}
5554

56-
TU_ATTR_ALWAYS_INLINE
57-
static inline void dwc2_dcd_int_enable (uint8_t rhport)
58-
{
59-
(void) rhport;
55+
TU_ATTR_ALWAYS_INLINE static inline void dwc2_dcd_int_enable(uint8_t rhport) {
56+
(void)rhport;
6057
esp_intr_alloc(ETS_USB_INTR_SOURCE, ESP_INTR_FLAG_LOWMED, dcd_int_handler_wrap, NULL, &usb_ih);
6158
}
6259

63-
TU_ATTR_ALWAYS_INLINE
64-
static inline void dwc2_dcd_int_disable (uint8_t rhport)
65-
{
66-
(void) rhport;
60+
TU_ATTR_ALWAYS_INLINE static inline void dwc2_dcd_int_disable(uint8_t rhport) {
61+
(void)rhport;
6762
esp_intr_free(usb_ih);
6863
}
6964

70-
static inline void dwc2_remote_wakeup_delay(void)
71-
{
65+
TU_ATTR_ALWAYS_INLINE static inline void dwc2_remote_wakeup_delay(void) {
7266
vTaskDelay(pdMS_TO_TICKS(1));
7367
}
7468

7569
// MCU specific PHY init, called BEFORE core reset
76-
static inline void dwc2_phy_init(dwc2_regs_t * dwc2, uint8_t hs_phy_type)
77-
{
78-
(void) dwc2;
79-
(void) hs_phy_type;
70+
TU_ATTR_ALWAYS_INLINE static inline void dwc2_phy_init(dwc2_regs_t* dwc2, uint8_t hs_phy_type) {
71+
(void)dwc2;
72+
(void)hs_phy_type;
8073

8174
// nothing to do
8275
}
8376

8477
// MCU specific PHY update, it is called AFTER init() and core reset
85-
static inline void dwc2_phy_update(dwc2_regs_t * dwc2, uint8_t hs_phy_type)
86-
{
87-
(void) dwc2;
88-
(void) hs_phy_type;
78+
TU_ATTR_ALWAYS_INLINE static inline void dwc2_phy_update(dwc2_regs_t* dwc2, uint8_t hs_phy_type) {
79+
(void)dwc2;
80+
(void)hs_phy_type;
8981

9082
// nothing to do
9183
}
@@ -94,4 +86,4 @@ static inline void dwc2_phy_update(dwc2_regs_t * dwc2, uint8_t hs_phy_type)
9486
}
9587
#endif
9688

97-
#endif /* _DWC2_ESP32_H_ */
89+
#endif

0 commit comments

Comments
 (0)