Skip to content

Commit e7b430d

Browse files
committed
Allow use of reset interface with custom descriptors
1 parent 1ca77d6 commit e7b430d

File tree

4 files changed

+75
-56
lines changed

4 files changed

+75
-56
lines changed

src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface.h

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* \brief Definition for the reset interface that may be exposed by the pico_stdio_usb library
1414
*/
1515

16+
// These defines are used by picotool
1617
// VENDOR sub-class for the reset interface
1718
#define RESET_INTERFACE_SUBCLASS 0x00
1819
// VENDOR protocol for the reset interface
@@ -25,4 +26,74 @@
2526
// regular flash boot
2627
#define RESET_REQUEST_FLASH 0x02
2728

29+
// These defines are only used on device
30+
#if PICO_ON_DEVICE
31+
// PICO_CONFIG: PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED, Optionally define a pin to use as bootloader activity LED when BOOTSEL mode is entered via USB (either VIA_BAUD_RATE or VIA_VENDOR_INTERFACE), type=int, min=0, max=47 on RP2350B, 29 otherwise, group=pico_stdio_usb
32+
33+
// PICO_CONFIG: PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED_ACTIVE_LOW, Whether pin to use as bootloader activity LED when BOOTSEL mode is entered via USB (either VIA_BAUD_RATE or VIA_VENDOR_INTERFACE) is active low, type=bool, default=0, group=pico_stdio_usb
34+
#ifndef PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED_ACTIVE_LOW
35+
#define PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED_ACTIVE_LOW 0
36+
#endif
37+
38+
// PICO_CONFIG: PICO_STDIO_USB_RESET_BOOTSEL_FIXED_ACTIVITY_LED, Whether the pin specified by PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED is fixed or can be modified by picotool over the VENDOR USB interface, type=bool, default=0, group=pico_stdio_usb
39+
#ifndef PICO_STDIO_USB_RESET_BOOTSEL_FIXED_ACTIVITY_LED
40+
#define PICO_STDIO_USB_RESET_BOOTSEL_FIXED_ACTIVITY_LED 0
41+
#endif
42+
43+
// Any modes disabled here can't be re-enabled by picotool via VENDOR_INTERFACE.
44+
// PICO_CONFIG: PICO_STDIO_USB_RESET_BOOTSEL_INTERFACE_DISABLE_MASK, Optionally disable either the mass storage interface (bit 0) or the PICOBOOT interface (bit 1) when entering BOOTSEL mode via USB (either VIA_BAUD_RATE or VIA_VENDOR_INTERFACE), type=int, min=0, max=3, default=0, group=pico_stdio_usb
45+
#ifndef PICO_STDIO_USB_RESET_BOOTSEL_INTERFACE_DISABLE_MASK
46+
#define PICO_STDIO_USB_RESET_BOOTSEL_INTERFACE_DISABLE_MASK 0u
47+
#endif
48+
49+
// PICO_CONFIG: PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE, Enable/disable resetting into BOOTSEL mode via an additional VENDOR USB interface - enables picotool based reset, type=bool, default=1 if application is not using TinyUSB directly, group=pico_stdio_usb
50+
#ifndef PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE
51+
#if !LIB_TINYUSB_HOST && !LIB_TINYUSB_DEVICE
52+
#define PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE 1
53+
#else
54+
#define PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE 0
55+
#endif
56+
#endif
57+
58+
// PICO_CONFIG: PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_BOOTSEL, If vendor reset interface is included allow rebooting to BOOTSEL mode, type=bool, default=1, group=pico_stdio_usb
59+
#ifndef PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_BOOTSEL
60+
#define PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_BOOTSEL 1
61+
#endif
62+
63+
// PICO_CONFIG: PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_FLASH_BOOT, If vendor reset interface is included allow rebooting with regular flash boot, type=bool, default=1, group=pico_stdio_usb
64+
#ifndef PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_FLASH_BOOT
65+
#define PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_FLASH_BOOT 1
66+
#endif
67+
68+
// PICO_CONFIG: PICO_STDIO_USB_RESET_RESET_TO_FLASH_DELAY_MS, Delay in ms before rebooting via regular flash boot, default=100, group=pico_stdio_usb
69+
#ifndef PICO_STDIO_USB_RESET_RESET_TO_FLASH_DELAY_MS
70+
#define PICO_STDIO_USB_RESET_RESET_TO_FLASH_DELAY_MS 100
71+
#endif
72+
73+
// PICO_CONFIG: PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR, If vendor reset interface is included add support for Microsoft OS 2.0 Descriptor, type=bool, default=1 when using default USB descriptors, 0 otherwise, group=pico_stdio_usb
74+
#ifndef PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR
75+
#ifdef PICO_STDIO_USB_USE_DEFAULT_DESCRIPTORS
76+
#define PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR 1
77+
#else
78+
#define PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR 0
79+
#endif
80+
#endif
81+
82+
// PICO_CONFIG: PICO_STDIO_USB_RESET_INTERFACE_MS_OS_20_DESCRIPTOR_ITF, If vendor reset interface is included, the USB interface number for the reset interface, type=int, default=2 when using default USB descriptors, undefined otherwise, group=pico_stdio_usb
83+
#ifndef PICO_STDIO_USB_RESET_INTERFACE_MS_OS_20_DESCRIPTOR_ITF
84+
#if PICO_STDIO_USB_USE_DEFAULT_DESCRIPTORS
85+
#define PICO_STDIO_USB_RESET_INTERFACE_MS_OS_20_DESCRIPTOR_ITF 2
86+
#elif PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR
87+
#error Must set PICO_STDIO_USB_RESET_INTERFACE_MS_OS_20_DESCRIPTOR_ITF when using PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR with custom USB descriptors
88+
#endif
89+
#endif
90+
91+
// Interface descriptor
92+
#define TUD_RPI_RESET_DESC_LEN 9
93+
#define TUD_RPI_RESET_DESCRIPTOR(_itfnum, _stridx) \
94+
/* Interface */\
95+
TUD_RPI_RESET_DESC_LEN, TUSB_DESC_INTERFACE, _itfnum, 0, 0, TUSB_CLASS_VENDOR_SPECIFIC, RESET_INTERFACE_SUBCLASS, RESET_INTERFACE_PROTOCOL, _stridx
96+
97+
#endif // PICO_ON_DEVICE
98+
2899
#endif

src/rp2_common/pico_stdio_usb/include/pico/stdio_usb.h

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -91,53 +91,6 @@
9191
#define PICO_STDIO_USB_DEINIT_DELAY_MS 110
9292
#endif
9393

94-
// PICO_CONFIG: PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED, Optionally define a pin to use as bootloader activity LED when BOOTSEL mode is entered via USB (either VIA_BAUD_RATE or VIA_VENDOR_INTERFACE), type=int, min=0, max=47 on RP2350B, 29 otherwise, group=pico_stdio_usb
95-
96-
// PICO_CONFIG: PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED_ACTIVE_LOW, Whether pin to use as bootloader activity LED when BOOTSEL mode is entered via USB (either VIA_BAUD_RATE or VIA_VENDOR_INTERFACE) is active low, type=bool, default=0, group=pico_stdio_usb
97-
#ifndef PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED_ACTIVE_LOW
98-
#define PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED_ACTIVE_LOW 0
99-
#endif
100-
101-
// PICO_CONFIG: PICO_STDIO_USB_RESET_BOOTSEL_FIXED_ACTIVITY_LED, Whether the pin specified by PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED is fixed or can be modified by picotool over the VENDOR USB interface, type=bool, default=0, group=pico_stdio_usb
102-
#ifndef PICO_STDIO_USB_RESET_BOOTSEL_FIXED_ACTIVITY_LED
103-
#define PICO_STDIO_USB_RESET_BOOTSEL_FIXED_ACTIVITY_LED 0
104-
#endif
105-
106-
// Any modes disabled here can't be re-enabled by picotool via VENDOR_INTERFACE.
107-
// PICO_CONFIG: PICO_STDIO_USB_RESET_BOOTSEL_INTERFACE_DISABLE_MASK, Optionally disable either the mass storage interface (bit 0) or the PICOBOOT interface (bit 1) when entering BOOTSEL mode via USB (either VIA_BAUD_RATE or VIA_VENDOR_INTERFACE), type=int, min=0, max=3, default=0, group=pico_stdio_usb
108-
#ifndef PICO_STDIO_USB_RESET_BOOTSEL_INTERFACE_DISABLE_MASK
109-
#define PICO_STDIO_USB_RESET_BOOTSEL_INTERFACE_DISABLE_MASK 0u
110-
#endif
111-
112-
// PICO_CONFIG: PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE, Enable/disable resetting into BOOTSEL mode via an additional VENDOR USB interface - enables picotool based reset, type=bool, default=1 if application is not using TinyUSB directly, group=pico_stdio_usb
113-
#ifndef PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE
114-
#if !LIB_TINYUSB_HOST && !LIB_TINYUSB_DEVICE
115-
#define PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE 1
116-
#else
117-
#define PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE 0
118-
#endif
119-
#endif
120-
121-
// PICO_CONFIG: PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_BOOTSEL, If vendor reset interface is included allow rebooting to BOOTSEL mode, type=bool, default=1, group=pico_stdio_usb
122-
#ifndef PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_BOOTSEL
123-
#define PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_BOOTSEL 1
124-
#endif
125-
126-
// PICO_CONFIG: PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_FLASH_BOOT, If vendor reset interface is included allow rebooting with regular flash boot, type=bool, default=1, group=pico_stdio_usb
127-
#ifndef PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_FLASH_BOOT
128-
#define PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_FLASH_BOOT 1
129-
#endif
130-
131-
// PICO_CONFIG: PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR, If vendor reset interface is included add support for Microsoft OS 2.0 Descriptor, type=bool, default=1, group=pico_stdio_usb
132-
#ifndef PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR
133-
#define PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR 1
134-
#endif
135-
136-
// PICO_CONFIG: PICO_STDIO_USB_RESET_RESET_TO_FLASH_DELAY_MS, Delay in ms before rebooting via regular flash boot, default=100, group=pico_stdio_usb
137-
#ifndef PICO_STDIO_USB_RESET_RESET_TO_FLASH_DELAY_MS
138-
#define PICO_STDIO_USB_RESET_RESET_TO_FLASH_DELAY_MS 100
139-
#endif
140-
14194
// PICO_CONFIG: PICO_STDIO_USB_USE_DEFAULT_DESCRIPTORS, Whether `pico_stdio_usb` provides the USB descriptors needed for USB communication, type=bool, default=1 if the application is not using tinyUSB directly, group=pico_stdio_usb
14295
#ifndef PICO_STDIO_USB_USE_DEFAULT_DESCRIPTORS
14396
#if !LIB_TINYUSB_HOST && !LIB_TINYUSB_DEVICE

src/rp2_common/pico_stdio_usb/reset_interface.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "tusb.h"
77

88
#include "pico/bootrom.h"
9+
#include "pico/stdio_usb/reset_interface.h"
910

1011
#if !defined(LIB_TINYUSB_HOST)
1112

@@ -14,7 +15,6 @@
1415
#endif
1516

1617
#if PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE
17-
#include "pico/stdio_usb/reset_interface.h"
1818
#include "hardware/watchdog.h"
1919
#include "device/usbd_pvt.h"
2020

@@ -25,7 +25,6 @@ static uint8_t itf_num;
2525
#define BOS_TOTAL_LEN (TUD_BOS_DESC_LEN + TUD_BOS_MICROSOFT_OS_DESC_LEN)
2626

2727
#define MS_OS_20_DESC_LEN 166
28-
#define USBD_ITF_RPI_RESET 2
2928

3029
uint8_t const desc_bos[] =
3130
{
@@ -49,7 +48,7 @@ static const uint8_t desc_ms_os_20[] =
4948
U16_TO_U8S_LE(0x000A), U16_TO_U8S_LE(MS_OS_20_SET_HEADER_DESCRIPTOR), U32_TO_U8S_LE(0x06030000), U16_TO_U8S_LE(MS_OS_20_DESC_LEN),
5049

5150
// Function Subset header: length, type, first interface, reserved, subset length
52-
U16_TO_U8S_LE(0x0008), U16_TO_U8S_LE(MS_OS_20_SUBSET_HEADER_FUNCTION), USBD_ITF_RPI_RESET, 0, U16_TO_U8S_LE(0x009C),
51+
U16_TO_U8S_LE(0x0008), U16_TO_U8S_LE(MS_OS_20_SUBSET_HEADER_FUNCTION), PICO_STDIO_USB_RESET_INTERFACE_MS_OS_20_DESCRIPTOR_ITF, 0, U16_TO_U8S_LE(MS_OS_20_DESC_LEN-0x000A),
5352

5453
// MS OS 2.0 Compatible ID descriptor: length, type, compatible ID, sub compatible ID
5554
U16_TO_U8S_LE(0x0014), U16_TO_U8S_LE(MS_OS_20_FEATURE_COMPATBLE_ID), 'W', 'I', 'N', 'U', 'S', 'B', 0x00, 0x00,

src/rp2_common/pico_stdio_usb/stdio_usb_descriptors.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
#define USBD_PRODUCT "Pico"
5454
#endif
5555

56-
#define TUD_RPI_RESET_DESC_LEN 9
5756
#if !PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE
5857
#define USBD_DESC_LEN (TUD_CONFIG_DESC_LEN + TUD_CDC_DESC_LEN)
5958
#else
@@ -72,6 +71,7 @@
7271
#define USBD_ITF_MAX (2)
7372
#else
7473
#define USBD_ITF_RPI_RESET (2)
74+
static_assert(USBD_ITF_RPI_RESET == PICO_STDIO_USB_RESET_INTERFACE_MS_OS_20_DESCRIPTOR_ITF, "USBD_ITF_RPI_RESET must be equal to PICO_STDIO_USB_RESET_INTERFACE_MS_OS_20_DESCRIPTOR_ITF");
7575
#define USBD_ITF_MAX (3)
7676
#endif
7777

@@ -115,10 +115,6 @@ static const tusb_desc_device_t usbd_desc_device = {
115115
.bNumConfigurations = 1,
116116
};
117117

118-
#define TUD_RPI_RESET_DESCRIPTOR(_itfnum, _stridx) \
119-
/* Interface */\
120-
9, TUSB_DESC_INTERFACE, _itfnum, 0, 0, TUSB_CLASS_VENDOR_SPECIFIC, RESET_INTERFACE_SUBCLASS, RESET_INTERFACE_PROTOCOL, _stridx,
121-
122118
static const uint8_t usbd_desc_cfg[USBD_DESC_LEN] = {
123119
TUD_CONFIG_DESCRIPTOR(1, USBD_ITF_MAX, USBD_STR_0, USBD_DESC_LEN,
124120
USBD_CONFIGURATION_DESCRIPTOR_ATTRIBUTE, USBD_MAX_POWER_MA),
@@ -127,7 +123,7 @@ static const uint8_t usbd_desc_cfg[USBD_DESC_LEN] = {
127123
USBD_CDC_CMD_MAX_SIZE, USBD_CDC_EP_OUT, USBD_CDC_EP_IN, USBD_CDC_IN_OUT_MAX_SIZE),
128124

129125
#if PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE
130-
TUD_RPI_RESET_DESCRIPTOR(USBD_ITF_RPI_RESET, USBD_STR_RPI_RESET)
126+
TUD_RPI_RESET_DESCRIPTOR(USBD_ITF_RPI_RESET, USBD_STR_RPI_RESET),
131127
#endif
132128
};
133129

0 commit comments

Comments
 (0)