put manifestation in task to avoid callback timeout
This commit is contained in:
parent
64813c7228
commit
8f31c8a740
|
@ -135,6 +135,41 @@ static void dl_task(void* arg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// task to complete flashing, used when entering manifestation
|
||||||
|
static void complete_task(void* arg)
|
||||||
|
{
|
||||||
|
esp_err_t rc;
|
||||||
|
// finish flashing
|
||||||
|
if (ota_handle) {
|
||||||
|
rc = esp_ota_end(ota_handle);
|
||||||
|
ota_handle = 0;
|
||||||
|
if (ESP_OK != rc) {
|
||||||
|
ESP_LOGE(TAG, "close OTA failed");
|
||||||
|
tud_dfu_finish_flashing(DFU_STATUS_ERR_PROG);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// switch to OTA app
|
||||||
|
const esp_partition_t *ota = esp_ota_get_next_update_partition(NULL);
|
||||||
|
esp_app_desc_t ota_desc;
|
||||||
|
esp_ota_get_partition_description(ota, &ota_desc);
|
||||||
|
if (ESP_APP_DESC_MAGIC_WORD == ota_desc.magic_word) {
|
||||||
|
ESP_LOGI(TAG, "set boot to valid app");
|
||||||
|
esp_ota_set_boot_partition(ota);
|
||||||
|
} else {
|
||||||
|
ESP_LOGI(TAG, "no valid app");
|
||||||
|
tud_dfu_finish_flashing(DFU_STATUS_ERR_VERIFY);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// flashing op for manifest is complete without error
|
||||||
|
xTimerChangePeriod(blinky_tm, pdMS_TO_TICKS(BLINK_IDLE), 0);
|
||||||
|
tud_dfu_finish_flashing(DFU_STATUS_OK);
|
||||||
|
|
||||||
|
vTaskDelete(NULL); // close task
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// Main
|
// Main
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
|
@ -289,38 +324,9 @@ void tud_dfu_download_cb(uint8_t alt, uint16_t block_num, uint8_t const* data, u
|
||||||
// Once finished flashing, application must call tud_dfu_finish_flashing()
|
// Once finished flashing, application must call tud_dfu_finish_flashing()
|
||||||
void tud_dfu_manifest_cb(uint8_t alt)
|
void tud_dfu_manifest_cb(uint8_t alt)
|
||||||
{
|
{
|
||||||
(void) alt;
|
(void)alt; // not used
|
||||||
esp_err_t rc;
|
|
||||||
ESP_LOGI(TAG, "download completed, enter manifestation");
|
ESP_LOGI(TAG, "download completed, enter manifestation");
|
||||||
blinky_tm = xTimerCreateStatic(NULL, pdMS_TO_TICKS(BLINK_IDLE), true, NULL, led_blinky_cb, &blinky_tmdef);
|
xTaskCreate(complete_task, "complete_task", 3 * 1024, NULL, 8, NULL);
|
||||||
|
|
||||||
// finish flashing
|
|
||||||
if (ota_handle) {
|
|
||||||
rc = esp_ota_end(ota_handle);
|
|
||||||
ota_handle = 0;
|
|
||||||
if (ESP_OK != rc) {
|
|
||||||
ESP_LOGE(TAG, "close OTA failed");
|
|
||||||
tud_dfu_finish_flashing(DFU_STATUS_ERR_PROG);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// switch to OTA app
|
|
||||||
const esp_partition_t *ota = esp_ota_get_next_update_partition(NULL);
|
|
||||||
esp_app_desc_t ota_desc;
|
|
||||||
esp_ota_get_partition_description(ota, &ota_desc);
|
|
||||||
if (ESP_APP_DESC_MAGIC_WORD == ota_desc.magic_word) {
|
|
||||||
ESP_LOGI(TAG, "boot set to valid app");
|
|
||||||
esp_ota_set_boot_partition(ota);
|
|
||||||
} else {
|
|
||||||
ESP_LOGI(TAG, "no valid app");
|
|
||||||
tud_dfu_finish_flashing(DFU_STATUS_ERR_VERIFY);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// flashing op for manifest is complete without error
|
|
||||||
// Application can perform checksum, should it fail, use appropriate status such as errVERIFY.
|
|
||||||
tud_dfu_finish_flashing(DFU_STATUS_OK);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Invoked when received DFU_UPLOAD request
|
// Invoked when received DFU_UPLOAD request
|
||||||
|
|
Loading…
Reference in New Issue