if it is possible to enable DFU mode on ESP32-S3(S2) by software?

swortain
Posts: 4
Joined: Mon Jul 17, 2023 6:38 am

if it is possible to enable DFU mode on ESP32-S3(S2) by software?

Postby swortain » Mon Jul 17, 2023 6:45 am

Hi, I'm working on a project that using a USB HID on esp32-s3, and cannot control the GPIO0 phisically.
So I'm wonderring if I can enable the DFU mode by ESP32-S3 itself? like receivng a message on HID then the device reboot and go to the DFU mode rather then original USB HID origin.

swortain
Posts: 4
Joined: Mon Jul 17, 2023 6:38 am

Re: if it is possible to enable DFU mode on ESP32-S3(S2) by software?

Postby swortain » Tue Jul 18, 2023 1:40 am

BTW, I'm using ESP as a USB HID device, so if I still need set the USB_PHY_SEL eFuse?

MicroController
Posts: 1708
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: if it is possible to enable DFU mode on ESP32-S3(S2) by software?

Postby MicroController » Tue Jul 18, 2023 10:58 pm

viewtopic.php?f=2&t=30811#p106733 says it is possible.

viewtopic.php?f=2&t=34013 also mentions how it's supposed to work.

swortain
Posts: 4
Joined: Mon Jul 17, 2023 6:38 am

Re: if it is possible to enable DFU mode on ESP32-S3(S2) by software?

Postby swortain » Tue Aug 08, 2023 6:40 am

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
微信图片_20230808143751.png (186.8 KiB) Viewed 873 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);
}

swortain
Posts: 4
Joined: Mon Jul 17, 2023 6:38 am

Re: if it is possible to enable DFU mode on ESP32-S3(S2) by software?

Postby swortain » Tue Aug 08, 2023 9:09 am

Hi, I find where the problem is.
Cause I need ESP32 act as HID device, I used tinyusb and if I call tinyusb_driver_install() in my program. the ESP32S3 cannot recognize by computer after reboot. If I delete that code, I works. But it seemed that tinyusb_driver_uninstall() is still on TODO list?
If there is some temporary solution?

Who is online

Users browsing this forum: No registered users and 73 guests