tinyusb: boot to factory on detach
This commit is contained in:
parent
dccc526ee5
commit
575ce0e063
|
@ -77,7 +77,7 @@ endif() # CONFIG_TINYUSB_DFU
|
||||||
idf_component_register(SRCS ${srcs}
|
idf_component_register(SRCS ${srcs}
|
||||||
INCLUDE_DIRS ${includes_public}
|
INCLUDE_DIRS ${includes_public}
|
||||||
PRIV_INCLUDE_DIRS ${includes_private}
|
PRIV_INCLUDE_DIRS ${includes_private}
|
||||||
PRIV_REQUIRES "vfs" "usb"
|
PRIV_REQUIRES "vfs" "usb" "app_update"
|
||||||
)
|
)
|
||||||
|
|
||||||
if(CONFIG_TINYUSB_DFU)
|
if(CONFIG_TINYUSB_DFU)
|
||||||
|
|
|
@ -16,12 +16,12 @@
|
||||||
#include "esp_check.h"
|
#include "esp_check.h"
|
||||||
#include "esp_err.h"
|
#include "esp_err.h"
|
||||||
#include "esp_log.h"
|
#include "esp_log.h"
|
||||||
#include "freertos/FreeRTOS.h"
|
#include "esp_partition.h"
|
||||||
#include "freertos/task.h"
|
#include "esp_ota_ops.h"
|
||||||
#include "tusb.h"
|
#include "tusb.h"
|
||||||
#include "sdkconfig.h"
|
#include "sdkconfig.h"
|
||||||
|
|
||||||
static const char *TAG = "tusb_usb_dfu";
|
static const char *TAG = "tusb_dfu_rt";
|
||||||
|
|
||||||
/* TinyUSB callbacks */
|
/* TinyUSB callbacks */
|
||||||
|
|
||||||
|
@ -29,4 +29,18 @@ static const char *TAG = "tusb_usb_dfu";
|
||||||
void tud_dfu_runtime_reboot_to_dfu_cb(void)
|
void tud_dfu_runtime_reboot_to_dfu_cb(void)
|
||||||
{
|
{
|
||||||
ESP_LOGI(TAG, "reboot");
|
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*/
|
||||||
|
|
Loading…
Reference in New Issue