diff --git a/components/tinyusb_dfu/CMakeLists.txt b/components/tinyusb_dfu/CMakeLists.txt index 6d12aa4..bde0233 100644 --- a/components/tinyusb_dfu/CMakeLists.txt +++ b/components/tinyusb_dfu/CMakeLists.txt @@ -77,7 +77,7 @@ endif() # CONFIG_TINYUSB_DFU idf_component_register(SRCS ${srcs} INCLUDE_DIRS ${includes_public} PRIV_INCLUDE_DIRS ${includes_private} - PRIV_REQUIRES "vfs" "usb" + PRIV_REQUIRES "vfs" "usb" "app_update" ) if(CONFIG_TINYUSB_DFU) diff --git a/components/tinyusb_dfu/additions/src/tusb_dfu_rt.c b/components/tinyusb_dfu/additions/src/tusb_dfu_rt.c index b168c11..98b86dc 100644 --- a/components/tinyusb_dfu/additions/src/tusb_dfu_rt.c +++ b/components/tinyusb_dfu/additions/src/tusb_dfu_rt.c @@ -16,12 +16,12 @@ #include "esp_check.h" #include "esp_err.h" #include "esp_log.h" -#include "freertos/FreeRTOS.h" -#include "freertos/task.h" +#include "esp_partition.h" +#include "esp_ota_ops.h" #include "tusb.h" #include "sdkconfig.h" -static const char *TAG = "tusb_usb_dfu"; +static const char *TAG = "tusb_dfu_rt"; /* TinyUSB callbacks */ @@ -29,4 +29,18 @@ static const char *TAG = "tusb_usb_dfu"; void tud_dfu_runtime_reboot_to_dfu_cb(void) { ESP_LOGI(TAG, "reboot"); + // switch to dfu factory + const esp_partition_t *factory = esp_partition_find_first(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_APP_FACTORY, NULL); + if (!factory) { + ESP_LOGE(TAG, "factory partition not found"); + return; + } + esp_err_t rc = esp_ota_set_boot_partition(factory); + if (ESP_OK != rc) { + ESP_LOGE(TAG, "can't set boot to factory"); + return; + } + esp_restart(); } + +/*********************************************************************** TinyUSB callbacks*/