summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorhathach <[email protected]>2021-07-12 17:50:11 +0700
committerhathach <[email protected]>2021-07-12 17:50:11 +0700
commit10a7e0502ad0ad1e53899afd547d8ddda12c7afe (patch)
treedac1310f3cebba57e586d151d1ebea68a4f0ca2e /examples
parentecb100a62fa99335fc41dca3d7c85a3903a7df65 (diff)
parent2147a31f25e6e848d9ec690d8324a6fa2d1d3127 (diff)
Merge branch 'dfu' of https://github.com/HiFiPhile/tinyusb into HiFiPhile-dfu
Diffstat (limited to 'examples')
-rw-r--r--examples/device/dfu/src/main.c32
-rw-r--r--examples/device/dfu/src/tusb_config.h7
-rw-r--r--examples/device/dfu/src/usb_descriptors.c7
3 files changed, 27 insertions, 19 deletions
diff --git a/examples/device/dfu/src/main.c b/examples/device/dfu/src/main.c
index 1c09066a8..f7c27174a 100644
--- a/examples/device/dfu/src/main.c
+++ b/examples/device/dfu/src/main.c
@@ -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;
}
diff --git a/examples/device/dfu/src/tusb_config.h b/examples/device/dfu/src/tusb_config.h
index 90e90b2e4..55aa19922 100644
--- a/examples/device/dfu/src/tusb_config.h
+++ b/examples/device/dfu/src/tusb_config.h
@@ -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
diff --git a/examples/device/dfu/src/usb_descriptors.c b/examples/device/dfu/src/usb_descriptors.c
index 8ad64354b..8c5eee455 100644
--- a/examples/device/dfu/src/usb_descriptors.c
+++ b/examples/device/dfu/src/usb_descriptors.c
@@ -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];