30
30
31
31
#include "esp32-hal-tinyusb.h"
32
32
#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"
33
35
34
36
typedef char tusb_str_t [127 ];
35
37
@@ -457,27 +459,22 @@ static void IRAM_ATTR usb_persist_shutdown_handler(void)
457
459
{
458
460
if (usb_persist_mode != RESTART_NO_PERSIST ){
459
461
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 ();
462
463
}
463
464
if (usb_persist_mode == RESTART_BOOTLOADER ) {
464
465
//USB CDC Download
465
466
if (usb_persist_enabled ) {
466
- USB_WRAP . date . val = USBDC_PERSIST_ENA ;
467
+ chip_usb_set_persist_flags ( USBDC_PERSIST_ENA ) ;
467
468
}
468
469
REG_WRITE (RTC_CNTL_OPTION1_REG , RTC_CNTL_FORCE_DOWNLOAD_BOOT );
469
- periph_module_disable (PERIPH_TIMG1_MODULE );
470
470
} else if (usb_persist_mode == RESTART_BOOTLOADER_DFU ) {
471
471
//DFU Download
472
- USB_WRAP . date . val = USBDC_BOOT_DFU ;
472
+ chip_usb_set_persist_flags ( USBDC_BOOT_DFU ) ;
473
473
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 );
476
474
} else if (usb_persist_enabled ) {
477
475
//USB Persist reboot
478
- USB_WRAP . date . val = USBDC_PERSIST_ENA ;
476
+ chip_usb_set_persist_flags ( USBDC_PERSIST_ENA ) ;
479
477
}
480
- SET_PERI_REG_MASK (RTC_CNTL_OPTIONS0_REG , RTC_CNTL_SW_PROCPU_RST );
481
478
}
482
479
}
483
480
@@ -531,7 +528,7 @@ esp_err_t tinyusb_init(tinyusb_device_config_t *config) {
531
528
periph_module_enable (PERIPH_USB_MODULE );
532
529
}
533
530
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 ) {
535
532
initialized = false;
536
533
return ESP_FAIL ;
537
534
}
@@ -550,11 +547,9 @@ esp_err_t tinyusb_init(tinyusb_device_config_t *config) {
550
547
551
548
void usb_persist_restart (restart_type_t mode )
552
549
{
553
- if (usb_persist_enabled && mode < RESTART_TYPE_MAX ) {
550
+ if (mode < RESTART_TYPE_MAX ) {
554
551
usb_persist_mode = mode ;
555
552
esp_restart ();
556
- } else {
557
- log_e ("Persistence is not enabled" );
558
553
}
559
554
}
560
555
0 commit comments