Skip to content

Commit d216665

Browse files
authored
fix: PHY initialization
Fixes the PHY initialization. After detaching the pin and ending the HW Serial, a new begin() wouldn't start the CDC because it lacked the proper PHY initialization.
1 parent 6959a41 commit d216665

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

cores/esp32/HWCDC.cpp

+10-7
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "soc/io_mux_reg.h"
2727
#pragma GCC diagnostic ignored "-Wvolatile"
2828
#include "hal/usb_serial_jtag_ll.h"
29+
#include "hal/usb_phy_ll.h"
2930
#pragma GCC diagnostic warning "-Wvolatile"
3031
#include "rom/ets_sys.h"
3132
#include "driver/usb_serial_jtag.h"
@@ -238,13 +239,6 @@ void HWCDC::begin(unsigned long baud)
238239
log_e("HW CDC TX Buffer error");
239240
}
240241
}
241-
usb_serial_jtag_ll_disable_intr_mask(USB_SERIAL_JTAG_LL_INTR_MASK);
242-
usb_serial_jtag_ll_ena_intr_mask(USB_SERIAL_JTAG_INTR_SERIAL_IN_EMPTY | USB_SERIAL_JTAG_INTR_SERIAL_OUT_RECV_PKT | USB_SERIAL_JTAG_INTR_BUS_RESET);
243-
if(!intr_handle && esp_intr_alloc(ETS_USB_SERIAL_JTAG_INTR_SOURCE, 0, hw_cdc_isr_handler, NULL, &intr_handle) != ESP_OK){
244-
isr_log_e("HW USB CDC failed to init interrupts");
245-
end();
246-
return;
247-
}
248242
// Setting USB D+ D- pins
249243
uint8_t pin = USB_DM_GPIO_NUM;
250244
if(perimanGetPinBusType(pin) != ESP32_BUS_TYPE_INIT){
@@ -264,6 +258,15 @@ void HWCDC::begin(unsigned long baud)
264258
if(!perimanSetPinBus(pin, ESP32_BUS_TYPE_USB_DP, (void *) this, -1, -1)){
265259
goto err;
266260
}
261+
// Configure PHY
262+
usb_phy_ll_int_jtag_enable(&USB_SERIAL_JTAG);
263+
usb_serial_jtag_ll_disable_intr_mask(USB_SERIAL_JTAG_LL_INTR_MASK);
264+
usb_serial_jtag_ll_ena_intr_mask(USB_SERIAL_JTAG_INTR_SERIAL_IN_EMPTY | USB_SERIAL_JTAG_INTR_SERIAL_OUT_RECV_PKT | USB_SERIAL_JTAG_INTR_BUS_RESET);
265+
if(!intr_handle && esp_intr_alloc(ETS_USB_SERIAL_JTAG_INTR_SOURCE, 0, hw_cdc_isr_handler, NULL, &intr_handle) != ESP_OK){
266+
isr_log_e("HW USB CDC failed to init interrupts");
267+
end();
268+
return;
269+
}
267270
return;
268271

269272
err:

0 commit comments

Comments
 (0)