Skip to content

Commit 31f2d9c

Browse files
committed
Add usb reset interface
1 parent 466432c commit 31f2d9c

File tree

4 files changed

+42
-8
lines changed

4 files changed

+42
-8
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ target_include_directories(debugprobe PRIVATE src)
4747

4848
target_compile_definitions (debugprobe PRIVATE
4949
PICO_RP2040_USB_DEVICE_ENUMERATION_FIX=1
50+
PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE=1
5051
)
5152

5253
option (DEBUG_ON_PICO "Compile firmware for the Pico instead of Debug Probe" OFF)
@@ -71,6 +72,7 @@ endif ()
7172
target_link_libraries(debugprobe PRIVATE
7273
pico_multicore
7374
pico_stdlib
75+
pico_usb_reset_interface
7476
pico_unique_id
7577
tinyusb_device
7678
tinyusb_board

src/tusb_edpt_handler.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,10 +282,15 @@ usbd_class_driver_t const _dap_edpt_driver =
282282
#endif
283283
};
284284

285+
static usbd_class_driver_t const _edpt_drivers[] = {
286+
_dap_edpt_driver,
287+
_resetd_driver,
288+
};
289+
285290
// Add the custom driver to the tinyUSB stack
286291
usbd_class_driver_t const *usbd_app_driver_get_cb(uint8_t *driver_count)
287292
{
288-
*driver_count = 1;
289-
return &_dap_edpt_driver;
293+
*driver_count = sizeof(_edpt_drivers) / sizeof(_edpt_drivers[0]);
294+
return _edpt_drivers;
290295
}
291296

src/tusb_edpt_handler.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
#include "device/usbd_pvt.h"
1313
#include "DAP_config.h"
1414

15+
#include "pico/usb_reset_interface.h"
16+
1517
#define DAP_INTERFACE_SUBCLASS 0x00
1618
#define DAP_INTERFACE_PROTOCOL 0x00
1719

src/usb_descriptors.c

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "tusb.h"
2929
#include "get_serial.h"
3030
#include "probe_config.h"
31+
#include "pico/usb_reset_interface.h"
3132

3233
//--------------------------------------------------------------------+
3334
// Device Descriptors
@@ -71,6 +72,7 @@ enum
7172
ITF_NUM_PROBE, // Old versions of Keil MDK only look at interface 0
7273
ITF_NUM_CDC_COM,
7374
ITF_NUM_CDC_DATA,
75+
ITF_NUM_RESET,
7476
ITF_NUM_TOTAL
7577
};
7678

@@ -83,7 +85,7 @@ enum
8385
#if (PROBE_DEBUG_PROTOCOL == PROTO_DAP_V1)
8486
#define CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + TUD_CDC_DESC_LEN + TUD_HID_INOUT_DESC_LEN)
8587
#else
86-
#define CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + TUD_CDC_DESC_LEN + TUD_VENDOR_DESC_LEN)
88+
#define CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + TUD_CDC_DESC_LEN + TUD_VENDOR_DESC_LEN + TUD_RPI_RESET_DESC_LEN)
8789
#endif
8890

8991
static uint8_t const desc_hid_report[] =
@@ -113,6 +115,8 @@ uint8_t desc_configuration[] =
113115
#endif
114116
// Interface 1 + 2
115117
TUD_CDC_DESCRIPTOR(ITF_NUM_CDC_COM, 6, CDC_NOTIFICATION_EP_NUM, 64, CDC_DATA_OUT_EP_NUM, CDC_DATA_IN_EP_NUM, 64),
118+
// Reset interface
119+
TUD_RPI_RESET_DESCRIPTOR(ITF_NUM_RESET, 7),
116120
};
117121

118122
// Invoked when received GET CONFIGURATION DESCRIPTOR
@@ -122,7 +126,7 @@ uint8_t const * tud_descriptor_configuration_cb(uint8_t index)
122126
{
123127
(void) index; // for multiple configurations
124128
/* Hack in CAP_BREAK support */
125-
desc_configuration[CONFIG_TOTAL_LEN - TUD_CDC_DESC_LEN + 8 + 9 + 5 + 5 + 4 - 1] = 0x6;
129+
desc_configuration[CONFIG_TOTAL_LEN - TUD_RPI_RESET_DESC_LEN - TUD_CDC_DESC_LEN + 8 + 9 + 5 + 5 + 4 - 1] = 0x6;
126130
return desc_configuration;
127131
}
128132

@@ -140,6 +144,7 @@ char const* string_desc_arr [] =
140144
"CMSIS-DAP v1 Interface", // 4: Interface descriptor for HID transport
141145
"CMSIS-DAP v2 Interface", // 5: Interface descriptor for Bulk transport
142146
"CDC-ACM UART Interface", // 6: Interface descriptor for CDC
147+
"Reset", // 7: Interface descriptor for Reset
143148
};
144149

145150
static uint16_t _desc_str[32];
@@ -198,7 +203,8 @@ will insert "DeviceInterfaceGUIDs" multistring property.
198203
https://developers.google.com/web/fundamentals/native-hardware/build-for-webusb/
199204
(Section Microsoft OS compatibility descriptors)
200205
*/
201-
#define MS_OS_20_DESC_LEN 0xB2
206+
#define MS_OS_FEATURE_DESC_LEN 0xA0
207+
#define MS_OS_20_DESC_LEN (0x0A + 0x08 + (MS_OS_FEATURE_DESC_LEN*2))
202208

203209
#define BOS_TOTAL_LEN (TUD_BOS_DESC_LEN + TUD_BOS_MICROSOFT_OS_DESC_LEN)
204210

@@ -220,14 +226,14 @@ uint8_t const desc_ms_os_20[] =
220226
U16_TO_U8S_LE(0x0008), U16_TO_U8S_LE(MS_OS_20_SUBSET_HEADER_CONFIGURATION), 0, 0, U16_TO_U8S_LE(MS_OS_20_DESC_LEN-0x0A),
221227

222228
// Function Subset header: length, type, first interface, reserved, subset length
223-
U16_TO_U8S_LE(0x0008), U16_TO_U8S_LE(MS_OS_20_SUBSET_HEADER_FUNCTION), ITF_NUM_PROBE, 0, U16_TO_U8S_LE(MS_OS_20_DESC_LEN-0x0A-0x08),
229+
U16_TO_U8S_LE(0x0008), U16_TO_U8S_LE(MS_OS_20_SUBSET_HEADER_FUNCTION), ITF_NUM_PROBE, 0, U16_TO_U8S_LE(MS_OS_FEATURE_DESC_LEN),
224230

225231
// MS OS 2.0 Compatible ID descriptor: length, type, compatible ID, sub compatible ID
226232
U16_TO_U8S_LE(0x0014), U16_TO_U8S_LE(MS_OS_20_FEATURE_COMPATBLE_ID), 'W', 'I', 'N', 'U', 'S', 'B', 0x00, 0x00,
227233
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // sub-compatible
228234

229235
// MS OS 2.0 Registry property descriptor: length, type
230-
U16_TO_U8S_LE(MS_OS_20_DESC_LEN-0x0A-0x08-0x08-0x14), U16_TO_U8S_LE(MS_OS_20_FEATURE_REG_PROPERTY),
236+
U16_TO_U8S_LE(MS_OS_FEATURE_DESC_LEN-0x08-0x14), U16_TO_U8S_LE(MS_OS_20_FEATURE_REG_PROPERTY),
231237
U16_TO_U8S_LE(0x0007), U16_TO_U8S_LE(0x002A), // wPropertyDataType, wPropertyNameLength and PropertyName "DeviceInterfaceGUIDs\0" in UTF-16
232238
'D', 0x00, 'e', 0x00, 'v', 0x00, 'i', 0x00, 'c', 0x00, 'e', 0x00, 'I', 0x00, 'n', 0x00, 't', 0x00, 'e', 0x00,
233239
'r', 0x00, 'f', 0x00, 'a', 0x00, 'c', 0x00, 'e', 0x00, 'G', 0x00, 'U', 0x00, 'I', 0x00, 'D', 0x00, 's', 0x00, 0x00, 0x00,
@@ -236,7 +242,26 @@ uint8_t const desc_ms_os_20[] =
236242
'{', 0x00, 'C', 0x00, 'D', 0x00, 'B', 0x00, '3', 0x00, 'B', 0x00, '5', 0x00, 'A', 0x00, 'D', 0x00, '-', 0x00,
237243
'2', 0x00, '9', 0x00, '3', 0x00, 'B', 0x00, '-', 0x00, '4', 0x00, '6', 0x00, '6', 0x00, '3', 0x00, '-', 0x00,
238244
'A', 0x00, 'A', 0x00, '3', 0x00, '6', 0x00, '-', 0x00, '1', 0x00, 'A', 0x00, 'A', 0x00, 'E', 0x00, '4', 0x00,
239-
'6', 0x00, '4', 0x00, '6', 0x00, '3', 0x00, '7', 0x00, '7', 0x00, '6', 0x00, '}', 0x00, 0x00, 0x00, 0x00, 0x00
245+
'6', 0x00, '4', 0x00, '6', 0x00, '3', 0x00, '7', 0x00, '7', 0x00, '6', 0x00, '}', 0x00, 0x00, 0x00, 0x00, 0x00,
246+
247+
// Function Subset header: length, type, first interface, reserved, subset length
248+
U16_TO_U8S_LE(0x0008), U16_TO_U8S_LE(MS_OS_20_SUBSET_HEADER_FUNCTION), ITF_NUM_RESET, 0, U16_TO_U8S_LE(MS_OS_FEATURE_DESC_LEN),
249+
250+
// MS OS 2.0 Compatible ID descriptor: length, type, compatible ID, sub compatible ID
251+
U16_TO_U8S_LE(0x0014), U16_TO_U8S_LE(MS_OS_20_FEATURE_COMPATBLE_ID), 'W', 'I', 'N', 'U', 'S', 'B', 0x00, 0x00,
252+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // sub-compatible
253+
254+
// MS OS 2.0 Registry property descriptor: length, type
255+
U16_TO_U8S_LE(MS_OS_FEATURE_DESC_LEN-0x08-0x14), U16_TO_U8S_LE(MS_OS_20_FEATURE_REG_PROPERTY),
256+
U16_TO_U8S_LE(0x0007), U16_TO_U8S_LE(0x002A), // wPropertyDataType, wPropertyNameLength and PropertyName "DeviceInterfaceGUIDs\0" in UTF-16
257+
'D', 0x00, 'e', 0x00, 'v', 0x00, 'i', 0x00, 'c', 0x00, 'e', 0x00, 'I', 0x00, 'n', 0x00, 't', 0x00, 'e', 0x00,
258+
'r', 0x00, 'f', 0x00, 'a', 0x00, 'c', 0x00, 'e', 0x00, 'G', 0x00, 'U', 0x00, 'I', 0x00, 'D', 0x00, 's', 0x00, 0x00, 0x00,
259+
U16_TO_U8S_LE(0x0050), // wPropertyDataLength
260+
// bPropertyData "{BDB3B5AD-293B-4663-AA36-1AAE46463776}" as a UTF-16 string (b doesn't mean bytes)
261+
'{', 0x00, 'B', 0x00, 'D', 0x00, 'B', 0x00, '3', 0x00, 'B', 0x00, '5', 0x00, 'A', 0x00, 'D', 0x00, '-', 0x00,
262+
'2', 0x00, '9', 0x00, '3', 0x00, 'B', 0x00, '-', 0x00, '4', 0x00, '6', 0x00, '6', 0x00, '3', 0x00, '-', 0x00,
263+
'A', 0x00, 'A', 0x00, '3', 0x00, '6', 0x00, '-', 0x00, '1', 0x00, 'A', 0x00, 'A', 0x00, 'E', 0x00, '4', 0x00,
264+
'6', 0x00, '4', 0x00, '6', 0x00, '3', 0x00, '7', 0x00, '7', 0x00, '6', 0x00, '}', 0x00, 0x00, 0x00, 0x00, 0x00,
240265
};
241266

242267
TU_VERIFY_STATIC(sizeof(desc_ms_os_20) == MS_OS_20_DESC_LEN, "Incorrect size");

0 commit comments

Comments
 (0)