Merge branch 'dfu' of https://github.com/HiFiPhile/tinyusb into HiFiPhile-dfu
This commit is contained in:
@@ -115,25 +115,27 @@ void tud_resume_cb(void)
|
||||
blink_interval_ms = BLINK_MOUNTED;
|
||||
}
|
||||
|
||||
// Invoked on DFU_DETACH request to reboot to the bootloader
|
||||
void tud_dfu_runtime_reboot_to_dfu_cb(void)
|
||||
{
|
||||
blink_interval_ms = BLINK_DFU_MODE;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Class callbacks
|
||||
//--------------------------------------------------------------------+
|
||||
bool tud_dfu_firmware_valid_check_cb(void)
|
||||
bool tud_dfu_firmware_valid_check_cb(uint8_t alt)
|
||||
{
|
||||
(void) alt;
|
||||
printf(" Firmware check\r\n");
|
||||
return true;
|
||||
}
|
||||
|
||||
void tud_dfu_req_dnload_data_cb(uint16_t wBlockNum, uint8_t* data, uint16_t length)
|
||||
uint16_t tud_dfu_set_timeout_cb(uint8_t alt)
|
||||
{
|
||||
// For example Alt1 (EEPROM) is slow, add 2000ms timeout
|
||||
if (alt == 1) return 2000;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void tud_dfu_req_dnload_data_cb(uint8_t alt, uint16_t wBlockNum, uint8_t* data, uint16_t length)
|
||||
{
|
||||
(void) data;
|
||||
printf(" Received BlockNum %u of length %u\r\n", wBlockNum, length);
|
||||
printf(" Received Alt %u BlockNum %u of length %u\r\n", alt, wBlockNum, length);
|
||||
|
||||
#if DFU_VERBOSE
|
||||
for(uint16_t i=0; i<length; i++)
|
||||
@@ -145,8 +147,9 @@ void tud_dfu_req_dnload_data_cb(uint16_t wBlockNum, uint8_t* data, uint16_t leng
|
||||
tud_dfu_dnload_complete();
|
||||
}
|
||||
|
||||
bool tud_dfu_device_data_done_check_cb(void)
|
||||
bool tud_dfu_device_data_done_check_cb(uint8_t alt)
|
||||
{
|
||||
(void) alt;
|
||||
printf(" Host said no more data... Returning true\r\n");
|
||||
return true;
|
||||
}
|
||||
@@ -156,15 +159,16 @@ void tud_dfu_abort_cb(void)
|
||||
printf(" Host aborted transfer\r\n");
|
||||
}
|
||||
|
||||
#define UPLOAD_SIZE (29)
|
||||
const uint8_t upload_test[UPLOAD_SIZE] = "Hello world from TinyUSB DFU!";
|
||||
#define UPLOAD_SIZE 43
|
||||
const uint8_t upload_test[2][UPLOAD_SIZE] = {"Hello world from TinyUSB DFU! - Partition 0",
|
||||
"Hello world from TinyUSB DFU! - Partition 1"};
|
||||
|
||||
uint16_t tud_dfu_req_upload_data_cb(uint16_t block_num, uint8_t* data, uint16_t length)
|
||||
uint16_t tud_dfu_req_upload_data_cb(uint8_t alt, uint16_t block_num, uint8_t* data, uint16_t length)
|
||||
{
|
||||
(void) block_num;
|
||||
(void) length;
|
||||
|
||||
memcpy(data, upload_test, UPLOAD_SIZE);
|
||||
memcpy(data, upload_test[alt], UPLOAD_SIZE);
|
||||
|
||||
return UPLOAD_SIZE;
|
||||
}
|
||||
|
||||
@@ -76,13 +76,16 @@
|
||||
#define CFG_TUD_ENDPOINT0_SIZE 64
|
||||
#endif
|
||||
|
||||
#define CFG_TUD_DFU_TRANSFER_BUFFER_SIZE 4096
|
||||
|
||||
//------------- CLASS -------------//
|
||||
|
||||
#define CFG_TUD_DFU_RUNTIME 0
|
||||
#define CFG_TUD_DFU_MODE 1
|
||||
|
||||
// Count of all alt settings, typically it's the partition count (Flash, EEPROM, etc.)
|
||||
#define CFG_TUD_DFU_ALT_COUNT 2
|
||||
// DFU buffer size, it has to be set to the buffer size used in TUD_DFU_MODE_DESCRIPTOR
|
||||
#define CFG_TUD_DFU_TRANSFER_BUFFER_SIZE 4096
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -96,8 +96,8 @@ uint8_t const desc_configuration[] =
|
||||
// Config number, interface count, string index, total length, attribute, power in mA
|
||||
TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP, 100),
|
||||
|
||||
// Interface number, string index, attributes, detach timeout, transfer size */
|
||||
TUD_DFU_MODE_DESCRIPTOR(ITF_NUM_DFU_MODE, 0, FUNC_ATTRS, 1000, CFG_TUD_DFU_TRANSFER_BUFFER_SIZE),
|
||||
// Interface number, attributes, detach timeout, transfer size, string index 0, [string index 1 ... string index n]
|
||||
TUD_DFU_MODE_DESCRIPTOR(ITF_NUM_DFU_MODE, FUNC_ATTRS, 1000, CFG_TUD_DFU_TRANSFER_BUFFER_SIZE, 4, 5),
|
||||
};
|
||||
|
||||
// Invoked when received GET CONFIGURATION DESCRIPTOR
|
||||
@@ -120,7 +120,8 @@ char const* string_desc_arr [] =
|
||||
"TinyUSB", // 1: Manufacturer
|
||||
"TinyUSB Device", // 2: Product
|
||||
"123456", // 3: Serials, should use chip ID
|
||||
"TinyUSB DFU", // 4: DFU
|
||||
"FLASH", // 4: DFU Partition 1
|
||||
"EEPROM", // 5: DFU Partition 2
|
||||
};
|
||||
|
||||
static uint16_t _desc_str[32];
|
||||
|
||||
Reference in New Issue
Block a user