7171// MACRO TYPEDEF CONSTANT ENUM DECLARATION
7272// --------------------------------------------------------------------+
7373
74- // Note: persist mode is mostly copied from esp32-hal-tinyusb.c from
75- // arduino-esp32 core.
76-
77- typedef enum {
78- RESTART_NO_PERSIST,
79- RESTART_PERSIST,
80- RESTART_BOOTLOADER,
81- RESTART_BOOTLOADER_DFU,
82- RESTART_TYPE_MAX
83- } restart_type_t ;
84-
85- static bool usb_persist_enabled = false ;
86- static restart_type_t usb_persist_mode = RESTART_NO_PERSIST;
87-
88- static void IRAM_ATTR usb_persist_shutdown_handler (void ) {
89- if (usb_persist_mode != RESTART_NO_PERSIST) {
90- if (usb_persist_enabled) {
91- usb_dc_prepare_persist ();
92- }
93- if (usb_persist_mode == RESTART_BOOTLOADER) {
94- // USB CDC Download
95- if (usb_persist_enabled) {
96- chip_usb_set_persist_flags (USBDC_PERSIST_ENA);
97- } else {
98- periph_module_reset (PERIPH_USB_MODULE);
99- periph_module_enable (PERIPH_USB_MODULE);
100- }
101- REG_WRITE (RTC_CNTL_OPTION1_REG, RTC_CNTL_FORCE_DOWNLOAD_BOOT);
102- } else if (usb_persist_mode == RESTART_BOOTLOADER_DFU) {
103- // DFU Download
104- chip_usb_set_persist_flags (USBDC_BOOT_DFU);
105- REG_WRITE (RTC_CNTL_OPTION1_REG, RTC_CNTL_FORCE_DOWNLOAD_BOOT);
106- } else if (usb_persist_enabled) {
107- // USB Persist reboot
108- chip_usb_set_persist_flags (USBDC_PERSIST_ENA);
109- }
110- }
111- }
112-
11374static void configure_pins (usb_hal_context_t *usb) {
11475 for (const usb_iopin_dsc_t *iopin = usb_periph_iopins; iopin->pin != -1 ;
11576 ++iopin) {
@@ -154,21 +115,12 @@ static void usb_device_task(void *param) {
154115void TinyUSB_Port_InitDevice (uint8_t rhport) {
155116 (void )rhport;
156117
157- // from esp32-hal_tinyusb
158- bool usb_did_persist = (USB_WRAP.date .val == USBDC_PERSIST_ENA);
159-
160- // if(usb_did_persist && usb_persist_enabled){
161- // Enable USB/IO_MUX peripheral reset, if coming from persistent reboot
162118 REG_CLR_BIT (RTC_CNTL_USB_CONF_REG, RTC_CNTL_IO_MUX_RESET_DISABLE);
163119 REG_CLR_BIT (RTC_CNTL_USB_CONF_REG, RTC_CNTL_USB_RESET_DISABLE);
164- // } else
165- if (!usb_did_persist || !usb_persist_enabled) {
166- // Reset USB module
167- periph_module_reset (PERIPH_USB_MODULE);
168- periph_module_enable (PERIPH_USB_MODULE);
169- }
170120
171- esp_register_shutdown_handler (usb_persist_shutdown_handler);
121+ // Reset USB module
122+ periph_module_reset (PERIPH_USB_MODULE);
123+ periph_module_enable (PERIPH_USB_MODULE);
172124
173125 usb_hal_context_t hal = {.use_external_phy = false };
174126 usb_hal_init (&hal);
@@ -183,13 +135,15 @@ void TinyUSB_Port_InitDevice(uint8_t rhport) {
183135
184136void TinyUSB_Port_EnterDFU (void ) {
185137 // Reset to Bootloader
186- usb_persist_mode = RESTART_BOOTLOADER;
138+
139+ periph_module_reset (PERIPH_USB_MODULE);
140+ periph_module_enable (PERIPH_USB_MODULE);
141+
142+ REG_WRITE (RTC_CNTL_OPTION1_REG, RTC_CNTL_FORCE_DOWNLOAD_BOOT);
187143 esp_restart ();
188144}
189145
190146uint8_t TinyUSB_Port_GetSerialNumber (uint8_t serial_id[16 ]) {
191- uint32_t *serial_32 = (uint32_t *)serial_id;
192-
193147 /* Get the MAC address */
194148 const uint32_t mac0 =
195149 __builtin_bswap32 (REG_GET_FIELD (EFUSE_RD_MAC_SPI_SYS_0_REG, EFUSE_MAC_0));
0 commit comments