Skip to content

Commit 5b5b61c

Browse files
committed
rework persist reboot
1 parent cbafe67 commit 5b5b61c

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

cores/esp32/esp32-hal-tinyusb.c

+8-13
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030

3131
#include "esp32-hal-tinyusb.h"
3232
#include "esp32s2/rom/usb/usb_persist.h"
33+
#include "esp32s2/rom/usb/usb_dc.h"
34+
#include "esp32s2/rom/usb/chip_usb_dw_wrapper.h"
3335

3436
typedef char tusb_str_t[127];
3537

@@ -457,27 +459,22 @@ static void IRAM_ATTR usb_persist_shutdown_handler(void)
457459
{
458460
if(usb_persist_mode != RESTART_NO_PERSIST){
459461
if (usb_persist_enabled) {
460-
REG_SET_BIT(RTC_CNTL_USB_CONF_REG, RTC_CNTL_IO_MUX_RESET_DISABLE);
461-
REG_SET_BIT(RTC_CNTL_USB_CONF_REG, RTC_CNTL_USB_RESET_DISABLE);
462+
usb_dc_prepare_persist();
462463
}
463464
if (usb_persist_mode == RESTART_BOOTLOADER) {
464465
//USB CDC Download
465466
if (usb_persist_enabled) {
466-
USB_WRAP.date.val = USBDC_PERSIST_ENA;
467+
chip_usb_set_persist_flags(USBDC_PERSIST_ENA);
467468
}
468469
REG_WRITE(RTC_CNTL_OPTION1_REG, RTC_CNTL_FORCE_DOWNLOAD_BOOT);
469-
periph_module_disable(PERIPH_TIMG1_MODULE);
470470
} else if (usb_persist_mode == RESTART_BOOTLOADER_DFU) {
471471
//DFU Download
472-
USB_WRAP.date.val = USBDC_BOOT_DFU;
472+
chip_usb_set_persist_flags(USBDC_BOOT_DFU);
473473
REG_WRITE(RTC_CNTL_OPTION1_REG, RTC_CNTL_FORCE_DOWNLOAD_BOOT);
474-
periph_module_disable(PERIPH_TIMG0_MODULE);
475-
periph_module_disable(PERIPH_TIMG1_MODULE);
476474
} else if (usb_persist_enabled) {
477475
//USB Persist reboot
478-
USB_WRAP.date.val = USBDC_PERSIST_ENA;
476+
chip_usb_set_persist_flags(USBDC_PERSIST_ENA);
479477
}
480-
SET_PERI_REG_MASK(RTC_CNTL_OPTIONS0_REG, RTC_CNTL_SW_PROCPU_RST);
481478
}
482479
}
483480

@@ -531,7 +528,7 @@ esp_err_t tinyusb_init(tinyusb_device_config_t *config) {
531528
periph_module_enable(PERIPH_USB_MODULE);
532529
}
533530

534-
if (usb_persist_enabled && esp_register_shutdown_handler(usb_persist_shutdown_handler) != ESP_OK) {
531+
if (esp_register_shutdown_handler(usb_persist_shutdown_handler) != ESP_OK) {
535532
initialized = false;
536533
return ESP_FAIL;
537534
}
@@ -550,11 +547,9 @@ esp_err_t tinyusb_init(tinyusb_device_config_t *config) {
550547

551548
void usb_persist_restart(restart_type_t mode)
552549
{
553-
if (usb_persist_enabled && mode < RESTART_TYPE_MAX) {
550+
if (mode < RESTART_TYPE_MAX) {
554551
usb_persist_mode = mode;
555552
esp_restart();
556-
} else {
557-
log_e("Persistence is not enabled");
558553
}
559554
}
560555

0 commit comments

Comments
 (0)