Skip to content

Commit 455e21f

Browse files
committed
correct esp32s2 reset to download mode
1 parent ad36148 commit 455e21f

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/arduino/ports/esp32/Adafruit_TinyUSB_esp32.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,6 @@ static void usb_device_task(void *param) {
115115
void TinyUSB_Port_InitDevice(uint8_t rhport) {
116116
(void)rhport;
117117

118-
REG_CLR_BIT(RTC_CNTL_USB_CONF_REG, RTC_CNTL_IO_MUX_RESET_DISABLE);
119-
REG_CLR_BIT(RTC_CNTL_USB_CONF_REG, RTC_CNTL_USB_RESET_DISABLE);
120-
121118
// Reset USB module
122119
periph_module_reset(PERIPH_USB_MODULE);
123120
periph_module_enable(PERIPH_USB_MODULE);
@@ -126,6 +123,10 @@ void TinyUSB_Port_InitDevice(uint8_t rhport) {
126123
usb_hal_init(&hal);
127124
configure_pins(&hal);
128125

126+
// reset core, should be in dcd_esp32sx.c (do that later with more proper testing)
127+
USB0.grstctl |= USB_CSFTRST;
128+
while ((USB0.grstctl & USB_CSFTRST) == USB_CSFTRST) {}
129+
129130
tusb_init();
130131

131132
// Create a task for tinyusb device stack
@@ -136,8 +137,9 @@ void TinyUSB_Port_InitDevice(uint8_t rhport) {
136137
void TinyUSB_Port_EnterDFU(void) {
137138
// Reset to Bootloader
138139

139-
periph_module_reset(PERIPH_USB_MODULE);
140-
periph_module_enable(PERIPH_USB_MODULE);
140+
// Reset USB Core
141+
USB0.grstctl |= USB_CSFTRST;
142+
while ((USB0.grstctl & USB_CSFTRST) == USB_CSFTRST) {}
141143

142144
REG_WRITE(RTC_CNTL_OPTION1_REG, RTC_CNTL_FORCE_DOWNLOAD_BOOT);
143145
esp_restart();

0 commit comments

Comments
 (0)