tinyusb: boot to factory on detach

This commit is contained in:
King Kévin 2022-07-20 11:03:35 +02:00
parent dccc526ee5
commit 575ce0e063
2 changed files with 18 additions and 4 deletions

View File

@ -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)

View File

@ -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*/