hi,sorry for the late reply.
I have tried the way as mentioned. and ESP32 saied it turn into download mode. but computer didn't recognize the device.
and here is my code(call reboot_dfu_set() in main() ).
- 微信图片_20230808143751.png (186.8 KiB) Viewed 866 times
Code: Select all
/* USB interrupt handler, forward the call to the ROM driver.
* Non-static to allow placement into IRAM by ldgen.
*/
void esp_usb_console_interrupt(void *arg) {
usb_dc_check_poll_for_interrupts();
/* Restart can be requested from esp_usb_console_cdc_acm_cb or esp_usb_console_dfu_detach_cb */
ESP_LOGI("DFU","[esp_usb_console_interrupt]");
esp_restart();
}
void reboot_dfu_set() {
esp_err_t err = esp_register_shutdown_handler(esp_usb_console_before_restart);
if (err != ESP_OK) {
ESP_LOGE("DFU", "[reboot_dfu_set] shutdown handler set failed.");
return;
}
err = esp_intr_alloc(ETS_USB_INTR_SOURCE, ISR_FLAG | ESP_INTR_FLAG_INTRDISABLED,
esp_usb_console_interrupt, NULL, &s_usb_int_handle);
/* Initialize USB / CDC */
s_cdc_acm_device = cdc_acm_init(cdcmem, CDC_WORK_BUF_SIZE);
usb_dc_check_poll_for_interrupts();
/* Set callback for handling DTR/RTS lines and TX/RX events */
// cdc_acm_irq_callback_set(s_cdc_acm_device, esp_usb_console_cdc_acm_cb);
cdc_acm_irq_state_enable(s_cdc_acm_device);
chip_usb_set_persist_flags(USBDC_BOOT_DFU);
REG_WRITE(RTC_CNTL_OPTION1_REG, RTC_CNTL_FORCE_DOWNLOAD_BOOT);
ESP_LOGD("DFU", "set finished.");
vTaskDelay(pdMS_TO_TICKS(10000));
ESP_LOGD("DFU", "restart now");
vTaskDelay(pdMS_TO_TICKS(100));
esp_restart();
}
void esp_usb_console_before_restart(void) {
usb_dc_prepare_persist();
chip_usb_set_persist_flags(USBDC_BOOT_DFU);
REG_WRITE(RTC_CNTL_OPTION1_REG, RTC_CNTL_FORCE_DOWNLOAD_BOOT);
}