diff options
| author | hathach <[email protected]> | 2020-09-01 12:02:25 +0700 |
|---|---|---|
| committer | hathach <[email protected]> | 2020-09-01 12:02:25 +0700 |
| commit | be708bb8a444a6e8f8676be842fcfd02a583ed0b (patch) | |
| tree | a72cd5e5491ade67c40b0a5f152d9d697420caaf /examples/device/dfu_rt | |
| parent | d108ea4326d824da73da0a4f9632c5da6aa2e3ec (diff) | |
| parent | f10b8145afb6d7b78fbf31b525951b4137e1d774 (diff) | |
Merge branch 'master' into update-host
Diffstat (limited to 'examples/device/dfu_rt')
| -rw-r--r-- | examples/device/dfu_rt/src/main.c | 58 | ||||
| -rw-r--r-- | examples/device/dfu_rt/src/tusb_config.h | 31 | ||||
| -rw-r--r-- | examples/device/dfu_rt/src/usb_descriptors.c | 4 |
3 files changed, 49 insertions, 44 deletions
diff --git a/examples/device/dfu_rt/src/main.c b/examples/device/dfu_rt/src/main.c index 666d89649..029ff7312 100644 --- a/examples/device/dfu_rt/src/main.c +++ b/examples/device/dfu_rt/src/main.c @@ -23,6 +23,19 @@ * */ +/* After device is enumerated, run following command + * + * $ dfu-util -l + * + * It should be able to list our device as in Runtime mode. Then run + * + * $ dfu-util -e + * + * This will send DETTACH command to put device into bootloader. Since this example + * is minimal, it doesn't actually go into DFU mode but rather change the LED blinking + * pattern to fast rate as indicator. + */ + #include <stdlib.h> #include <stdio.h> #include <string.h> @@ -41,9 +54,9 @@ * - 2500 ms : device is suspended */ enum { - BLINK_DFU_MODE = 1000, + BLINK_DFU_MODE = 100, BLINK_NOT_MOUNTED = 250, - BLINK_MOUNTED = 0, + BLINK_MOUNTED = 1000, BLINK_SUSPENDED = 2500, }; @@ -104,48 +117,19 @@ void tud_dfu_rt_reboot_to_dfu(void) blink_interval_ms = BLINK_DFU_MODE; } - //--------------------------------------------------------------------+ // BLINKING TASK + Indicator pulse //--------------------------------------------------------------------+ - -volatile uint8_t doPulse = false; -// called from USB context -void led_indicator_pulse(void) { - doPulse = true; -} - void led_blinking_task(void) { static uint32_t start_ms = 0; static bool led_state = false; - if(blink_interval_ms == BLINK_MOUNTED) // Mounted - { - if(doPulse) - { - led_state = true; - board_led_write(true); - start_ms = board_millis(); - doPulse = false; - } - else if (led_state == true) - { - if ( board_millis() - start_ms < 750) //Spec says blink must be between 500 and 1000 ms. - { - return; // not enough time - } - led_state = false; - board_led_write(false); - } - } - else - { - // Blink every interval ms - if ( board_millis() - start_ms < blink_interval_ms) return; // not enough time - start_ms += blink_interval_ms; - board_led_write(led_state); - led_state = 1 - led_state; // toggle - } + // Blink every interval ms + if ( board_millis() - start_ms < blink_interval_ms) return; // not enough time + start_ms += blink_interval_ms; + + board_led_write(led_state); + led_state = 1 - led_state; // toggle } diff --git a/examples/device/dfu_rt/src/tusb_config.h b/examples/device/dfu_rt/src/tusb_config.h index f6bf79e05..226573263 100644 --- a/examples/device/dfu_rt/src/tusb_config.h +++ b/examples/device/dfu_rt/src/tusb_config.h @@ -16,19 +16,38 @@ // COMMON CONFIGURATION //-------------------------------------------------------------------- -// defined by compiler flags for flexibility +// defined by board.mk #ifndef CFG_TUSB_MCU #error CFG_TUSB_MCU must be defined #endif -#if CFG_TUSB_MCU == OPT_MCU_LPC18XX || CFG_TUSB_MCU == OPT_MCU_LPC43XX || CFG_TUSB_MCU == OPT_MCU_MIMXRT10XX || \ - CFG_TUSB_MCU == OPT_MCU_NUC505 || CFG_TUSB_MCU == OPT_MCU_CXD56 - #define CFG_TUSB_RHPORT0_MODE (OPT_MODE_DEVICE | OPT_MODE_HIGH_SPEED) +// RHPort number used for device can be defined by board.mk, default to port 0 +#ifndef BOARD_DEVICE_RHPORT_NUM + #define BOARD_DEVICE_RHPORT_NUM 0 +#endif + +// RHPort max operational speed can defined by board.mk +// Default to Highspeed for MCU with internal HighSpeed PHY (can be port specific), otherwise FullSpeed +#ifndef BOARD_DEVICE_RHPORT_SPEED + #if (CFG_TUSB_MCU == OPT_MCU_LPC18XX || CFG_TUSB_MCU == OPT_MCU_LPC43XX || CFG_TUSB_MCU == OPT_MCU_MIMXRT10XX || \ + CFG_TUSB_MCU == OPT_MCU_NUC505 || CFG_TUSB_MCU == OPT_MCU_CXD56) + #define BOARD_DEVICE_RHPORT_SPEED OPT_MODE_HIGH_SPEED + #else + #define BOARD_DEVICE_RHPORT_SPEED OPT_MODE_FULL_SPEED + #endif +#endif + +// Device mode with rhport and speed defined by board.mk +#if BOARD_DEVICE_RHPORT_NUM == 0 + #define CFG_TUSB_RHPORT0_MODE (OPT_MODE_DEVICE | BOARD_DEVICE_RHPORT_SPEED) +#elif BOARD_DEVICE_RHPORT_NUM == 1 + #define CFG_TUSB_RHPORT1_MODE (OPT_MODE_DEVICE | BOARD_DEVICE_RHPORT_SPEED) #else - #define CFG_TUSB_RHPORT0_MODE OPT_MODE_DEVICE + #error "Incorrect RHPort configuration" #endif -#define CFG_TUSB_OS OPT_OS_NONE +// This example doesn't use an RTOS +#define CFG_TUSB_OS OPT_OS_NONE // CFG_TUSB_DEBUG is defined by compiler in DEBUG build // #define CFG_TUSB_DEBUG 0 diff --git a/examples/device/dfu_rt/src/usb_descriptors.c b/examples/device/dfu_rt/src/usb_descriptors.c index 3d900efd9..8b2bd265d 100644 --- a/examples/device/dfu_rt/src/usb_descriptors.c +++ b/examples/device/dfu_rt/src/usb_descriptors.c @@ -139,7 +139,8 @@ uint16_t const* tud_descriptor_string_cb(uint8_t index, uint16_t langid) } else { - // Convert ASCII string into UTF-16 + // Note: the 0xEE index string is a Microsoft OS 1.0 Descriptors. + // https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/microsoft-defined-usb-descriptors if ( !(index < sizeof(string_desc_arr)/sizeof(string_desc_arr[0])) ) return NULL; @@ -151,6 +152,7 @@ uint16_t const* tud_descriptor_string_cb(uint8_t index, uint16_t langid) chr_count = 31; } + // Convert ASCII string into UTF-16 for(uint8_t i=0; i<chr_count; i++) { _desc_str[1+i] = str[i]; |
