From cf4220a9fb24279b423656257cea39b3ab68aa67 Mon Sep 17 00:00:00 2001 From: MasterPhi Date: Tue, 6 Jul 2021 18:03:05 +0200 Subject: [PATCH] Update --- examples/device/dfu/src/tusb_config.h | 1 + src/class/dfu/dfu_device.c | 3 +++ src/class/dfu/dfu_device.h | 11 +++++++++-- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/examples/device/dfu/src/tusb_config.h b/examples/device/dfu/src/tusb_config.h index 90e90b2e4..0df46c14e 100644 --- a/examples/device/dfu/src/tusb_config.h +++ b/examples/device/dfu/src/tusb_config.h @@ -76,6 +76,7 @@ #define CFG_TUD_ENDPOINT0_SIZE 64 #endif +// DFU buffer size, must to be set to the largest buffer size used by an any given storage type #define CFG_TUD_DFU_TRANSFER_BUFFER_SIZE 4096 //------------- CLASS -------------// diff --git a/src/class/dfu/dfu_device.c b/src/class/dfu/dfu_device.c index 9eafca359..a186e9140 100644 --- a/src/class/dfu/dfu_device.c +++ b/src/class/dfu/dfu_device.c @@ -147,6 +147,7 @@ void dfu_moded_init(void) _dfu_state_ctx.status = DFU_STATUS_OK; _dfu_state_ctx.attrs = 0; _dfu_state_ctx.blk_transfer_in_proc = false; + _dfu_state_ctx.alt = 0; dfu_debug_print_context(); } @@ -158,6 +159,8 @@ void dfu_moded_reset(uint8_t rhport) _dfu_state_ctx.state = DFU_IDLE; _dfu_state_ctx.status = DFU_STATUS_OK; _dfu_state_ctx.blk_transfer_in_proc = false; + _dfu_state_ctx.alt = 0; + dfu_debug_print_context(); } diff --git a/src/class/dfu/dfu_device.h b/src/class/dfu/dfu_device.h index d5bc88ab2..c5c1ede28 100644 --- a/src/class/dfu/dfu_device.h +++ b/src/class/dfu/dfu_device.h @@ -33,6 +33,13 @@ extern "C" { #endif +//--------------------------------------------------------------------+ +// Class Driver Default Configure & Validation +//--------------------------------------------------------------------+ + +#if !defined(CFG_TUD_DFU_TRANSFER_BUFFER_SIZE) + #error " CFG_TUD_DFU_TRANSFER_BUFFER_SIZE must be defined, it have to be set to the largest buffer size used by an any given storage type" +#endif //--------------------------------------------------------------------+ // Application Callback API (weak is optional) @@ -45,7 +52,7 @@ bool tud_dfu_firmware_valid_check_cb(uint8_t alt); // This callback takes the wBlockNum chunk of length length and provides it // to the application at the data pointer. This data is only valid for this // call, so the app must use it not or copy it. -// alt is used as the partition number, in order to multiple partitions like FLASH, EEPROM, etc. +// alt is used as the partition number, in order to support multiple partitions like FLASH, EEPROM, etc. void tud_dfu_req_dnload_data_cb(uint8_t alt, uint16_t wBlockNum, uint8_t* data, uint16_t length); // Must be called when the application is done using the last block of data @@ -65,7 +72,7 @@ TU_ATTR_WEAK void tud_dfu_abort_cb(void); // Invoked when a DFU_UPLOAD request is received // This callback must populate data with up to length bytes // Return the number of bytes to write -// alt is used as the partition number, in order to multiple partitions like FLASH, EEPROM, etc. +// alt is used as the partition number, in order to support multiple partitions like FLASH, EEPROM, etc. TU_ATTR_WEAK uint16_t tud_dfu_req_upload_data_cb(uint8_t alt, uint16_t block_num, uint8_t* data, uint16_t length); //--------------------------------------------------------------------+