Skip to content

Commit a7fcf86

Browse files
authored
fix: perimgr + begin (#9331)
* fix: perimgr + begin Fixes Perimgr setup in begin() Fixes issue with reset INTR mask preventing previous sent data to be read. Adds a INTR mask to end() to clear all pending interrupts. * Update cores/esp32/HWCDC.cpp * Update cores/esp32/HWCDC.cpp * Update cores/esp32/HWCDC.cpp * Update cores/esp32/HWCDC.cpp * Update cores/esp32/HWCDC.cpp * Update cores/esp32/HWCDC.cpp * Update cores/esp32/HWCDC.cpp * Update cores/esp32/HWCDC.cpp * Update HWCDC.cpp * Update HWCDC.cpp * Update cores/esp32/HWCDC.cpp * Update cores/esp32/HWCDC.cpp * Update cores/esp32/HWCDC.cpp * Update cores/esp32/HWCDC.cpp
1 parent 5bcaf99 commit a7fcf86

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed

Diff for: cores/esp32/HWCDC.cpp

+27-9
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,8 @@ static void ARDUINO_ISR_ATTR cdc0_write_char(char c) {
177177
}
178178

179179
HWCDC::HWCDC() {
180-
180+
perimanSetBusDeinit(ESP32_BUS_TYPE_USB_DM, HWCDC::deinit);
181+
perimanSetBusDeinit(ESP32_BUS_TYPE_USB_DP, HWCDC::deinit);
181182
}
182183

183184
HWCDC::~HWCDC(){
@@ -238,26 +239,43 @@ void HWCDC::begin(unsigned long baud)
238239
}
239240
}
240241
usb_serial_jtag_ll_disable_intr_mask(USB_SERIAL_JTAG_LL_INTR_MASK);
241-
usb_serial_jtag_ll_clr_intsts_mask(USB_SERIAL_JTAG_LL_INTR_MASK);
242242
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);
243243
if(!intr_handle && esp_intr_alloc(ETS_USB_SERIAL_JTAG_INTR_SOURCE, 0, hw_cdc_isr_handler, NULL, &intr_handle) != ESP_OK){
244244
isr_log_e("HW USB CDC failed to init interrupts");
245245
end();
246246
return;
247247
}
248-
if (perimanSetBusDeinit(ESP32_BUS_TYPE_USB_DM, HWCDC::deinit) && perimanSetBusDeinit(ESP32_BUS_TYPE_USB_DP, HWCDC::deinit)) {
249-
// Setting USB D+ D- pins
250-
perimanSetPinBus(USB_DM_GPIO_NUM, ESP32_BUS_TYPE_USB_DM, (void *) this, -1, -1);
251-
perimanSetPinBus(USB_DP_GPIO_NUM, ESP32_BUS_TYPE_USB_DP, (void *) this, -1, -1);
252-
} else {
253-
log_e("Serial JTAG Pins can't be set into Peripheral Manager.");
248+
// Setting USB D+ D- pins
249+
uint8_t pin = ESP32_BUS_TYPE_USB_DM;
250+
if(perimanGetPinBusType(pin) != ESP32_BUS_TYPE_INIT){
251+
if(!perimanClearPinBus(pin)){
252+
goto err;
253+
}
254+
}
255+
if(!perimanSetPinBus(pin, ESP32_BUS_TYPE_USB_DM, (void *) this, -1, -1)){
256+
goto err;
254257
}
258+
pin = ESP32_BUS_TYPE_USB_DP;
259+
if(perimanGetPinBusType(pin) != ESP32_BUS_TYPE_INIT){
260+
if(!perimanClearPinBus(pin)){
261+
goto err;
262+
}
263+
}
264+
if(!perimanSetPinBus(pin, ESP32_BUS_TYPE_USB_DP, (void *) this, -1, -1)){
265+
goto err;
266+
}
267+
return;
268+
269+
err:
270+
log_e("Serial JTAG Pin %u can't be set into Peripheral Manager.", pin);
271+
end();
255272
}
256273

257274
void HWCDC::end()
258275
{
259-
//Disable tx/rx interrupt.
276+
//Disable/clear/free tx/rx interrupt.
260277
usb_serial_jtag_ll_disable_intr_mask(USB_SERIAL_JTAG_LL_INTR_MASK);
278+
usb_serial_jtag_ll_clr_intsts_mask(USB_SERIAL_JTAG_LL_INTR_MASK);
261279
esp_intr_free(intr_handle);
262280
intr_handle = NULL;
263281
if(tx_lock != NULL) {

0 commit comments

Comments
 (0)