From 6b36c1edfc2d707b36f1615892e4933382c341c1 Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Tue, 5 Aug 2025 18:09:38 +0100 Subject: [PATCH 01/22] Allow use of reset interface with custom descriptors --- .../include/pico/usb_reset_interface.h | 71 +++++++++++++++++++ .../pico_stdio_usb/include/pico/stdio_usb.h | 47 ------------ .../pico_stdio_usb/reset_interface.c | 5 +- .../pico_stdio_usb/stdio_usb_descriptors.c | 8 +-- 4 files changed, 75 insertions(+), 56 deletions(-) diff --git a/src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface.h b/src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface.h index d5269ecf8..e04fa2034 100644 --- a/src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface.h +++ b/src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface.h @@ -13,6 +13,7 @@ * \brief Definition for the reset interface that may be exposed by the pico_stdio_usb library */ +// These defines are used by picotool // VENDOR sub-class for the reset interface #define RESET_INTERFACE_SUBCLASS 0x00 // VENDOR protocol for the reset interface @@ -25,4 +26,74 @@ // regular flash boot #define RESET_REQUEST_FLASH 0x02 +// These defines are only used on device +#if PICO_ON_DEVICE +// 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 + +// 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 +#ifndef PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED_ACTIVE_LOW +#define PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED_ACTIVE_LOW 0 +#endif + +// 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 +#ifndef PICO_STDIO_USB_RESET_BOOTSEL_FIXED_ACTIVITY_LED +#define PICO_STDIO_USB_RESET_BOOTSEL_FIXED_ACTIVITY_LED 0 +#endif + +// Any modes disabled here can't be re-enabled by picotool via VENDOR_INTERFACE. +// 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 +#ifndef PICO_STDIO_USB_RESET_BOOTSEL_INTERFACE_DISABLE_MASK +#define PICO_STDIO_USB_RESET_BOOTSEL_INTERFACE_DISABLE_MASK 0u +#endif + +// 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 +#ifndef PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE +#if !LIB_TINYUSB_HOST && !LIB_TINYUSB_DEVICE +#define PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE 1 +#else +#define PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE 0 +#endif +#endif + +// 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 +#ifndef PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_BOOTSEL +#define PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_BOOTSEL 1 +#endif + +// 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 +#ifndef PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_FLASH_BOOT +#define PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_FLASH_BOOT 1 +#endif + +// 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 +#ifndef PICO_STDIO_USB_RESET_RESET_TO_FLASH_DELAY_MS +#define PICO_STDIO_USB_RESET_RESET_TO_FLASH_DELAY_MS 100 +#endif + +// 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 +#ifndef PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR +#ifdef PICO_STDIO_USB_USE_DEFAULT_DESCRIPTORS +#define PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR 1 +#else +#define PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR 0 +#endif +#endif + +// 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 +#ifndef PICO_STDIO_USB_RESET_INTERFACE_MS_OS_20_DESCRIPTOR_ITF +#if PICO_STDIO_USB_USE_DEFAULT_DESCRIPTORS +#define PICO_STDIO_USB_RESET_INTERFACE_MS_OS_20_DESCRIPTOR_ITF 2 +#elif PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR +#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 +#endif +#endif + +// Interface descriptor +#define TUD_RPI_RESET_DESC_LEN 9 +#define TUD_RPI_RESET_DESCRIPTOR(_itfnum, _stridx) \ + /* Interface */\ + TUD_RPI_RESET_DESC_LEN, TUSB_DESC_INTERFACE, _itfnum, 0, 0, TUSB_CLASS_VENDOR_SPECIFIC, RESET_INTERFACE_SUBCLASS, RESET_INTERFACE_PROTOCOL, _stridx + +#endif // PICO_ON_DEVICE + #endif \ No newline at end of file diff --git a/src/rp2_common/pico_stdio_usb/include/pico/stdio_usb.h b/src/rp2_common/pico_stdio_usb/include/pico/stdio_usb.h index 5cf2e1f66..5015d7efa 100644 --- a/src/rp2_common/pico_stdio_usb/include/pico/stdio_usb.h +++ b/src/rp2_common/pico_stdio_usb/include/pico/stdio_usb.h @@ -91,53 +91,6 @@ #define PICO_STDIO_USB_DEINIT_DELAY_MS 110 #endif -// 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 - -// 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 -#ifndef PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED_ACTIVE_LOW -#define PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED_ACTIVE_LOW 0 -#endif - -// 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 -#ifndef PICO_STDIO_USB_RESET_BOOTSEL_FIXED_ACTIVITY_LED -#define PICO_STDIO_USB_RESET_BOOTSEL_FIXED_ACTIVITY_LED 0 -#endif - -// Any modes disabled here can't be re-enabled by picotool via VENDOR_INTERFACE. -// 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 -#ifndef PICO_STDIO_USB_RESET_BOOTSEL_INTERFACE_DISABLE_MASK -#define PICO_STDIO_USB_RESET_BOOTSEL_INTERFACE_DISABLE_MASK 0u -#endif - -// 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 -#ifndef PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE -#if !LIB_TINYUSB_HOST && !LIB_TINYUSB_DEVICE -#define PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE 1 -#else -#define PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE 0 -#endif -#endif - -// 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 -#ifndef PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_BOOTSEL -#define PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_BOOTSEL 1 -#endif - -// 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 -#ifndef PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_FLASH_BOOT -#define PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_FLASH_BOOT 1 -#endif - -// 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 -#ifndef PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR -#define PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR 1 -#endif - -// 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 -#ifndef PICO_STDIO_USB_RESET_RESET_TO_FLASH_DELAY_MS -#define PICO_STDIO_USB_RESET_RESET_TO_FLASH_DELAY_MS 100 -#endif - // 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 #ifndef PICO_STDIO_USB_USE_DEFAULT_DESCRIPTORS #if !LIB_TINYUSB_HOST && !LIB_TINYUSB_DEVICE diff --git a/src/rp2_common/pico_stdio_usb/reset_interface.c b/src/rp2_common/pico_stdio_usb/reset_interface.c index 061320936..c974362da 100644 --- a/src/rp2_common/pico_stdio_usb/reset_interface.c +++ b/src/rp2_common/pico_stdio_usb/reset_interface.c @@ -7,13 +7,13 @@ #if !defined(LIB_TINYUSB_HOST) || (defined(LIB_TINYUSB_HOST) && defined(CFG_TUH_RPI_PIO_USB)) #include "pico/bootrom.h" +#include "pico/stdio_usb/reset_interface.h" #if PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE && !(PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_BOOTSEL || PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_FLASH_BOOT) #warning PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE has been selected but neither PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_BOOTSEL nor PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_FLASH_BOOT have been selected. #endif #if PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE -#include "pico/stdio_usb/reset_interface.h" #include "hardware/watchdog.h" #include "device/usbd_pvt.h" @@ -24,7 +24,6 @@ static uint8_t itf_num; #define BOS_TOTAL_LEN (TUD_BOS_DESC_LEN + TUD_BOS_MICROSOFT_OS_DESC_LEN) #define MS_OS_20_DESC_LEN 166 -#define USBD_ITF_RPI_RESET 2 uint8_t const desc_bos[] = { @@ -48,7 +47,7 @@ static const uint8_t desc_ms_os_20[] = 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), // Function Subset header: length, type, first interface, reserved, subset length - 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), + 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), // MS OS 2.0 Compatible ID descriptor: length, type, compatible ID, sub compatible ID U16_TO_U8S_LE(0x0014), U16_TO_U8S_LE(MS_OS_20_FEATURE_COMPATBLE_ID), 'W', 'I', 'N', 'U', 'S', 'B', 0x00, 0x00, diff --git a/src/rp2_common/pico_stdio_usb/stdio_usb_descriptors.c b/src/rp2_common/pico_stdio_usb/stdio_usb_descriptors.c index b805e8fb2..95abd342d 100644 --- a/src/rp2_common/pico_stdio_usb/stdio_usb_descriptors.c +++ b/src/rp2_common/pico_stdio_usb/stdio_usb_descriptors.c @@ -53,7 +53,6 @@ #define USBD_PRODUCT "Pico" #endif -#define TUD_RPI_RESET_DESC_LEN 9 #if !PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE #define USBD_DESC_LEN (TUD_CONFIG_DESC_LEN + TUD_CDC_DESC_LEN) #else @@ -72,6 +71,7 @@ #define USBD_ITF_MAX (2) #else #define USBD_ITF_RPI_RESET (2) +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"); #define USBD_ITF_MAX (3) #endif @@ -115,10 +115,6 @@ static const tusb_desc_device_t usbd_desc_device = { .bNumConfigurations = 1, }; -#define TUD_RPI_RESET_DESCRIPTOR(_itfnum, _stridx) \ - /* Interface */\ - 9, TUSB_DESC_INTERFACE, _itfnum, 0, 0, TUSB_CLASS_VENDOR_SPECIFIC, RESET_INTERFACE_SUBCLASS, RESET_INTERFACE_PROTOCOL, _stridx, - static const uint8_t usbd_desc_cfg[USBD_DESC_LEN] = { TUD_CONFIG_DESCRIPTOR(1, USBD_ITF_MAX, USBD_STR_0, USBD_DESC_LEN, USBD_CONFIGURATION_DESCRIPTOR_ATTRIBUTE, USBD_MAX_POWER_MA), @@ -127,7 +123,7 @@ static const uint8_t usbd_desc_cfg[USBD_DESC_LEN] = { USBD_CDC_CMD_MAX_SIZE, USBD_CDC_EP_OUT, USBD_CDC_EP_IN, USBD_CDC_IN_OUT_MAX_SIZE), #if PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE - TUD_RPI_RESET_DESCRIPTOR(USBD_ITF_RPI_RESET, USBD_STR_RPI_RESET) + TUD_RPI_RESET_DESCRIPTOR(USBD_ITF_RPI_RESET, USBD_STR_RPI_RESET), #endif }; From 2f2471ad80a05ef2858deac811f83509d54c9a21 Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Wed, 6 Aug 2025 09:45:40 +0100 Subject: [PATCH 02/22] Fix pico_config assertion error --- .../include/pico/usb_reset_interface.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface.h b/src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface.h index e04fa2034..7877397ba 100644 --- a/src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface.h +++ b/src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface.h @@ -79,7 +79,7 @@ #endif #endif -// 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 +// 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 #ifndef PICO_STDIO_USB_RESET_INTERFACE_MS_OS_20_DESCRIPTOR_ITF #if PICO_STDIO_USB_USE_DEFAULT_DESCRIPTORS #define PICO_STDIO_USB_RESET_INTERFACE_MS_OS_20_DESCRIPTOR_ITF 2 From 186c37de9fc1094195c21e72f84e7d6036623446 Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Wed, 6 Aug 2025 16:32:40 +0100 Subject: [PATCH 03/22] Create separate library for reset interface --- .../include/pico/usb_reset_interface.h | 70 ------------- src/rp2_common/pico_stdio_usb/CMakeLists.txt | 18 +++- .../include/pico/stdio_usb/reset_interface.h | 97 +++++++++++++++++++ .../pico_stdio_usb/reset_interface.c | 26 ++--- 4 files changed, 120 insertions(+), 91 deletions(-) diff --git a/src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface.h b/src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface.h index 7877397ba..8f58b3cef 100644 --- a/src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface.h +++ b/src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface.h @@ -26,74 +26,4 @@ // regular flash boot #define RESET_REQUEST_FLASH 0x02 -// These defines are only used on device -#if PICO_ON_DEVICE -// 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 - -// 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 -#ifndef PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED_ACTIVE_LOW -#define PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED_ACTIVE_LOW 0 -#endif - -// 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 -#ifndef PICO_STDIO_USB_RESET_BOOTSEL_FIXED_ACTIVITY_LED -#define PICO_STDIO_USB_RESET_BOOTSEL_FIXED_ACTIVITY_LED 0 -#endif - -// Any modes disabled here can't be re-enabled by picotool via VENDOR_INTERFACE. -// 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 -#ifndef PICO_STDIO_USB_RESET_BOOTSEL_INTERFACE_DISABLE_MASK -#define PICO_STDIO_USB_RESET_BOOTSEL_INTERFACE_DISABLE_MASK 0u -#endif - -// 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 -#ifndef PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE -#if !LIB_TINYUSB_HOST && !LIB_TINYUSB_DEVICE -#define PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE 1 -#else -#define PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE 0 -#endif -#endif - -// 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 -#ifndef PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_BOOTSEL -#define PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_BOOTSEL 1 -#endif - -// 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 -#ifndef PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_FLASH_BOOT -#define PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_FLASH_BOOT 1 -#endif - -// 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 -#ifndef PICO_STDIO_USB_RESET_RESET_TO_FLASH_DELAY_MS -#define PICO_STDIO_USB_RESET_RESET_TO_FLASH_DELAY_MS 100 -#endif - -// 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 -#ifndef PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR -#ifdef PICO_STDIO_USB_USE_DEFAULT_DESCRIPTORS -#define PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR 1 -#else -#define PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR 0 -#endif -#endif - -// 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 -#ifndef PICO_STDIO_USB_RESET_INTERFACE_MS_OS_20_DESCRIPTOR_ITF -#if PICO_STDIO_USB_USE_DEFAULT_DESCRIPTORS -#define PICO_STDIO_USB_RESET_INTERFACE_MS_OS_20_DESCRIPTOR_ITF 2 -#elif PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR -#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 -#endif -#endif - -// Interface descriptor -#define TUD_RPI_RESET_DESC_LEN 9 -#define TUD_RPI_RESET_DESCRIPTOR(_itfnum, _stridx) \ - /* Interface */\ - TUD_RPI_RESET_DESC_LEN, TUSB_DESC_INTERFACE, _itfnum, 0, 0, TUSB_CLASS_VENDOR_SPECIFIC, RESET_INTERFACE_SUBCLASS, RESET_INTERFACE_PROTOCOL, _stridx - -#endif // PICO_ON_DEVICE - #endif \ No newline at end of file diff --git a/src/rp2_common/pico_stdio_usb/CMakeLists.txt b/src/rp2_common/pico_stdio_usb/CMakeLists.txt index 8dc672182..58d5279af 100644 --- a/src/rp2_common/pico_stdio_usb/CMakeLists.txt +++ b/src/rp2_common/pico_stdio_usb/CMakeLists.txt @@ -1,10 +1,24 @@ if (TARGET tinyusb_device_unmarked) + pico_add_library(pico_stdio_usb_reset_interface) + + target_include_directories(pico_stdio_usb_reset_interface_headers SYSTEM INTERFACE ${CMAKE_CURRENT_LIST_DIR}/include) + + target_sources(pico_stdio_usb_reset_interface INTERFACE + ${CMAKE_CURRENT_LIST_DIR}/reset_interface.c + ) + + pico_mirrored_target_link_libraries(pico_stdio_usb_reset_interface INTERFACE + pico_usb_reset_interface + ) + target_link_libraries(pico_stdio_usb_reset_interface INTERFACE + tinyusb_device_unmarked + ) + pico_add_library(pico_stdio_usb) target_include_directories(pico_stdio_usb_headers SYSTEM INTERFACE ${CMAKE_CURRENT_LIST_DIR}/include) target_sources(pico_stdio_usb INTERFACE - ${CMAKE_CURRENT_LIST_DIR}/reset_interface.c ${CMAKE_CURRENT_LIST_DIR}/stdio_usb.c ${CMAKE_CURRENT_LIST_DIR}/stdio_usb_descriptors.c ) @@ -13,7 +27,7 @@ if (TARGET tinyusb_device_unmarked) pico_stdio pico_time pico_unique_id - pico_usb_reset_interface + pico_stdio_usb_reset_interface ) target_link_libraries(pico_stdio_usb INTERFACE tinyusb_device_unmarked diff --git a/src/rp2_common/pico_stdio_usb/include/pico/stdio_usb/reset_interface.h b/src/rp2_common/pico_stdio_usb/include/pico/stdio_usb/reset_interface.h index e0cca103c..a9ffef0d3 100644 --- a/src/rp2_common/pico_stdio_usb/include/pico/stdio_usb/reset_interface.h +++ b/src/rp2_common/pico_stdio_usb/include/pico/stdio_usb/reset_interface.h @@ -10,4 +10,101 @@ // definitions have been moved here #include "pico/usb_reset_interface.h" +#if PICO_ON_DEVICE +// 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 + +// 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 +#ifndef PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED_ACTIVE_LOW +#define PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED_ACTIVE_LOW 0 +#endif + +// 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 +#ifndef PICO_STDIO_USB_RESET_BOOTSEL_FIXED_ACTIVITY_LED +#define PICO_STDIO_USB_RESET_BOOTSEL_FIXED_ACTIVITY_LED 0 +#endif + +// Any modes disabled here can't be re-enabled by picotool via VENDOR_INTERFACE. +// 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 +#ifndef PICO_STDIO_USB_RESET_BOOTSEL_INTERFACE_DISABLE_MASK +#define PICO_STDIO_USB_RESET_BOOTSEL_INTERFACE_DISABLE_MASK 0u +#endif + +// 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 +#ifndef PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE +#if !LIB_TINYUSB_HOST && !LIB_TINYUSB_DEVICE +#define PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE 1 +#else +#define PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE 0 +#endif +#endif + +// PICO_CONFIG: PICO_STDIO_USB_RESET_INCLUDE_APP_DRIVER_CB, Set to 0 if your application defines usbd_app_driver_get_cb, type=bool, default=1, group=pico_stdio_usb +#ifndef PICO_STDIO_USB_RESET_INCLUDE_APP_DRIVER_CB +#define PICO_STDIO_USB_RESET_INCLUDE_APP_DRIVER_CB 1 +#endif + +// 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 +#ifndef PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_BOOTSEL +#define PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_BOOTSEL 1 +#endif + +// 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 +#ifndef PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_FLASH_BOOT +#define PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_FLASH_BOOT 1 +#endif + +// 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 +#ifndef PICO_STDIO_USB_RESET_RESET_TO_FLASH_DELAY_MS +#define PICO_STDIO_USB_RESET_RESET_TO_FLASH_DELAY_MS 100 +#endif + +// 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 +#ifndef PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR +#ifdef PICO_STDIO_USB_USE_DEFAULT_DESCRIPTORS +#define PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR 1 +#else +#define PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR 0 +#endif +#endif + +// 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 +#ifndef PICO_STDIO_USB_RESET_INTERFACE_MS_OS_20_DESCRIPTOR_ITF +#if PICO_STDIO_USB_USE_DEFAULT_DESCRIPTORS +#define PICO_STDIO_USB_RESET_INTERFACE_MS_OS_20_DESCRIPTOR_ITF 2 +#elif PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR +#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 +#endif +#endif + +// Interface descriptor +#define TUD_RPI_RESET_DESC_LEN 9 +#define TUD_RPI_RESET_DESCRIPTOR(_itfnum, _stridx) \ + /* Interface */\ + TUD_RPI_RESET_DESC_LEN, TUSB_DESC_INTERFACE, _itfnum, 0, 0, TUSB_CLASS_VENDOR_SPECIFIC, RESET_INTERFACE_SUBCLASS, RESET_INTERFACE_PROTOCOL, _stridx + + +#include "stdint.h" +#include "device/usbd_pvt.h" + +void resetd_init(void); +void resetd_reset(uint8_t __unused rhport); +uint16_t resetd_open(uint8_t __unused rhport, tusb_desc_interface_t const *itf_desc, uint16_t max_len); +bool resetd_control_xfer_cb(uint8_t __unused rhport, uint8_t stage, tusb_control_request_t const * request); +bool resetd_xfer_cb(uint8_t __unused rhport, uint8_t __unused ep_addr, xfer_result_t __unused result, uint32_t __unused xferred_bytes); + +static usbd_class_driver_t const _resetd_driver = +{ +#if CFG_TUSB_DEBUG >= 2 + .name = "RESET", +#endif + .init = resetd_init, + .reset = resetd_reset, + .open = resetd_open, + .control_xfer_cb = resetd_control_xfer_cb, + .xfer_cb = resetd_xfer_cb, + .sof = NULL +}; + +#endif + #endif \ No newline at end of file diff --git a/src/rp2_common/pico_stdio_usb/reset_interface.c b/src/rp2_common/pico_stdio_usb/reset_interface.c index c974362da..8651f86fa 100644 --- a/src/rp2_common/pico_stdio_usb/reset_interface.c +++ b/src/rp2_common/pico_stdio_usb/reset_interface.c @@ -15,7 +15,6 @@ #if PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE #include "hardware/watchdog.h" -#include "device/usbd_pvt.h" static uint8_t itf_num; @@ -88,14 +87,14 @@ bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_requ } #endif -static void resetd_init(void) { +void resetd_init(void) { } -static void resetd_reset(uint8_t __unused rhport) { +void resetd_reset(uint8_t __unused rhport) { itf_num = 0; } -static uint16_t resetd_open(uint8_t __unused rhport, tusb_desc_interface_t const *itf_desc, uint16_t max_len) { +uint16_t resetd_open(uint8_t __unused rhport, tusb_desc_interface_t const *itf_desc, uint16_t max_len) { TU_VERIFY(TUSB_CLASS_VENDOR_SPECIFIC == itf_desc->bInterfaceClass && RESET_INTERFACE_SUBCLASS == itf_desc->bInterfaceSubClass && RESET_INTERFACE_PROTOCOL == itf_desc->bInterfaceProtocol, 0); @@ -108,7 +107,7 @@ static uint16_t resetd_open(uint8_t __unused rhport, tusb_desc_interface_t const } // Support for parameterized reset via vendor interface control request -static bool resetd_control_xfer_cb(uint8_t __unused rhport, uint8_t stage, tusb_control_request_t const * request) { +bool resetd_control_xfer_cb(uint8_t __unused rhport, uint8_t stage, tusb_control_request_t const * request) { // nothing to do with DATA & ACK stage if (stage != CONTROL_STAGE_SETUP) return true; @@ -145,29 +144,18 @@ static bool resetd_control_xfer_cb(uint8_t __unused rhport, uint8_t stage, tusb_ return false; } -static bool resetd_xfer_cb(uint8_t __unused rhport, uint8_t __unused ep_addr, xfer_result_t __unused result, uint32_t __unused xferred_bytes) { +bool resetd_xfer_cb(uint8_t __unused rhport, uint8_t __unused ep_addr, xfer_result_t __unused result, uint32_t __unused xferred_bytes) { return true; } -static usbd_class_driver_t const _resetd_driver = -{ -#if CFG_TUSB_DEBUG >= 2 - .name = "RESET", -#endif - .init = resetd_init, - .reset = resetd_reset, - .open = resetd_open, - .control_xfer_cb = resetd_control_xfer_cb, - .xfer_cb = resetd_xfer_cb, - .sof = NULL -}; - +#if PICO_STDIO_USB_RESET_INCLUDE_APP_DRIVER_CB // Implement callback to add our custom driver usbd_class_driver_t const *usbd_app_driver_get_cb(uint8_t *driver_count) { *driver_count = 1; return &_resetd_driver; } #endif +#endif #if PICO_STDIO_USB_ENABLE_RESET_VIA_BAUD_RATE // Support for default BOOTSEL reset by changing baud rate From 9948e914169fe33acee7970a444944b9bc7ef6d3 Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Wed, 6 Aug 2025 17:57:39 +0100 Subject: [PATCH 04/22] Move pico_usb_reset_interface library into separate folder --- src/cmake/rp2_common.cmake | 1 + .../CMakeLists.txt | 2 - .../include/pico/usb_reset_interface.h | 99 ++++++++++++++++++- src/rp2_common/pico_stdio_usb/CMakeLists.txt | 17 +--- .../include/pico/stdio_usb/reset_interface.h | 99 +------------------ .../pico_stdio_usb/stdio_usb_descriptors.c | 2 +- .../pico_usb_reset_interface/CMakeLists.txt | 11 +++ .../usb_reset_interface.c} | 2 +- 8 files changed, 114 insertions(+), 119 deletions(-) create mode 100644 src/rp2_common/pico_usb_reset_interface/CMakeLists.txt rename src/rp2_common/{pico_stdio_usb/reset_interface.c => pico_usb_reset_interface/usb_reset_interface.c} (99%) diff --git a/src/cmake/rp2_common.cmake b/src/cmake/rp2_common.cmake index 273839f70..c51f4f0b0 100644 --- a/src/cmake/rp2_common.cmake +++ b/src/cmake/rp2_common.cmake @@ -121,6 +121,7 @@ if (NOT PICO_BARE_METAL) endif() pico_add_subdirectory(rp2_common/tinyusb) pico_add_subdirectory(rp2_common/pico_stdio_usb) + pico_add_subdirectory(rp2_common/pico_usb_reset_interface) pico_add_subdirectory(rp2_common/pico_i2c_slave) # networking libraries - note dependency order is important diff --git a/src/common/pico_usb_reset_interface_headers/CMakeLists.txt b/src/common/pico_usb_reset_interface_headers/CMakeLists.txt index 6be755edc..f1927a890 100644 --- a/src/common/pico_usb_reset_interface_headers/CMakeLists.txt +++ b/src/common/pico_usb_reset_interface_headers/CMakeLists.txt @@ -1,6 +1,4 @@ # don't use pico_add_library here as picotool includes it directly add_library(pico_usb_reset_interface_headers INTERFACE) -add_library(pico_usb_reset_interface INTERFACE) -target_link_libraries(pico_usb_reset_interface INTERFACE pico_usb_reset_interface_headers) target_include_directories(pico_usb_reset_interface_headers SYSTEM INTERFACE ${CMAKE_CURRENT_LIST_DIR}/include) diff --git a/src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface.h b/src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface.h index 8f58b3cef..8ecfadf06 100644 --- a/src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface.h +++ b/src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface.h @@ -10,7 +10,7 @@ /** \file usb_reset_interface.h * \defgroup pico_usb_reset_interface_headers pico_usb_reset_interface_headers * - * \brief Definition for the reset interface that may be exposed by the pico_stdio_usb library + * \brief Definition for the reset interface that may be exposed by the pico_usb_reset_interface library */ // These defines are used by picotool @@ -26,4 +26,101 @@ // regular flash boot #define RESET_REQUEST_FLASH 0x02 +#if PICO_ON_DEVICE +// 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_usb_reset_interface + +// 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_usb_reset_interface +#ifndef PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED_ACTIVE_LOW +#define PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED_ACTIVE_LOW 0 +#endif + +// 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_usb_reset_interface +#ifndef PICO_STDIO_USB_RESET_BOOTSEL_FIXED_ACTIVITY_LED +#define PICO_STDIO_USB_RESET_BOOTSEL_FIXED_ACTIVITY_LED 0 +#endif + +// Any modes disabled here can't be re-enabled by picotool via VENDOR_INTERFACE. +// 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_usb_reset_interface +#ifndef PICO_STDIO_USB_RESET_BOOTSEL_INTERFACE_DISABLE_MASK +#define PICO_STDIO_USB_RESET_BOOTSEL_INTERFACE_DISABLE_MASK 0u +#endif + +// 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_usb_reset_interface +#ifndef PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE +#if !LIB_TINYUSB_HOST && !LIB_TINYUSB_DEVICE +#define PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE 1 +#else +#define PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE 0 +#endif +#endif + +// PICO_CONFIG: PICO_STDIO_USB_RESET_INCLUDE_APP_DRIVER_CB, Set to 0 if your application defines usbd_app_driver_get_cb, type=bool, default=1 when using pico_usb_reset_interface, 0 otherwise, group=pico_usb_reset_interface +#ifndef PICO_STDIO_USB_RESET_INCLUDE_APP_DRIVER_CB +#define PICO_STDIO_USB_RESET_INCLUDE_APP_DRIVER_CB LIB_PICO_STDIO_USB +#endif + +// 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_usb_reset_interface +#ifndef PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_BOOTSEL +#define PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_BOOTSEL 1 +#endif + +// 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_usb_reset_interface +#ifndef PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_FLASH_BOOT +#define PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_FLASH_BOOT 1 +#endif + +// PICO_CONFIG: PICO_STDIO_USB_RESET_RESET_TO_FLASH_DELAY_MS, Delay in ms before rebooting via regular flash boot, default=100, group=pico_usb_reset_interface +#ifndef PICO_STDIO_USB_RESET_RESET_TO_FLASH_DELAY_MS +#define PICO_STDIO_USB_RESET_RESET_TO_FLASH_DELAY_MS 100 +#endif + +// 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 if application is not using TinyUSB directly, 0 otherwise, group=pico_usb_reset_interface +#ifndef PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR +#if !LIB_TINYUSB_HOST && !LIB_TINYUSB_DEVICE +#define PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR 1 +#else +#define PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR 0 +#endif +#endif + +// 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 if application is not using TinyUSB directly, undefined otherwise, group=pico_usb_reset_interface +#ifndef PICO_STDIO_USB_RESET_INTERFACE_MS_OS_20_DESCRIPTOR_ITF +#if !LIB_TINYUSB_HOST && !LIB_TINYUSB_DEVICE +#define PICO_STDIO_USB_RESET_INTERFACE_MS_OS_20_DESCRIPTOR_ITF 2 +#elif PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR +#error Must set PICO_STDIO_USB_RESET_INTERFACE_MS_OS_20_DESCRIPTOR_ITF to the reset interface number when using PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR with custom USB descriptors +#endif +#endif + +// Interface descriptor +#define TUD_RPI_RESET_DESC_LEN 9 +#define TUD_RPI_RESET_DESCRIPTOR(_itfnum, _stridx) \ + /* Interface */\ + TUD_RPI_RESET_DESC_LEN, TUSB_DESC_INTERFACE, _itfnum, 0, 0, TUSB_CLASS_VENDOR_SPECIFIC, RESET_INTERFACE_SUBCLASS, RESET_INTERFACE_PROTOCOL, _stridx + + +#include "stdint.h" +#include "device/usbd_pvt.h" + +void resetd_init(void); +void resetd_reset(uint8_t __unused rhport); +uint16_t resetd_open(uint8_t __unused rhport, tusb_desc_interface_t const *itf_desc, uint16_t max_len); +bool resetd_control_xfer_cb(uint8_t __unused rhport, uint8_t stage, tusb_control_request_t const * request); +bool resetd_xfer_cb(uint8_t __unused rhport, uint8_t __unused ep_addr, xfer_result_t __unused result, uint32_t __unused xferred_bytes); + +static usbd_class_driver_t const _resetd_driver = +{ +#if CFG_TUSB_DEBUG >= 2 + .name = "RESET", +#endif + .init = resetd_init, + .reset = resetd_reset, + .open = resetd_open, + .control_xfer_cb = resetd_control_xfer_cb, + .xfer_cb = resetd_xfer_cb, + .sof = NULL +}; + +#endif + #endif \ No newline at end of file diff --git a/src/rp2_common/pico_stdio_usb/CMakeLists.txt b/src/rp2_common/pico_stdio_usb/CMakeLists.txt index 58d5279af..cad6a1453 100644 --- a/src/rp2_common/pico_stdio_usb/CMakeLists.txt +++ b/src/rp2_common/pico_stdio_usb/CMakeLists.txt @@ -1,19 +1,4 @@ if (TARGET tinyusb_device_unmarked) - pico_add_library(pico_stdio_usb_reset_interface) - - target_include_directories(pico_stdio_usb_reset_interface_headers SYSTEM INTERFACE ${CMAKE_CURRENT_LIST_DIR}/include) - - target_sources(pico_stdio_usb_reset_interface INTERFACE - ${CMAKE_CURRENT_LIST_DIR}/reset_interface.c - ) - - pico_mirrored_target_link_libraries(pico_stdio_usb_reset_interface INTERFACE - pico_usb_reset_interface - ) - target_link_libraries(pico_stdio_usb_reset_interface INTERFACE - tinyusb_device_unmarked - ) - pico_add_library(pico_stdio_usb) target_include_directories(pico_stdio_usb_headers SYSTEM INTERFACE ${CMAKE_CURRENT_LIST_DIR}/include) @@ -27,7 +12,7 @@ if (TARGET tinyusb_device_unmarked) pico_stdio pico_time pico_unique_id - pico_stdio_usb_reset_interface + pico_usb_reset_interface ) target_link_libraries(pico_stdio_usb INTERFACE tinyusb_device_unmarked diff --git a/src/rp2_common/pico_stdio_usb/include/pico/stdio_usb/reset_interface.h b/src/rp2_common/pico_stdio_usb/include/pico/stdio_usb/reset_interface.h index a9ffef0d3..f5b74f65a 100644 --- a/src/rp2_common/pico_stdio_usb/include/pico/stdio_usb/reset_interface.h +++ b/src/rp2_common/pico_stdio_usb/include/pico/stdio_usb/reset_interface.h @@ -8,103 +8,6 @@ #define _PICO_STDIO_USB_RESET_INTERFACE_H // definitions have been moved here -#include "pico/usb_reset_interface.h" - -#if PICO_ON_DEVICE -// 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 - -// 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 -#ifndef PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED_ACTIVE_LOW -#define PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED_ACTIVE_LOW 0 -#endif - -// 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 -#ifndef PICO_STDIO_USB_RESET_BOOTSEL_FIXED_ACTIVITY_LED -#define PICO_STDIO_USB_RESET_BOOTSEL_FIXED_ACTIVITY_LED 0 -#endif - -// Any modes disabled here can't be re-enabled by picotool via VENDOR_INTERFACE. -// 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 -#ifndef PICO_STDIO_USB_RESET_BOOTSEL_INTERFACE_DISABLE_MASK -#define PICO_STDIO_USB_RESET_BOOTSEL_INTERFACE_DISABLE_MASK 0u -#endif - -// 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 -#ifndef PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE -#if !LIB_TINYUSB_HOST && !LIB_TINYUSB_DEVICE -#define PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE 1 -#else -#define PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE 0 -#endif -#endif - -// PICO_CONFIG: PICO_STDIO_USB_RESET_INCLUDE_APP_DRIVER_CB, Set to 0 if your application defines usbd_app_driver_get_cb, type=bool, default=1, group=pico_stdio_usb -#ifndef PICO_STDIO_USB_RESET_INCLUDE_APP_DRIVER_CB -#define PICO_STDIO_USB_RESET_INCLUDE_APP_DRIVER_CB 1 -#endif - -// 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 -#ifndef PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_BOOTSEL -#define PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_BOOTSEL 1 -#endif - -// 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 -#ifndef PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_FLASH_BOOT -#define PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_FLASH_BOOT 1 -#endif - -// 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 -#ifndef PICO_STDIO_USB_RESET_RESET_TO_FLASH_DELAY_MS -#define PICO_STDIO_USB_RESET_RESET_TO_FLASH_DELAY_MS 100 -#endif - -// 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 -#ifndef PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR -#ifdef PICO_STDIO_USB_USE_DEFAULT_DESCRIPTORS -#define PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR 1 -#else -#define PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR 0 -#endif -#endif - -// 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 -#ifndef PICO_STDIO_USB_RESET_INTERFACE_MS_OS_20_DESCRIPTOR_ITF -#if PICO_STDIO_USB_USE_DEFAULT_DESCRIPTORS -#define PICO_STDIO_USB_RESET_INTERFACE_MS_OS_20_DESCRIPTOR_ITF 2 -#elif PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR -#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 -#endif -#endif - -// Interface descriptor -#define TUD_RPI_RESET_DESC_LEN 9 -#define TUD_RPI_RESET_DESCRIPTOR(_itfnum, _stridx) \ - /* Interface */\ - TUD_RPI_RESET_DESC_LEN, TUSB_DESC_INTERFACE, _itfnum, 0, 0, TUSB_CLASS_VENDOR_SPECIFIC, RESET_INTERFACE_SUBCLASS, RESET_INTERFACE_PROTOCOL, _stridx - - -#include "stdint.h" -#include "device/usbd_pvt.h" - -void resetd_init(void); -void resetd_reset(uint8_t __unused rhport); -uint16_t resetd_open(uint8_t __unused rhport, tusb_desc_interface_t const *itf_desc, uint16_t max_len); -bool resetd_control_xfer_cb(uint8_t __unused rhport, uint8_t stage, tusb_control_request_t const * request); -bool resetd_xfer_cb(uint8_t __unused rhport, uint8_t __unused ep_addr, xfer_result_t __unused result, uint32_t __unused xferred_bytes); - -static usbd_class_driver_t const _resetd_driver = -{ -#if CFG_TUSB_DEBUG >= 2 - .name = "RESET", -#endif - .init = resetd_init, - .reset = resetd_reset, - .open = resetd_open, - .control_xfer_cb = resetd_control_xfer_cb, - .xfer_cb = resetd_xfer_cb, - .sof = NULL -}; - -#endif +#include "pico/usb_reset_interface_constants.h" #endif \ No newline at end of file diff --git a/src/rp2_common/pico_stdio_usb/stdio_usb_descriptors.c b/src/rp2_common/pico_stdio_usb/stdio_usb_descriptors.c index 95abd342d..385ba8bff 100644 --- a/src/rp2_common/pico_stdio_usb/stdio_usb_descriptors.c +++ b/src/rp2_common/pico_stdio_usb/stdio_usb_descriptors.c @@ -27,7 +27,7 @@ */ #include "pico/stdio_usb.h" -#include "pico/stdio_usb/reset_interface.h" +#include "pico/usb_reset_interface.h" #include "pico/unique_id.h" #include "tusb.h" diff --git a/src/rp2_common/pico_usb_reset_interface/CMakeLists.txt b/src/rp2_common/pico_usb_reset_interface/CMakeLists.txt new file mode 100644 index 000000000..f2f7d307a --- /dev/null +++ b/src/rp2_common/pico_usb_reset_interface/CMakeLists.txt @@ -0,0 +1,11 @@ +if (TARGET tinyusb_device_unmarked) + pico_add_impl_library(pico_usb_reset_interface) + + target_sources(pico_usb_reset_interface INTERFACE + ${CMAKE_CURRENT_LIST_DIR}/usb_reset_interface.c + ) + + target_link_libraries(pico_usb_reset_interface INTERFACE + tinyusb_device_unmarked + ) +endif() diff --git a/src/rp2_common/pico_stdio_usb/reset_interface.c b/src/rp2_common/pico_usb_reset_interface/usb_reset_interface.c similarity index 99% rename from src/rp2_common/pico_stdio_usb/reset_interface.c rename to src/rp2_common/pico_usb_reset_interface/usb_reset_interface.c index 8651f86fa..023d8550f 100644 --- a/src/rp2_common/pico_stdio_usb/reset_interface.c +++ b/src/rp2_common/pico_usb_reset_interface/usb_reset_interface.c @@ -7,7 +7,7 @@ #if !defined(LIB_TINYUSB_HOST) || (defined(LIB_TINYUSB_HOST) && defined(CFG_TUH_RPI_PIO_USB)) #include "pico/bootrom.h" -#include "pico/stdio_usb/reset_interface.h" +#include "pico/usb_reset_interface.h" #if PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE && !(PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_BOOTSEL || PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_FLASH_BOOT) #warning PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE has been selected but neither PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_BOOTSEL nor PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_FLASH_BOOT have been selected. From 0125f0ce56d69feffdd40cd00fae45aca99e9bda Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Wed, 6 Aug 2025 18:27:49 +0100 Subject: [PATCH 05/22] Fix bazel build --- src/rp2_common/pico_stdio_usb/BUILD.bazel | 4 +--- .../include/pico/stdio_usb/reset_interface.h | 2 +- .../pico_usb_reset_interface/BUILD.bazel | 21 +++++++++++++++++++ 3 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 src/rp2_common/pico_usb_reset_interface/BUILD.bazel diff --git a/src/rp2_common/pico_stdio_usb/BUILD.bazel b/src/rp2_common/pico_stdio_usb/BUILD.bazel index f554378be..5f851bc8d 100644 --- a/src/rp2_common/pico_stdio_usb/BUILD.bazel +++ b/src/rp2_common/pico_stdio_usb/BUILD.bazel @@ -56,7 +56,6 @@ cc_library( cc_library( name = "pico_stdio_usb_enabled", srcs = [ - "reset_interface.c", "stdio_usb.c", "stdio_usb_descriptors.c", ], @@ -72,10 +71,9 @@ cc_library( "//src/common/pico_binary_info", "//src/common/pico_sync", "//src/rp2_common/hardware_irq", - "//src/rp2_common/hardware_watchdog", - "//src/rp2_common/pico_bootrom", "//src/rp2_common/pico_stdio:pico_stdio_headers", "//src/rp2_common/pico_unique_id", + "//src/rp2_common/pico_usb_reset_interface", ], # Ensure `stdio_usb_descriptors.c` isn't affected by link order. alwayslink = True, diff --git a/src/rp2_common/pico_stdio_usb/include/pico/stdio_usb/reset_interface.h b/src/rp2_common/pico_stdio_usb/include/pico/stdio_usb/reset_interface.h index f5b74f65a..e0cca103c 100644 --- a/src/rp2_common/pico_stdio_usb/include/pico/stdio_usb/reset_interface.h +++ b/src/rp2_common/pico_stdio_usb/include/pico/stdio_usb/reset_interface.h @@ -8,6 +8,6 @@ #define _PICO_STDIO_USB_RESET_INTERFACE_H // definitions have been moved here -#include "pico/usb_reset_interface_constants.h" +#include "pico/usb_reset_interface.h" #endif \ No newline at end of file diff --git a/src/rp2_common/pico_usb_reset_interface/BUILD.bazel b/src/rp2_common/pico_usb_reset_interface/BUILD.bazel new file mode 100644 index 000000000..3ec1fcd82 --- /dev/null +++ b/src/rp2_common/pico_usb_reset_interface/BUILD.bazel @@ -0,0 +1,21 @@ +load("//bazel:defs.bzl", "compatible_with_config", "compatible_with_rp2", "incompatible_with_config") +load("//bazel/util:sdk_define.bzl", "pico_sdk_define") + +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "pico_usb_reset_interface", + srcs = [ + "usb_reset_interface.c", + ], + defines = [ + "LIB_PICO_USB_RESET_INTERFACE=1", + ], + target_compatible_with = compatible_with_rp2(), + deps = [ + "//src/common/pico_usb_reset_interface_headers", + "//bazel/config:PICO_TINYUSB_LIB", + "//src/rp2_common/hardware_watchdog", + "//src/rp2_common/pico_bootrom", + ], +) From e40947e45233ced9001253ba8ac253a7c2d5d3b8 Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Wed, 13 Aug 2025 12:18:52 +0100 Subject: [PATCH 06/22] Move ms_os_20_desc into header --- .../include/pico/usb_reset_interface.h | 25 +++++++++++++++++++ .../usb_reset_interface.c | 24 ++---------------- 2 files changed, 27 insertions(+), 22 deletions(-) diff --git a/src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface.h b/src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface.h index 8ecfadf06..9d77b0b4d 100644 --- a/src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface.h +++ b/src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface.h @@ -99,6 +99,31 @@ TUD_RPI_RESET_DESC_LEN, TUSB_DESC_INTERFACE, _itfnum, 0, 0, TUSB_CLASS_VENDOR_SPECIFIC, RESET_INTERFACE_SUBCLASS, RESET_INTERFACE_PROTOCOL, _stridx +// Microsoft OS 2.0 Descriptor +#define RPI_RESET_MS_OS_20_DESC_LEN (0x08 + 0x14 + 0x80) +#define RPI_RESET_MS_OS_20_DESCRIPTOR(itf_num) \ + /* Function Subset header: length, type, first interface, reserved, subset length */ \ + U16_TO_U8S_LE(0x0008), U16_TO_U8S_LE(MS_OS_20_SUBSET_HEADER_FUNCTION), itf_num, 0, U16_TO_U8S_LE(RPI_RESET_MS_OS_20_DESC_LEN), \ + \ + /* MS OS 2.0 Compatible ID descriptor: length, type, compatible ID, sub compatible ID */ \ + U16_TO_U8S_LE(0x0014), U16_TO_U8S_LE(MS_OS_20_FEATURE_COMPATBLE_ID), 'W', 'I', 'N', 'U', 'S', 'B', 0x00, 0x00, \ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* sub-compatible */ \ + \ + /* MS OS 2.0 Registry property descriptor: length, type */ \ + U16_TO_U8S_LE(0x0080), U16_TO_U8S_LE(MS_OS_20_FEATURE_REG_PROPERTY), \ + U16_TO_U8S_LE(0x0001), U16_TO_U8S_LE(0x0028), /* wPropertyDataType, wPropertyNameLength and PropertyName "DeviceInterfaceGUID" in UTF-16 */ \ + 'D', 0x00, 'e', 0x00, 'v', 0x00, 'i', 0x00, 'c', 0x00, 'e', 0x00, 'I', 0x00, 'n', 0x00, 't', 0x00, 'e', 0x00, \ + 'r', 0x00, 'f', 0x00, 'a', 0x00, 'c', 0x00, 'e', 0x00, 'G', 0x00, 'U', 0x00, 'I', 0x00, 'D', 0x00, 0x00, 0x00, \ + U16_TO_U8S_LE(0x004E), /* wPropertyDataLength */ \ + /* Vendor-defined Property Data: {bc7398c1-73cd-4cb7-98b8-913a8fca7bf6} */ \ + '{', 0, 'b', 0, 'c', 0, '7', 0, '3', 0, '9', 0, \ + '8', 0, 'c', 0, '1', 0, '-', 0, '7', 0, '3', 0, \ + 'c', 0, 'd', 0, '-', 0, '4', 0, 'c', 0, 'b', 0, \ + '7', 0, '-', 0, '9', 0, '8', 0, 'b', 0, '8', 0, \ + '-', 0, '9', 0, '1', 0, '3', 0, 'a', 0, '8', 0, \ + 'f', 0, 'c', 0, 'a', 0, '7', 0, 'b', 0, 'f', 0, \ + '6', 0, '}', 0, 0, 0 + #include "stdint.h" #include "device/usbd_pvt.h" diff --git a/src/rp2_common/pico_usb_reset_interface/usb_reset_interface.c b/src/rp2_common/pico_usb_reset_interface/usb_reset_interface.c index 023d8550f..e4dd60d70 100644 --- a/src/rp2_common/pico_usb_reset_interface/usb_reset_interface.c +++ b/src/rp2_common/pico_usb_reset_interface/usb_reset_interface.c @@ -22,7 +22,7 @@ static uint8_t itf_num; // Support for Microsoft OS 2.0 descriptor #define BOS_TOTAL_LEN (TUD_BOS_DESC_LEN + TUD_BOS_MICROSOFT_OS_DESC_LEN) -#define MS_OS_20_DESC_LEN 166 +#define MS_OS_20_DESC_LEN (RPI_RESET_MS_OS_20_DESC_LEN + 0x0A) uint8_t const desc_bos[] = { @@ -45,27 +45,7 @@ static const uint8_t desc_ms_os_20[] = // Set header: length, type, windows version, total length 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), - // Function Subset header: length, type, first interface, reserved, subset length - 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), - - // MS OS 2.0 Compatible ID descriptor: length, type, compatible ID, sub compatible ID - U16_TO_U8S_LE(0x0014), U16_TO_U8S_LE(MS_OS_20_FEATURE_COMPATBLE_ID), 'W', 'I', 'N', 'U', 'S', 'B', 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // sub-compatible - - // MS OS 2.0 Registry property descriptor: length, type - U16_TO_U8S_LE(0x0080), U16_TO_U8S_LE(MS_OS_20_FEATURE_REG_PROPERTY), - U16_TO_U8S_LE(0x0001), U16_TO_U8S_LE(0x0028), // wPropertyDataType, wPropertyNameLength and PropertyName "DeviceInterfaceGUID" in UTF-16 - 'D', 0x00, 'e', 0x00, 'v', 0x00, 'i', 0x00, 'c', 0x00, 'e', 0x00, 'I', 0x00, 'n', 0x00, 't', 0x00, 'e', 0x00, - 'r', 0x00, 'f', 0x00, 'a', 0x00, 'c', 0x00, 'e', 0x00, 'G', 0x00, 'U', 0x00, 'I', 0x00, 'D', 0x00, 0x00, 0x00, - U16_TO_U8S_LE(0x004E), // wPropertyDataLength - // Vendor-defined Property Data: {bc7398c1-73cd-4cb7-98b8-913a8fca7bf6} - '{', 0, 'b', 0, 'c', 0, '7', 0, '3', 0, '9', 0, - '8', 0, 'c', 0, '1', 0, '-', 0, '7', 0, '3', 0, - 'c', 0, 'd', 0, '-', 0, '4', 0, 'c', 0, 'b', 0, - '7', 0, '-', 0, '9', 0, '8', 0, 'b', 0, '8', 0, - '-', 0, '9', 0, '1', 0, '3', 0, 'a', 0, '8', 0, - 'f', 0, 'c', 0, 'a', 0, '7', 0, 'b', 0, 'f', 0, - '6', 0, '}', 0, 0, 0 + RPI_RESET_MS_OS_20_DESCRIPTOR(PICO_STDIO_USB_RESET_INTERFACE_MS_OS_20_DESCRIPTOR_ITF) }; TU_VERIFY_STATIC(sizeof(desc_ms_os_20) == MS_OS_20_DESC_LEN, "Incorrect size"); From 483e7e3206cfcedb255797685a779732d982681a Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Thu, 14 Aug 2025 14:05:55 +0100 Subject: [PATCH 07/22] CFG_TUD_VENDOR isn't actually used --- src/rp2_common/pico_stdio_usb/include/tusb_config.h | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/rp2_common/pico_stdio_usb/include/tusb_config.h b/src/rp2_common/pico_stdio_usb/include/tusb_config.h index 0b9e4306b..302ff0ad8 100644 --- a/src/rp2_common/pico_stdio_usb/include/tusb_config.h +++ b/src/rp2_common/pico_stdio_usb/include/tusb_config.h @@ -48,14 +48,7 @@ #endif // We use a vendor specific interface but with our own driver -// Vendor driver only used for Microsoft OS 2.0 descriptor -#if !PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR #define CFG_TUD_VENDOR (0) -#else -#define CFG_TUD_VENDOR (1) -#define CFG_TUD_VENDOR_RX_BUFSIZE (256) -#define CFG_TUD_VENDOR_TX_BUFSIZE (256) -#endif #endif #endif From ea37b13c1133524eeb0b22ef7b92a427d6d001e6 Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Thu, 14 Aug 2025 14:37:22 +0100 Subject: [PATCH 08/22] Add documentation to usb_reset_interface.h --- .../include/pico/usb_reset_interface.h | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface.h b/src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface.h index 9d77b0b4d..02d382e34 100644 --- a/src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface.h +++ b/src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface.h @@ -8,9 +8,24 @@ #define _PICO_USB_RESET_INTERFACE_H /** \file usb_reset_interface.h - * \defgroup pico_usb_reset_interface_headers pico_usb_reset_interface_headers + * \defgroup pico_usb_reset_interface pico_usb_reset_interface * - * \brief Definition for the reset interface that may be exposed by the pico_usb_reset_interface library + * \brief Functionality to enable the RP-series microcontroller to be reset over the USB interface. + * + * This library can be used to enable the RP-series microcontroller to be reset over the USB interface. + * + * This functionality is included by default when using the `pico_stdio_usb` library and not using TinyUSB directly. + * + * To add this functionality to a project using TinyUSB directly, you need to: + * 1. Link the pico_usb_reset_interface library, and include the `pico/usb_reset_interface.h` header file where needed. + * 2. Define PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE=1 + * 3. Add `TUD_RPI_RESET_DESCRIPTOR(, )` to your USB descriptors (length is `TUD_RPI_RESET_DESC_LEN`) + * 4. Check if your project has an existing `usbd_app_driver_get_cb` function: + * - If it does, you need to add the `_resetd_driver` to the drivers returned + * - If it does not, and you aren't using the `pico_stdio_usb` library, you need to define `PICO_STDIO_USB_RESET_INCLUDE_APP_DRIVER_CB=1` + * 5. Check if your project has an existing Microsoft OS 2.0 Descriptor: + * - If it does, you need to add the Function Subset header `RPI_RESET_MS_OS_20_DESCRIPTOR()` to your Microsoft OS 2.0 Descriptor (length is `RPI_RESET_MS_OS_20_DESC_LEN`) + * - If it does not, you need to define `PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR=1` and `PICO_STDIO_USB_RESET_INTERFACE_MS_OS_20_DESCRIPTOR_ITF=` */ // These defines are used by picotool From 348376c931972a9c05cf37bd22617e04257b29d9 Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Thu, 14 Aug 2025 14:43:04 +0100 Subject: [PATCH 09/22] Change #if PICO_ON_DEVICE -> #if LIB_PICO_USB_RESET_INTERFACE Cleaner way of separating the usb_reset_interface.h header --- .../include/pico/usb_reset_interface.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface.h b/src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface.h index 02d382e34..205b4d799 100644 --- a/src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface.h +++ b/src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface.h @@ -41,7 +41,9 @@ // regular flash boot #define RESET_REQUEST_FLASH 0x02 -#if PICO_ON_DEVICE +#if LIB_PICO_USB_RESET_INTERFACE +// These defines are only used by the pico_usb_reset_interface library, not the pico_usb_reset_interface_headers library + // 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_usb_reset_interface // 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_usb_reset_interface From 7d2a1350f7e940b5b1ebc14589f7c979dd1e2d16 Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Fri, 15 Aug 2025 11:47:21 +0100 Subject: [PATCH 10/22] Rename publically accessible functions --- .../include/pico/usb_reset_interface.h | 24 +++++++++---------- .../usb_reset_interface.c | 12 +++++----- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface.h b/src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface.h index 205b4d799..66212f350 100644 --- a/src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface.h +++ b/src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface.h @@ -21,7 +21,7 @@ * 2. Define PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE=1 * 3. Add `TUD_RPI_RESET_DESCRIPTOR(, )` to your USB descriptors (length is `TUD_RPI_RESET_DESC_LEN`) * 4. Check if your project has an existing `usbd_app_driver_get_cb` function: - * - If it does, you need to add the `_resetd_driver` to the drivers returned + * - If it does, you need to add the `pico_usb_reset_interface_driver` to the drivers returned * - If it does not, and you aren't using the `pico_stdio_usb` library, you need to define `PICO_STDIO_USB_RESET_INCLUDE_APP_DRIVER_CB=1` * 5. Check if your project has an existing Microsoft OS 2.0 Descriptor: * - If it does, you need to add the Function Subset header `RPI_RESET_MS_OS_20_DESCRIPTOR()` to your Microsoft OS 2.0 Descriptor (length is `RPI_RESET_MS_OS_20_DESC_LEN`) @@ -144,22 +144,22 @@ #include "stdint.h" #include "device/usbd_pvt.h" -void resetd_init(void); -void resetd_reset(uint8_t __unused rhport); -uint16_t resetd_open(uint8_t __unused rhport, tusb_desc_interface_t const *itf_desc, uint16_t max_len); -bool resetd_control_xfer_cb(uint8_t __unused rhport, uint8_t stage, tusb_control_request_t const * request); -bool resetd_xfer_cb(uint8_t __unused rhport, uint8_t __unused ep_addr, xfer_result_t __unused result, uint32_t __unused xferred_bytes); +void pico_usb_reset_interface_init(void); +void pico_usb_reset_interface_reset(uint8_t __unused rhport); +uint16_t pico_usb_reset_interface_open(uint8_t __unused rhport, tusb_desc_interface_t const *itf_desc, uint16_t max_len); +bool pico_usb_reset_interface_control_xfer_cb(uint8_t __unused rhport, uint8_t stage, tusb_control_request_t const * request); +bool pico_usb_reset_interface_xfer_cb(uint8_t __unused rhport, uint8_t __unused ep_addr, xfer_result_t __unused result, uint32_t __unused xferred_bytes); -static usbd_class_driver_t const _resetd_driver = +static usbd_class_driver_t const pico_usb_reset_interface_driver = { #if CFG_TUSB_DEBUG >= 2 .name = "RESET", #endif - .init = resetd_init, - .reset = resetd_reset, - .open = resetd_open, - .control_xfer_cb = resetd_control_xfer_cb, - .xfer_cb = resetd_xfer_cb, + .init = pico_usb_reset_interface_init, + .reset = pico_usb_reset_interface_reset, + .open = pico_usb_reset_interface_open, + .control_xfer_cb = pico_usb_reset_interface_control_xfer_cb, + .xfer_cb = pico_usb_reset_interface_xfer_cb, .sof = NULL }; diff --git a/src/rp2_common/pico_usb_reset_interface/usb_reset_interface.c b/src/rp2_common/pico_usb_reset_interface/usb_reset_interface.c index e4dd60d70..6e15391ec 100644 --- a/src/rp2_common/pico_usb_reset_interface/usb_reset_interface.c +++ b/src/rp2_common/pico_usb_reset_interface/usb_reset_interface.c @@ -67,14 +67,14 @@ bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_requ } #endif -void resetd_init(void) { +void pico_usb_reset_interface_init(void) { } -void resetd_reset(uint8_t __unused rhport) { +void pico_usb_reset_interface_reset(uint8_t __unused rhport) { itf_num = 0; } -uint16_t resetd_open(uint8_t __unused rhport, tusb_desc_interface_t const *itf_desc, uint16_t max_len) { +uint16_t pico_usb_reset_interface_open(uint8_t __unused rhport, tusb_desc_interface_t const *itf_desc, uint16_t max_len) { TU_VERIFY(TUSB_CLASS_VENDOR_SPECIFIC == itf_desc->bInterfaceClass && RESET_INTERFACE_SUBCLASS == itf_desc->bInterfaceSubClass && RESET_INTERFACE_PROTOCOL == itf_desc->bInterfaceProtocol, 0); @@ -87,7 +87,7 @@ uint16_t resetd_open(uint8_t __unused rhport, tusb_desc_interface_t const *itf_d } // Support for parameterized reset via vendor interface control request -bool resetd_control_xfer_cb(uint8_t __unused rhport, uint8_t stage, tusb_control_request_t const * request) { +bool pico_usb_reset_interface_control_xfer_cb(uint8_t __unused rhport, uint8_t stage, tusb_control_request_t const * request) { // nothing to do with DATA & ACK stage if (stage != CONTROL_STAGE_SETUP) return true; @@ -124,7 +124,7 @@ bool resetd_control_xfer_cb(uint8_t __unused rhport, uint8_t stage, tusb_control return false; } -bool resetd_xfer_cb(uint8_t __unused rhport, uint8_t __unused ep_addr, xfer_result_t __unused result, uint32_t __unused xferred_bytes) { +bool pico_usb_reset_interface_xfer_cb(uint8_t __unused rhport, uint8_t __unused ep_addr, xfer_result_t __unused result, uint32_t __unused xferred_bytes) { return true; } @@ -132,7 +132,7 @@ bool resetd_xfer_cb(uint8_t __unused rhport, uint8_t __unused ep_addr, xfer_resu // Implement callback to add our custom driver usbd_class_driver_t const *usbd_app_driver_get_cb(uint8_t *driver_count) { *driver_count = 1; - return &_resetd_driver; + return &pico_usb_reset_interface_driver; } #endif #endif From b1b6468be2a95903ac9f766244455b7144298983 Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Fri, 15 Aug 2025 12:15:23 +0100 Subject: [PATCH 11/22] Move LIB_PICO_USB_RESET_INTERFACE only headers into separate files --- .../BUILD.bazel | 2 +- .../include/pico/usb_reset_interface.h | 120 +----------------- .../include/pico/usb_reset_interface_config.h | 75 +++++++++++ .../include/pico/usb_reset_interface_tusb.h | 64 ++++++++++ 4 files changed, 142 insertions(+), 119 deletions(-) create mode 100644 src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface_config.h create mode 100644 src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface_tusb.h diff --git a/src/common/pico_usb_reset_interface_headers/BUILD.bazel b/src/common/pico_usb_reset_interface_headers/BUILD.bazel index 6e827437d..b8486aa90 100644 --- a/src/common/pico_usb_reset_interface_headers/BUILD.bazel +++ b/src/common/pico_usb_reset_interface_headers/BUILD.bazel @@ -4,6 +4,6 @@ package(default_visibility = ["//visibility:public"]) cc_library( name = "pico_usb_reset_interface_headers", - hdrs = ["include/pico/usb_reset_interface.h"], + hdrs = ["include/pico/usb_reset_interface.h", "include/pico/usb_reset_interface_config.h", "include/pico/usb_reset_interface_tusb.h"], includes = ["include"], ) diff --git a/src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface.h b/src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface.h index 66212f350..92314ce8a 100644 --- a/src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface.h +++ b/src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface.h @@ -44,124 +44,8 @@ #if LIB_PICO_USB_RESET_INTERFACE // These defines are only used by the pico_usb_reset_interface library, not the pico_usb_reset_interface_headers library -// 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_usb_reset_interface - -// 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_usb_reset_interface -#ifndef PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED_ACTIVE_LOW -#define PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED_ACTIVE_LOW 0 -#endif - -// 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_usb_reset_interface -#ifndef PICO_STDIO_USB_RESET_BOOTSEL_FIXED_ACTIVITY_LED -#define PICO_STDIO_USB_RESET_BOOTSEL_FIXED_ACTIVITY_LED 0 -#endif - -// Any modes disabled here can't be re-enabled by picotool via VENDOR_INTERFACE. -// 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_usb_reset_interface -#ifndef PICO_STDIO_USB_RESET_BOOTSEL_INTERFACE_DISABLE_MASK -#define PICO_STDIO_USB_RESET_BOOTSEL_INTERFACE_DISABLE_MASK 0u -#endif - -// 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_usb_reset_interface -#ifndef PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE -#if !LIB_TINYUSB_HOST && !LIB_TINYUSB_DEVICE -#define PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE 1 -#else -#define PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE 0 -#endif -#endif - -// PICO_CONFIG: PICO_STDIO_USB_RESET_INCLUDE_APP_DRIVER_CB, Set to 0 if your application defines usbd_app_driver_get_cb, type=bool, default=1 when using pico_usb_reset_interface, 0 otherwise, group=pico_usb_reset_interface -#ifndef PICO_STDIO_USB_RESET_INCLUDE_APP_DRIVER_CB -#define PICO_STDIO_USB_RESET_INCLUDE_APP_DRIVER_CB LIB_PICO_STDIO_USB -#endif - -// 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_usb_reset_interface -#ifndef PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_BOOTSEL -#define PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_BOOTSEL 1 -#endif - -// 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_usb_reset_interface -#ifndef PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_FLASH_BOOT -#define PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_FLASH_BOOT 1 -#endif - -// PICO_CONFIG: PICO_STDIO_USB_RESET_RESET_TO_FLASH_DELAY_MS, Delay in ms before rebooting via regular flash boot, default=100, group=pico_usb_reset_interface -#ifndef PICO_STDIO_USB_RESET_RESET_TO_FLASH_DELAY_MS -#define PICO_STDIO_USB_RESET_RESET_TO_FLASH_DELAY_MS 100 -#endif - -// 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 if application is not using TinyUSB directly, 0 otherwise, group=pico_usb_reset_interface -#ifndef PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR -#if !LIB_TINYUSB_HOST && !LIB_TINYUSB_DEVICE -#define PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR 1 -#else -#define PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR 0 -#endif -#endif - -// 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 if application is not using TinyUSB directly, undefined otherwise, group=pico_usb_reset_interface -#ifndef PICO_STDIO_USB_RESET_INTERFACE_MS_OS_20_DESCRIPTOR_ITF -#if !LIB_TINYUSB_HOST && !LIB_TINYUSB_DEVICE -#define PICO_STDIO_USB_RESET_INTERFACE_MS_OS_20_DESCRIPTOR_ITF 2 -#elif PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR -#error Must set PICO_STDIO_USB_RESET_INTERFACE_MS_OS_20_DESCRIPTOR_ITF to the reset interface number when using PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR with custom USB descriptors -#endif -#endif - -// Interface descriptor -#define TUD_RPI_RESET_DESC_LEN 9 -#define TUD_RPI_RESET_DESCRIPTOR(_itfnum, _stridx) \ - /* Interface */\ - TUD_RPI_RESET_DESC_LEN, TUSB_DESC_INTERFACE, _itfnum, 0, 0, TUSB_CLASS_VENDOR_SPECIFIC, RESET_INTERFACE_SUBCLASS, RESET_INTERFACE_PROTOCOL, _stridx - - -// Microsoft OS 2.0 Descriptor -#define RPI_RESET_MS_OS_20_DESC_LEN (0x08 + 0x14 + 0x80) -#define RPI_RESET_MS_OS_20_DESCRIPTOR(itf_num) \ - /* Function Subset header: length, type, first interface, reserved, subset length */ \ - U16_TO_U8S_LE(0x0008), U16_TO_U8S_LE(MS_OS_20_SUBSET_HEADER_FUNCTION), itf_num, 0, U16_TO_U8S_LE(RPI_RESET_MS_OS_20_DESC_LEN), \ - \ - /* MS OS 2.0 Compatible ID descriptor: length, type, compatible ID, sub compatible ID */ \ - U16_TO_U8S_LE(0x0014), U16_TO_U8S_LE(MS_OS_20_FEATURE_COMPATBLE_ID), 'W', 'I', 'N', 'U', 'S', 'B', 0x00, 0x00, \ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* sub-compatible */ \ - \ - /* MS OS 2.0 Registry property descriptor: length, type */ \ - U16_TO_U8S_LE(0x0080), U16_TO_U8S_LE(MS_OS_20_FEATURE_REG_PROPERTY), \ - U16_TO_U8S_LE(0x0001), U16_TO_U8S_LE(0x0028), /* wPropertyDataType, wPropertyNameLength and PropertyName "DeviceInterfaceGUID" in UTF-16 */ \ - 'D', 0x00, 'e', 0x00, 'v', 0x00, 'i', 0x00, 'c', 0x00, 'e', 0x00, 'I', 0x00, 'n', 0x00, 't', 0x00, 'e', 0x00, \ - 'r', 0x00, 'f', 0x00, 'a', 0x00, 'c', 0x00, 'e', 0x00, 'G', 0x00, 'U', 0x00, 'I', 0x00, 'D', 0x00, 0x00, 0x00, \ - U16_TO_U8S_LE(0x004E), /* wPropertyDataLength */ \ - /* Vendor-defined Property Data: {bc7398c1-73cd-4cb7-98b8-913a8fca7bf6} */ \ - '{', 0, 'b', 0, 'c', 0, '7', 0, '3', 0, '9', 0, \ - '8', 0, 'c', 0, '1', 0, '-', 0, '7', 0, '3', 0, \ - 'c', 0, 'd', 0, '-', 0, '4', 0, 'c', 0, 'b', 0, \ - '7', 0, '-', 0, '9', 0, '8', 0, 'b', 0, '8', 0, \ - '-', 0, '9', 0, '1', 0, '3', 0, 'a', 0, '8', 0, \ - 'f', 0, 'c', 0, 'a', 0, '7', 0, 'b', 0, 'f', 0, \ - '6', 0, '}', 0, 0, 0 - -#include "stdint.h" -#include "device/usbd_pvt.h" - -void pico_usb_reset_interface_init(void); -void pico_usb_reset_interface_reset(uint8_t __unused rhport); -uint16_t pico_usb_reset_interface_open(uint8_t __unused rhport, tusb_desc_interface_t const *itf_desc, uint16_t max_len); -bool pico_usb_reset_interface_control_xfer_cb(uint8_t __unused rhport, uint8_t stage, tusb_control_request_t const * request); -bool pico_usb_reset_interface_xfer_cb(uint8_t __unused rhport, uint8_t __unused ep_addr, xfer_result_t __unused result, uint32_t __unused xferred_bytes); - -static usbd_class_driver_t const pico_usb_reset_interface_driver = -{ -#if CFG_TUSB_DEBUG >= 2 - .name = "RESET", -#endif - .init = pico_usb_reset_interface_init, - .reset = pico_usb_reset_interface_reset, - .open = pico_usb_reset_interface_open, - .control_xfer_cb = pico_usb_reset_interface_control_xfer_cb, - .xfer_cb = pico_usb_reset_interface_xfer_cb, - .sof = NULL -}; +#include "pico/usb_reset_interface_config.h" +#include "pico/usb_reset_interface_tusb.h" #endif diff --git a/src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface_config.h b/src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface_config.h new file mode 100644 index 000000000..e2bbbcde7 --- /dev/null +++ b/src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface_config.h @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2025 Raspberry Pi (Trading) Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef _PICO_USB_RESET_INTERFACE_CONFIG_H +#define _PICO_USB_RESET_INTERFACE_CONFIG_H + +// 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_usb_reset_interface + +// 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_usb_reset_interface +#ifndef PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED_ACTIVE_LOW +#define PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED_ACTIVE_LOW 0 +#endif + +// 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_usb_reset_interface +#ifndef PICO_STDIO_USB_RESET_BOOTSEL_FIXED_ACTIVITY_LED +#define PICO_STDIO_USB_RESET_BOOTSEL_FIXED_ACTIVITY_LED 0 +#endif + +// Any modes disabled here can't be re-enabled by picotool via VENDOR_INTERFACE. +// 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_usb_reset_interface +#ifndef PICO_STDIO_USB_RESET_BOOTSEL_INTERFACE_DISABLE_MASK +#define PICO_STDIO_USB_RESET_BOOTSEL_INTERFACE_DISABLE_MASK 0u +#endif + +// 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_usb_reset_interface +#ifndef PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE +#if !LIB_TINYUSB_HOST && !LIB_TINYUSB_DEVICE +#define PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE 1 +#else +#define PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE 0 +#endif +#endif + +// PICO_CONFIG: PICO_STDIO_USB_RESET_INCLUDE_APP_DRIVER_CB, Set to 0 if your application defines usbd_app_driver_get_cb, type=bool, default=1 when using pico_usb_reset_interface, 0 otherwise, group=pico_usb_reset_interface +#ifndef PICO_STDIO_USB_RESET_INCLUDE_APP_DRIVER_CB +#define PICO_STDIO_USB_RESET_INCLUDE_APP_DRIVER_CB LIB_PICO_STDIO_USB +#endif + +// 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_usb_reset_interface +#ifndef PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_BOOTSEL +#define PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_BOOTSEL 1 +#endif + +// 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_usb_reset_interface +#ifndef PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_FLASH_BOOT +#define PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_FLASH_BOOT 1 +#endif + +// PICO_CONFIG: PICO_STDIO_USB_RESET_RESET_TO_FLASH_DELAY_MS, Delay in ms before rebooting via regular flash boot, default=100, group=pico_usb_reset_interface +#ifndef PICO_STDIO_USB_RESET_RESET_TO_FLASH_DELAY_MS +#define PICO_STDIO_USB_RESET_RESET_TO_FLASH_DELAY_MS 100 +#endif + +// 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 if application is not using TinyUSB directly, 0 otherwise, group=pico_usb_reset_interface +#ifndef PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR +#if !LIB_TINYUSB_HOST && !LIB_TINYUSB_DEVICE +#define PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR 1 +#else +#define PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR 0 +#endif +#endif + +// 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 if application is not using TinyUSB directly, undefined otherwise, group=pico_usb_reset_interface +#ifndef PICO_STDIO_USB_RESET_INTERFACE_MS_OS_20_DESCRIPTOR_ITF +#if !LIB_TINYUSB_HOST && !LIB_TINYUSB_DEVICE +#define PICO_STDIO_USB_RESET_INTERFACE_MS_OS_20_DESCRIPTOR_ITF 2 +#elif PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR +#error Must set PICO_STDIO_USB_RESET_INTERFACE_MS_OS_20_DESCRIPTOR_ITF to the reset interface number when using PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR with custom USB descriptors +#endif +#endif + +#endif \ No newline at end of file diff --git a/src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface_tusb.h b/src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface_tusb.h new file mode 100644 index 000000000..bcafdc126 --- /dev/null +++ b/src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface_tusb.h @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2025 Raspberry Pi (Trading) Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef _PICO_USB_RESET_INTERFACE_TUSB_H +#define _PICO_USB_RESET_INTERFACE_TUSB_H + +// Interface descriptor +#define TUD_RPI_RESET_DESC_LEN 9 +#define TUD_RPI_RESET_DESCRIPTOR(_itfnum, _stridx) \ + /* Interface */\ + TUD_RPI_RESET_DESC_LEN, TUSB_DESC_INTERFACE, _itfnum, 0, 0, TUSB_CLASS_VENDOR_SPECIFIC, RESET_INTERFACE_SUBCLASS, RESET_INTERFACE_PROTOCOL, _stridx + + +// Microsoft OS 2.0 Descriptor +#define RPI_RESET_MS_OS_20_DESC_LEN (0x08 + 0x14 + 0x80) +#define RPI_RESET_MS_OS_20_DESCRIPTOR(itf_num) \ + /* Function Subset header: length, type, first interface, reserved, subset length */ \ + U16_TO_U8S_LE(0x0008), U16_TO_U8S_LE(MS_OS_20_SUBSET_HEADER_FUNCTION), itf_num, 0, U16_TO_U8S_LE(RPI_RESET_MS_OS_20_DESC_LEN), \ + \ + /* MS OS 2.0 Compatible ID descriptor: length, type, compatible ID, sub compatible ID */ \ + U16_TO_U8S_LE(0x0014), U16_TO_U8S_LE(MS_OS_20_FEATURE_COMPATBLE_ID), 'W', 'I', 'N', 'U', 'S', 'B', 0x00, 0x00, \ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* sub-compatible */ \ + \ + /* MS OS 2.0 Registry property descriptor: length, type */ \ + U16_TO_U8S_LE(0x0080), U16_TO_U8S_LE(MS_OS_20_FEATURE_REG_PROPERTY), \ + U16_TO_U8S_LE(0x0001), U16_TO_U8S_LE(0x0028), /* wPropertyDataType, wPropertyNameLength and PropertyName "DeviceInterfaceGUID" in UTF-16 */ \ + 'D', 0x00, 'e', 0x00, 'v', 0x00, 'i', 0x00, 'c', 0x00, 'e', 0x00, 'I', 0x00, 'n', 0x00, 't', 0x00, 'e', 0x00, \ + 'r', 0x00, 'f', 0x00, 'a', 0x00, 'c', 0x00, 'e', 0x00, 'G', 0x00, 'U', 0x00, 'I', 0x00, 'D', 0x00, 0x00, 0x00, \ + U16_TO_U8S_LE(0x004E), /* wPropertyDataLength */ \ + /* Vendor-defined Property Data: {bc7398c1-73cd-4cb7-98b8-913a8fca7bf6} */ \ + '{', 0, 'b', 0, 'c', 0, '7', 0, '3', 0, '9', 0, \ + '8', 0, 'c', 0, '1', 0, '-', 0, '7', 0, '3', 0, \ + 'c', 0, 'd', 0, '-', 0, '4', 0, 'c', 0, 'b', 0, \ + '7', 0, '-', 0, '9', 0, '8', 0, 'b', 0, '8', 0, \ + '-', 0, '9', 0, '1', 0, '3', 0, 'a', 0, '8', 0, \ + 'f', 0, 'c', 0, 'a', 0, '7', 0, 'b', 0, 'f', 0, \ + '6', 0, '}', 0, 0, 0 + +#include "stdint.h" +#include "device/usbd_pvt.h" + +void pico_usb_reset_interface_init(void); +void pico_usb_reset_interface_reset(uint8_t __unused rhport); +uint16_t pico_usb_reset_interface_open(uint8_t __unused rhport, tusb_desc_interface_t const *itf_desc, uint16_t max_len); +bool pico_usb_reset_interface_control_xfer_cb(uint8_t __unused rhport, uint8_t stage, tusb_control_request_t const * request); +bool pico_usb_reset_interface_xfer_cb(uint8_t __unused rhport, uint8_t __unused ep_addr, xfer_result_t __unused result, uint32_t __unused xferred_bytes); + +static usbd_class_driver_t const pico_usb_reset_interface_driver = +{ +#if CFG_TUSB_DEBUG >= 2 + .name = "RESET", +#endif + .init = pico_usb_reset_interface_init, + .reset = pico_usb_reset_interface_reset, + .open = pico_usb_reset_interface_open, + .control_xfer_cb = pico_usb_reset_interface_control_xfer_cb, + .xfer_cb = pico_usb_reset_interface_xfer_cb, + .sof = NULL +}; + +#endif \ No newline at end of file From bc1a80adc415ae5260d41354382e43198db87f34 Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Fri, 15 Aug 2025 12:32:09 +0100 Subject: [PATCH 12/22] Make new usb_reset_interface_device header so old usb_reset_interface header remains the same --- .../BUILD.bazel | 2 +- .../include/pico/usb_reset_interface.h | 28 ++------------- .../include/pico/usb_reset_interface_device.h | 35 +++++++++++++++++++ .../pico_stdio_usb/stdio_usb_descriptors.c | 2 +- .../usb_reset_interface.c | 2 +- 5 files changed, 40 insertions(+), 29 deletions(-) create mode 100644 src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface_device.h diff --git a/src/common/pico_usb_reset_interface_headers/BUILD.bazel b/src/common/pico_usb_reset_interface_headers/BUILD.bazel index b8486aa90..248fd167d 100644 --- a/src/common/pico_usb_reset_interface_headers/BUILD.bazel +++ b/src/common/pico_usb_reset_interface_headers/BUILD.bazel @@ -4,6 +4,6 @@ package(default_visibility = ["//visibility:public"]) cc_library( name = "pico_usb_reset_interface_headers", - hdrs = ["include/pico/usb_reset_interface.h", "include/pico/usb_reset_interface_config.h", "include/pico/usb_reset_interface_tusb.h"], + hdrs = ["include/pico/usb_reset_interface.h", "include/pico/usb_reset_interface_config.h", "include/pico/usb_reset_interface_device.h", "include/pico/usb_reset_interface_tusb.h"], includes = ["include"], ) diff --git a/src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface.h b/src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface.h index 92314ce8a..d5269ecf8 100644 --- a/src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface.h +++ b/src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface.h @@ -8,27 +8,11 @@ #define _PICO_USB_RESET_INTERFACE_H /** \file usb_reset_interface.h - * \defgroup pico_usb_reset_interface pico_usb_reset_interface + * \defgroup pico_usb_reset_interface_headers pico_usb_reset_interface_headers * - * \brief Functionality to enable the RP-series microcontroller to be reset over the USB interface. - * - * This library can be used to enable the RP-series microcontroller to be reset over the USB interface. - * - * This functionality is included by default when using the `pico_stdio_usb` library and not using TinyUSB directly. - * - * To add this functionality to a project using TinyUSB directly, you need to: - * 1. Link the pico_usb_reset_interface library, and include the `pico/usb_reset_interface.h` header file where needed. - * 2. Define PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE=1 - * 3. Add `TUD_RPI_RESET_DESCRIPTOR(, )` to your USB descriptors (length is `TUD_RPI_RESET_DESC_LEN`) - * 4. Check if your project has an existing `usbd_app_driver_get_cb` function: - * - If it does, you need to add the `pico_usb_reset_interface_driver` to the drivers returned - * - If it does not, and you aren't using the `pico_stdio_usb` library, you need to define `PICO_STDIO_USB_RESET_INCLUDE_APP_DRIVER_CB=1` - * 5. Check if your project has an existing Microsoft OS 2.0 Descriptor: - * - If it does, you need to add the Function Subset header `RPI_RESET_MS_OS_20_DESCRIPTOR()` to your Microsoft OS 2.0 Descriptor (length is `RPI_RESET_MS_OS_20_DESC_LEN`) - * - If it does not, you need to define `PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR=1` and `PICO_STDIO_USB_RESET_INTERFACE_MS_OS_20_DESCRIPTOR_ITF=` + * \brief Definition for the reset interface that may be exposed by the pico_stdio_usb library */ -// These defines are used by picotool // VENDOR sub-class for the reset interface #define RESET_INTERFACE_SUBCLASS 0x00 // VENDOR protocol for the reset interface @@ -41,12 +25,4 @@ // regular flash boot #define RESET_REQUEST_FLASH 0x02 -#if LIB_PICO_USB_RESET_INTERFACE -// These defines are only used by the pico_usb_reset_interface library, not the pico_usb_reset_interface_headers library - -#include "pico/usb_reset_interface_config.h" -#include "pico/usb_reset_interface_tusb.h" - -#endif - #endif \ No newline at end of file diff --git a/src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface_device.h b/src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface_device.h new file mode 100644 index 000000000..4346fe76d --- /dev/null +++ b/src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface_device.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2025 Raspberry Pi (Trading) Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef _PICO_USB_RESET_INTERFACE_DEVICE_H +#define _PICO_USB_RESET_INTERFACE_DEVICE_H + +/** \file usb_reset_interface_device.h + * \defgroup pico_usb_reset_interface pico_usb_reset_interface + * + * \brief Functionality to enable the RP-series microcontroller to be reset over the USB interface. + * + * This library can be used to enable the RP-series microcontroller to be reset over the USB interface. + * + * This functionality is included by default when using the `pico_stdio_usb` library and not using TinyUSB directly. + * + * To add this functionality to a project using TinyUSB directly, you need to: + * 1. Link the pico_usb_reset_interface library, and include the `pico/usb_reset_interface_device.h` header file where needed. + * 2. Define PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE=1 + * 3. Add `TUD_RPI_RESET_DESCRIPTOR(, )` to your USB descriptors (length is `TUD_RPI_RESET_DESC_LEN`) + * 4. Check if your project has an existing `usbd_app_driver_get_cb` function: + * - If it does, you need to add the `pico_usb_reset_interface_driver` to the drivers returned + * - If it does not, and you aren't using the `pico_stdio_usb` library, you need to define `PICO_STDIO_USB_RESET_INCLUDE_APP_DRIVER_CB=1` + * 5. Check if your project has an existing Microsoft OS 2.0 Descriptor: + * - If it does, you need to add the Function Subset header `RPI_RESET_MS_OS_20_DESCRIPTOR()` to your Microsoft OS 2.0 Descriptor (length is `RPI_RESET_MS_OS_20_DESC_LEN`) + * - If it does not, you need to define `PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR=1` and `PICO_STDIO_USB_RESET_INTERFACE_MS_OS_20_DESCRIPTOR_ITF=` + */ + +#include "pico/usb_reset_interface.h" +#include "pico/usb_reset_interface_config.h" +#include "pico/usb_reset_interface_tusb.h" + +#endif \ No newline at end of file diff --git a/src/rp2_common/pico_stdio_usb/stdio_usb_descriptors.c b/src/rp2_common/pico_stdio_usb/stdio_usb_descriptors.c index 385ba8bff..95796f6ac 100644 --- a/src/rp2_common/pico_stdio_usb/stdio_usb_descriptors.c +++ b/src/rp2_common/pico_stdio_usb/stdio_usb_descriptors.c @@ -27,7 +27,7 @@ */ #include "pico/stdio_usb.h" -#include "pico/usb_reset_interface.h" +#include "pico/usb_reset_interface_device.h" #include "pico/unique_id.h" #include "tusb.h" diff --git a/src/rp2_common/pico_usb_reset_interface/usb_reset_interface.c b/src/rp2_common/pico_usb_reset_interface/usb_reset_interface.c index 6e15391ec..e57a53459 100644 --- a/src/rp2_common/pico_usb_reset_interface/usb_reset_interface.c +++ b/src/rp2_common/pico_usb_reset_interface/usb_reset_interface.c @@ -7,7 +7,7 @@ #if !defined(LIB_TINYUSB_HOST) || (defined(LIB_TINYUSB_HOST) && defined(CFG_TUH_RPI_PIO_USB)) #include "pico/bootrom.h" -#include "pico/usb_reset_interface.h" +#include "pico/usb_reset_interface_device.h" #if PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE && !(PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_BOOTSEL || PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_FLASH_BOOT) #warning PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE has been selected but neither PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_BOOTSEL nor PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_FLASH_BOOT have been selected. From a7ffbab8306c6f37261cb003c5b4c703bf19faae Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Mon, 18 Aug 2025 10:32:30 +0100 Subject: [PATCH 13/22] Review fixups pico_usb_reset_... -> usb_reset_... PICO_STDIO_USB_RESET_INCLUDE_APP_DRIVER_CB -> PICO_STDIO_USB_RESET_INCLUDE_DEFAULT_APP_DRIVER_CB Add to docs/index.h --- docs/index.h | 1 + .../include/pico/usb_reset_interface_config.h | 8 +++---- .../include/pico/usb_reset_interface_device.h | 4 ++-- .../include/pico/usb_reset_interface_tusb.h | 22 +++++++++---------- .../usb_reset_interface.c | 14 ++++++------ 5 files changed, 25 insertions(+), 24 deletions(-) diff --git a/docs/index.h b/docs/index.h index 572d94c70..5ed500785 100644 --- a/docs/index.h +++ b/docs/index.h @@ -127,5 +127,6 @@ * \cond boot_picoboot_headers \defgroup boot_picoboot_headers boot_picoboot_headers \endcond * \cond boot_uf2_headers \defgroup boot_uf2_headers boot_uf2_headers \endcond * \cond pico_usb_reset_interface_headers \defgroup pico_usb_reset_interface_headers pico_usb_reset_interface_headers \endcond + * \cond pico_usb_reset_interface \defgroup pico_usb_reset_interface pico_usb_reset_interface \endcond * @} */ diff --git a/src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface_config.h b/src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface_config.h index e2bbbcde7..211e154dc 100644 --- a/src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface_config.h +++ b/src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface_config.h @@ -34,9 +34,9 @@ #endif #endif -// PICO_CONFIG: PICO_STDIO_USB_RESET_INCLUDE_APP_DRIVER_CB, Set to 0 if your application defines usbd_app_driver_get_cb, type=bool, default=1 when using pico_usb_reset_interface, 0 otherwise, group=pico_usb_reset_interface -#ifndef PICO_STDIO_USB_RESET_INCLUDE_APP_DRIVER_CB -#define PICO_STDIO_USB_RESET_INCLUDE_APP_DRIVER_CB LIB_PICO_STDIO_USB +// PICO_CONFIG: PICO_STDIO_USB_RESET_INCLUDE_DEFAULT_APP_DRIVER_CB, Set to 0 if your application defines its own usbd_app_driver_get_cb function, type=bool, default=1 when using pico_usb_reset_interface, 0 otherwise, group=pico_usb_reset_interface +#ifndef PICO_STDIO_USB_RESET_INCLUDE_DEFAULT_APP_DRIVER_CB +#define PICO_STDIO_USB_RESET_INCLUDE_DEFAULT_APP_DRIVER_CB LIB_PICO_STDIO_USB #endif // 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_usb_reset_interface @@ -63,7 +63,7 @@ #endif #endif -// 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 if application is not using TinyUSB directly, undefined otherwise, group=pico_usb_reset_interface +// PICO_CONFIG: PICO_STDIO_USB_RESET_INTERFACE_MS_OS_20_DESCRIPTOR_ITF, If vendor reset interface is included this specifies the USB interface number for the reset interface, type=int, default=2 if application is not using TinyUSB directly, undefined otherwise, group=pico_usb_reset_interface #ifndef PICO_STDIO_USB_RESET_INTERFACE_MS_OS_20_DESCRIPTOR_ITF #if !LIB_TINYUSB_HOST && !LIB_TINYUSB_DEVICE #define PICO_STDIO_USB_RESET_INTERFACE_MS_OS_20_DESCRIPTOR_ITF 2 diff --git a/src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface_device.h b/src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface_device.h index 4346fe76d..b2aafce11 100644 --- a/src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface_device.h +++ b/src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface_device.h @@ -21,8 +21,8 @@ * 2. Define PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE=1 * 3. Add `TUD_RPI_RESET_DESCRIPTOR(, )` to your USB descriptors (length is `TUD_RPI_RESET_DESC_LEN`) * 4. Check if your project has an existing `usbd_app_driver_get_cb` function: - * - If it does, you need to add the `pico_usb_reset_interface_driver` to the drivers returned - * - If it does not, and you aren't using the `pico_stdio_usb` library, you need to define `PICO_STDIO_USB_RESET_INCLUDE_APP_DRIVER_CB=1` + * - If it does, you need to add the `usb_reset_interface_driver` to the drivers returned + * - If it does not, and you aren't using the `pico_stdio_usb` library, you need to define `PICO_STDIO_USB_RESET_INCLUDE_DEFAULT_APP_DRIVER_CB=1` * 5. Check if your project has an existing Microsoft OS 2.0 Descriptor: * - If it does, you need to add the Function Subset header `RPI_RESET_MS_OS_20_DESCRIPTOR()` to your Microsoft OS 2.0 Descriptor (length is `RPI_RESET_MS_OS_20_DESC_LEN`) * - If it does not, you need to define `PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR=1` and `PICO_STDIO_USB_RESET_INTERFACE_MS_OS_20_DESCRIPTOR_ITF=` diff --git a/src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface_tusb.h b/src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface_tusb.h index bcafdc126..5adaded6e 100644 --- a/src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface_tusb.h +++ b/src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface_tusb.h @@ -42,22 +42,22 @@ #include "stdint.h" #include "device/usbd_pvt.h" -void pico_usb_reset_interface_init(void); -void pico_usb_reset_interface_reset(uint8_t __unused rhport); -uint16_t pico_usb_reset_interface_open(uint8_t __unused rhport, tusb_desc_interface_t const *itf_desc, uint16_t max_len); -bool pico_usb_reset_interface_control_xfer_cb(uint8_t __unused rhport, uint8_t stage, tusb_control_request_t const * request); -bool pico_usb_reset_interface_xfer_cb(uint8_t __unused rhport, uint8_t __unused ep_addr, xfer_result_t __unused result, uint32_t __unused xferred_bytes); +void usb_reset_interface_init(void); +void usb_reset_interface_reset(uint8_t __unused rhport); +uint16_t usb_reset_interface_open(uint8_t __unused rhport, tusb_desc_interface_t const *itf_desc, uint16_t max_len); +bool usb_reset_interface_control_xfer_cb(uint8_t __unused rhport, uint8_t stage, tusb_control_request_t const * request); +bool usb_reset_interface_xfer_cb(uint8_t __unused rhport, uint8_t __unused ep_addr, xfer_result_t __unused result, uint32_t __unused xferred_bytes); -static usbd_class_driver_t const pico_usb_reset_interface_driver = +static usbd_class_driver_t const usb_reset_interface_driver = { #if CFG_TUSB_DEBUG >= 2 .name = "RESET", #endif - .init = pico_usb_reset_interface_init, - .reset = pico_usb_reset_interface_reset, - .open = pico_usb_reset_interface_open, - .control_xfer_cb = pico_usb_reset_interface_control_xfer_cb, - .xfer_cb = pico_usb_reset_interface_xfer_cb, + .init = usb_reset_interface_init, + .reset = usb_reset_interface_reset, + .open = usb_reset_interface_open, + .control_xfer_cb = usb_reset_interface_control_xfer_cb, + .xfer_cb = usb_reset_interface_xfer_cb, .sof = NULL }; diff --git a/src/rp2_common/pico_usb_reset_interface/usb_reset_interface.c b/src/rp2_common/pico_usb_reset_interface/usb_reset_interface.c index e57a53459..ee22b4585 100644 --- a/src/rp2_common/pico_usb_reset_interface/usb_reset_interface.c +++ b/src/rp2_common/pico_usb_reset_interface/usb_reset_interface.c @@ -67,14 +67,14 @@ bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_requ } #endif -void pico_usb_reset_interface_init(void) { +void usb_reset_interface_init(void) { } -void pico_usb_reset_interface_reset(uint8_t __unused rhport) { +void usb_reset_interface_reset(uint8_t __unused rhport) { itf_num = 0; } -uint16_t pico_usb_reset_interface_open(uint8_t __unused rhport, tusb_desc_interface_t const *itf_desc, uint16_t max_len) { +uint16_t usb_reset_interface_open(uint8_t __unused rhport, tusb_desc_interface_t const *itf_desc, uint16_t max_len) { TU_VERIFY(TUSB_CLASS_VENDOR_SPECIFIC == itf_desc->bInterfaceClass && RESET_INTERFACE_SUBCLASS == itf_desc->bInterfaceSubClass && RESET_INTERFACE_PROTOCOL == itf_desc->bInterfaceProtocol, 0); @@ -87,7 +87,7 @@ uint16_t pico_usb_reset_interface_open(uint8_t __unused rhport, tusb_desc_interf } // Support for parameterized reset via vendor interface control request -bool pico_usb_reset_interface_control_xfer_cb(uint8_t __unused rhport, uint8_t stage, tusb_control_request_t const * request) { +bool usb_reset_interface_control_xfer_cb(uint8_t __unused rhport, uint8_t stage, tusb_control_request_t const * request) { // nothing to do with DATA & ACK stage if (stage != CONTROL_STAGE_SETUP) return true; @@ -124,15 +124,15 @@ bool pico_usb_reset_interface_control_xfer_cb(uint8_t __unused rhport, uint8_t s return false; } -bool pico_usb_reset_interface_xfer_cb(uint8_t __unused rhport, uint8_t __unused ep_addr, xfer_result_t __unused result, uint32_t __unused xferred_bytes) { +bool usb_reset_interface_xfer_cb(uint8_t __unused rhport, uint8_t __unused ep_addr, xfer_result_t __unused result, uint32_t __unused xferred_bytes) { return true; } -#if PICO_STDIO_USB_RESET_INCLUDE_APP_DRIVER_CB +#if PICO_STDIO_USB_RESET_INCLUDE_DEFAULT_APP_DRIVER_CB // Implement callback to add our custom driver usbd_class_driver_t const *usbd_app_driver_get_cb(uint8_t *driver_count) { *driver_count = 1; - return &pico_usb_reset_interface_driver; + return &usb_reset_interface_driver; } #endif #endif From 2c0f717a247bf159c9c72e97104d4748f7dcfb89 Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Mon, 18 May 2026 17:43:02 +0100 Subject: [PATCH 14/22] Remove STDIO from defines Include backwards compatibility with old define names Also fix bazel build --- .../BUILD.bazel | 7 +- .../include/pico/usb_reset_interface_config.h | 133 +++++++++++++----- .../include/pico/usb_reset_interface_device.h | 6 +- .../pico_stdio_usb/include/pico/stdio_usb.h | 14 -- .../pico_stdio_usb/stdio_usb_descriptors.c | 12 +- .../pico_usb_reset_interface/BUILD.bazel | 6 +- .../usb_reset_interface.c | 40 +++--- 7 files changed, 133 insertions(+), 85 deletions(-) diff --git a/src/common/pico_usb_reset_interface_headers/BUILD.bazel b/src/common/pico_usb_reset_interface_headers/BUILD.bazel index 248fd167d..a840f0c8f 100644 --- a/src/common/pico_usb_reset_interface_headers/BUILD.bazel +++ b/src/common/pico_usb_reset_interface_headers/BUILD.bazel @@ -4,6 +4,11 @@ package(default_visibility = ["//visibility:public"]) cc_library( name = "pico_usb_reset_interface_headers", - hdrs = ["include/pico/usb_reset_interface.h", "include/pico/usb_reset_interface_config.h", "include/pico/usb_reset_interface_device.h", "include/pico/usb_reset_interface_tusb.h"], + hdrs = [ + "include/pico/usb_reset_interface.h", + "include/pico/usb_reset_interface_config.h", + "include/pico/usb_reset_interface_device.h", + "include/pico/usb_reset_interface_tusb.h", + ], includes = ["include"], ) diff --git a/src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface_config.h b/src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface_config.h index 211e154dc..4b535d4ee 100644 --- a/src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface_config.h +++ b/src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface_config.h @@ -7,68 +7,125 @@ #ifndef _PICO_USB_RESET_INTERFACE_CONFIG_H #define _PICO_USB_RESET_INTERFACE_CONFIG_H -// 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_usb_reset_interface +// PICO_CONFIG: PICO_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_usb_reset_interface +#ifdef PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED // backwards compatibility with SDK <= 2.2.0 +#define PICO_USB_RESET_BOOTSEL_ACTIVITY_LED PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED +#endif // default is undefined -// 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_usb_reset_interface -#ifndef PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED_ACTIVE_LOW -#define PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED_ACTIVE_LOW 0 +// PICO_CONFIG: PICO_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_usb_reset_interface +#ifndef PICO_USB_RESET_BOOTSEL_ACTIVITY_LED_ACTIVE_LOW +#ifdef PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED_ACTIVE_LOW // backwards compatibility with SDK <= 2.2.0 +#define PICO_USB_RESET_BOOTSEL_ACTIVITY_LED_ACTIVE_LOW PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED_ACTIVE_LOW +#else +#define PICO_USB_RESET_BOOTSEL_ACTIVITY_LED_ACTIVE_LOW 0 +#endif #endif -// 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_usb_reset_interface -#ifndef PICO_STDIO_USB_RESET_BOOTSEL_FIXED_ACTIVITY_LED -#define PICO_STDIO_USB_RESET_BOOTSEL_FIXED_ACTIVITY_LED 0 +// PICO_CONFIG: PICO_USB_RESET_BOOTSEL_FIXED_ACTIVITY_LED, Whether the pin specified by PICO_USB_RESET_BOOTSEL_ACTIVITY_LED is fixed or can be modified by picotool over the VENDOR USB interface, type=bool, default=0, group=pico_usb_reset_interface +#ifndef PICO_USB_RESET_BOOTSEL_FIXED_ACTIVITY_LED +#ifdef PICO_STDIO_USB_RESET_BOOTSEL_FIXED_ACTIVITY_LED // backwards compatibility with SDK <= 2.2.0 +#define PICO_USB_RESET_BOOTSEL_FIXED_ACTIVITY_LED PICO_STDIO_USB_RESET_BOOTSEL_FIXED_ACTIVITY_LED +#else +#define PICO_USB_RESET_BOOTSEL_FIXED_ACTIVITY_LED 0 +#endif #endif // Any modes disabled here can't be re-enabled by picotool via VENDOR_INTERFACE. -// 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_usb_reset_interface -#ifndef PICO_STDIO_USB_RESET_BOOTSEL_INTERFACE_DISABLE_MASK -#define PICO_STDIO_USB_RESET_BOOTSEL_INTERFACE_DISABLE_MASK 0u +// PICO_CONFIG: PICO_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_usb_reset_interface +#ifndef PICO_USB_RESET_BOOTSEL_INTERFACE_DISABLE_MASK +#ifdef PICO_STDIO_USB_RESET_BOOTSEL_INTERFACE_DISABLE_MASK // backwards compatibility with SDK <= 2.2.0 +#define PICO_USB_RESET_BOOTSEL_INTERFACE_DISABLE_MASK PICO_STDIO_USB_RESET_BOOTSEL_INTERFACE_DISABLE_MASK +#else +#define PICO_USB_RESET_BOOTSEL_INTERFACE_DISABLE_MASK 0u +#endif +#endif + +// PICO_CONFIG: PICO_ENABLE_USB_RESET_VIA_BAUD_RATE, Enable/disable resetting into BOOTSEL mode if the host sets the baud rate to a magic value (PICO_USB_RESET_MAGIC_BAUD_RATE), type=bool, default=1 if application is not using TinyUSB directly, group=pico_usb_reset_interface +#ifndef PICO_ENABLE_USB_RESET_VIA_BAUD_RATE +#ifdef PICO_STDIO_USB_ENABLE_RESET_VIA_BAUD_RATE // backwards compatibility with SDK <= 2.2.0 +#define PICO_ENABLE_USB_RESET_VIA_BAUD_RATE PICO_STDIO_USB_ENABLE_RESET_VIA_BAUD_RATE +#elif !LIB_TINYUSB_HOST && !LIB_TINYUSB_DEVICE +#define PICO_ENABLE_USB_RESET_VIA_BAUD_RATE 1 +#else +#define PICO_ENABLE_USB_RESET_VIA_BAUD_RATE 0 +#endif +#endif + +// PICO_CONFIG: PICO_USB_RESET_MAGIC_BAUD_RATE, Baud rate that if selected causes a reset into BOOTSEL mode (if PICO_ENABLE_USB_RESET_VIA_BAUD_RATE is set), default=1200, group=pico_usb_reset_interface +#ifndef PICO_USB_RESET_MAGIC_BAUD_RATE +#ifdef PICO_STDIO_USB_RESET_MAGIC_BAUD_RATE // backwards compatibility with SDK <= 2.2.0 +#define PICO_USB_RESET_MAGIC_BAUD_RATE PICO_STDIO_USB_RESET_MAGIC_BAUD_RATE +#else +#define PICO_USB_RESET_MAGIC_BAUD_RATE 1200 +#endif #endif -// 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_usb_reset_interface -#ifndef PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE -#if !LIB_TINYUSB_HOST && !LIB_TINYUSB_DEVICE -#define PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE 1 +// PICO_CONFIG: PICO_ENABLE_USB_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_usb_reset_interface +#ifndef PICO_ENABLE_USB_RESET_VIA_VENDOR_INTERFACE +#ifdef PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE // backwards compatibility with SDK <= 2.2.0 +#define PICO_ENABLE_USB_RESET_VIA_VENDOR_INTERFACE PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE +#elif !LIB_TINYUSB_HOST && !LIB_TINYUSB_DEVICE +#define PICO_ENABLE_USB_RESET_VIA_VENDOR_INTERFACE 1 #else -#define PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE 0 +#define PICO_ENABLE_USB_RESET_VIA_VENDOR_INTERFACE 0 #endif #endif -// PICO_CONFIG: PICO_STDIO_USB_RESET_INCLUDE_DEFAULT_APP_DRIVER_CB, Set to 0 if your application defines its own usbd_app_driver_get_cb function, type=bool, default=1 when using pico_usb_reset_interface, 0 otherwise, group=pico_usb_reset_interface -#ifndef PICO_STDIO_USB_RESET_INCLUDE_DEFAULT_APP_DRIVER_CB -#define PICO_STDIO_USB_RESET_INCLUDE_DEFAULT_APP_DRIVER_CB LIB_PICO_STDIO_USB +// PICO_CONFIG: PICO_USB_RESET_INCLUDE_DEFAULT_APP_DRIVER_CB, Set to 0 if your application defines its own usbd_app_driver_get_cb function, type=bool, default=1 when using pico_usb_reset_interface, 0 otherwise, group=pico_usb_reset_interface +#ifndef PICO_USB_RESET_INCLUDE_DEFAULT_APP_DRIVER_CB +#ifdef PICO_STDIO_USB_RESET_INCLUDE_DEFAULT_APP_DRIVER_CB // backwards compatibility with SDK <= 2.2.0 +#define PICO_USB_RESET_INCLUDE_DEFAULT_APP_DRIVER_CB PICO_STDIO_USB_RESET_INCLUDE_DEFAULT_APP_DRIVER_CB +#else +#define PICO_USB_RESET_INCLUDE_DEFAULT_APP_DRIVER_CB LIB_PICO_STDIO_USB +#endif #endif -// 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_usb_reset_interface -#ifndef PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_BOOTSEL -#define PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_BOOTSEL 1 +// PICO_CONFIG: PICO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_BOOTSEL, If vendor reset interface is included allow rebooting to BOOTSEL mode, type=bool, default=1, group=pico_usb_reset_interface +#ifndef PICO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_BOOTSEL +#ifdef PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_BOOTSEL // backwards compatibility with SDK <= 2.2.0 +#define PICO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_BOOTSEL PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_BOOTSEL +#else +#define PICO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_BOOTSEL 1 +#endif #endif -// 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_usb_reset_interface -#ifndef PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_FLASH_BOOT -#define PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_FLASH_BOOT 1 +// PICO_CONFIG: PICO_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_usb_reset_interface +#ifndef PICO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_FLASH_BOOT +#ifdef PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_FLASH_BOOT // backwards compatibility with SDK <= 2.2.0 +#define PICO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_FLASH_BOOT PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_FLASH_BOOT +#else +#define PICO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_FLASH_BOOT 1 +#endif #endif -// PICO_CONFIG: PICO_STDIO_USB_RESET_RESET_TO_FLASH_DELAY_MS, Delay in ms before rebooting via regular flash boot, default=100, group=pico_usb_reset_interface -#ifndef PICO_STDIO_USB_RESET_RESET_TO_FLASH_DELAY_MS -#define PICO_STDIO_USB_RESET_RESET_TO_FLASH_DELAY_MS 100 +// PICO_CONFIG: PICO_USB_RESET_RESET_TO_FLASH_DELAY_MS, Delay in ms before rebooting via regular flash boot, default=100, group=pico_usb_reset_interface +#ifndef PICO_USB_RESET_RESET_TO_FLASH_DELAY_MS +#ifdef PICO_STDIO_USB_RESET_RESET_TO_FLASH_DELAY_MS // backwards compatibility with SDK <= 2.2.0 +#define PICO_USB_RESET_RESET_TO_FLASH_DELAY_MS PICO_STDIO_USB_RESET_RESET_TO_FLASH_DELAY_MS +#else +#define PICO_USB_RESET_RESET_TO_FLASH_DELAY_MS 100 +#endif #endif -// 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 if application is not using TinyUSB directly, 0 otherwise, group=pico_usb_reset_interface -#ifndef PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR -#if !LIB_TINYUSB_HOST && !LIB_TINYUSB_DEVICE -#define PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR 1 +// PICO_CONFIG: PICO_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 if application is not using TinyUSB directly, 0 otherwise, group=pico_usb_reset_interface +#ifndef PICO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR +#ifdef PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR // backwards compatibility with SDK <= 2.2.0 +#define PICO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR +#elif !LIB_TINYUSB_HOST && !LIB_TINYUSB_DEVICE +#define PICO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR 1 #else -#define PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR 0 +#define PICO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR 0 #endif #endif -// PICO_CONFIG: PICO_STDIO_USB_RESET_INTERFACE_MS_OS_20_DESCRIPTOR_ITF, If vendor reset interface is included this specifies the USB interface number for the reset interface, type=int, default=2 if application is not using TinyUSB directly, undefined otherwise, group=pico_usb_reset_interface -#ifndef PICO_STDIO_USB_RESET_INTERFACE_MS_OS_20_DESCRIPTOR_ITF -#if !LIB_TINYUSB_HOST && !LIB_TINYUSB_DEVICE -#define PICO_STDIO_USB_RESET_INTERFACE_MS_OS_20_DESCRIPTOR_ITF 2 -#elif PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR -#error Must set PICO_STDIO_USB_RESET_INTERFACE_MS_OS_20_DESCRIPTOR_ITF to the reset interface number when using PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR with custom USB descriptors +// PICO_CONFIG: PICO_USB_RESET_INTERFACE_MS_OS_20_DESCRIPTOR_ITF, If vendor reset interface is included this specifies the USB interface number for the reset interface, type=int, default=2 if application is not using TinyUSB directly, undefined otherwise, group=pico_usb_reset_interface +#ifndef PICO_USB_RESET_INTERFACE_MS_OS_20_DESCRIPTOR_ITF +#ifdef PICO_STDIO_USB_RESET_INTERFACE_MS_OS_20_DESCRIPTOR_ITF // backwards compatibility with SDK <= 2.2.0 +#define PICO_USB_RESET_INTERFACE_MS_OS_20_DESCRIPTOR_ITF PICO_STDIO_USB_RESET_INTERFACE_MS_OS_20_DESCRIPTOR_ITF +#elif !LIB_TINYUSB_HOST && !LIB_TINYUSB_DEVICE +#define PICO_USB_RESET_INTERFACE_MS_OS_20_DESCRIPTOR_ITF 2 +#elif PICO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR +#error Must set PICO_USB_RESET_INTERFACE_MS_OS_20_DESCRIPTOR_ITF to the reset interface number when using PICO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR with custom USB descriptors #endif #endif diff --git a/src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface_device.h b/src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface_device.h index b2aafce11..be5dabda4 100644 --- a/src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface_device.h +++ b/src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface_device.h @@ -18,14 +18,14 @@ * * To add this functionality to a project using TinyUSB directly, you need to: * 1. Link the pico_usb_reset_interface library, and include the `pico/usb_reset_interface_device.h` header file where needed. - * 2. Define PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE=1 + * 2. Define PICO_ENABLE_USB_RESET_VIA_VENDOR_INTERFACE=1 * 3. Add `TUD_RPI_RESET_DESCRIPTOR(, )` to your USB descriptors (length is `TUD_RPI_RESET_DESC_LEN`) * 4. Check if your project has an existing `usbd_app_driver_get_cb` function: * - If it does, you need to add the `usb_reset_interface_driver` to the drivers returned - * - If it does not, and you aren't using the `pico_stdio_usb` library, you need to define `PICO_STDIO_USB_RESET_INCLUDE_DEFAULT_APP_DRIVER_CB=1` + * - If it does not, and you aren't using the `pico_stdio_usb` library, you need to define `PICO_USB_RESET_INCLUDE_DEFAULT_APP_DRIVER_CB=1` * 5. Check if your project has an existing Microsoft OS 2.0 Descriptor: * - If it does, you need to add the Function Subset header `RPI_RESET_MS_OS_20_DESCRIPTOR()` to your Microsoft OS 2.0 Descriptor (length is `RPI_RESET_MS_OS_20_DESC_LEN`) - * - If it does not, you need to define `PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR=1` and `PICO_STDIO_USB_RESET_INTERFACE_MS_OS_20_DESCRIPTOR_ITF=` + * - If it does not, you need to define `PICO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR=1` and `PICO_USB_RESET_INTERFACE_MS_OS_20_DESCRIPTOR_ITF=` */ #include "pico/usb_reset_interface.h" diff --git a/src/rp2_common/pico_stdio_usb/include/pico/stdio_usb.h b/src/rp2_common/pico_stdio_usb/include/pico/stdio_usb.h index 5015d7efa..42aa986e6 100644 --- a/src/rp2_common/pico_stdio_usb/include/pico/stdio_usb.h +++ b/src/rp2_common/pico_stdio_usb/include/pico/stdio_usb.h @@ -62,20 +62,6 @@ #endif #endif -// PICO_CONFIG: PICO_STDIO_USB_ENABLE_RESET_VIA_BAUD_RATE, Enable/disable resetting into BOOTSEL mode if the host sets the baud rate to a magic value (PICO_STDIO_USB_RESET_MAGIC_BAUD_RATE), type=bool, default=1 if application is not using TinyUSB directly, group=pico_stdio_usb -#ifndef PICO_STDIO_USB_ENABLE_RESET_VIA_BAUD_RATE -#if !LIB_TINYUSB_HOST && !LIB_TINYUSB_DEVICE -#define PICO_STDIO_USB_ENABLE_RESET_VIA_BAUD_RATE 1 -#else -#define PICO_STDIO_USB_ENABLE_RESET_VIA_BAUD_RATE 0 -#endif -#endif - -// PICO_CONFIG: PICO_STDIO_USB_RESET_MAGIC_BAUD_RATE, Baud rate that if selected causes a reset into BOOTSEL mode (if PICO_STDIO_USB_ENABLE_RESET_VIA_BAUD_RATE is set), default=1200, group=pico_stdio_usb -#ifndef PICO_STDIO_USB_RESET_MAGIC_BAUD_RATE -#define PICO_STDIO_USB_RESET_MAGIC_BAUD_RATE 1200 -#endif - // PICO_CONFIG: PICO_STDIO_USB_CONNECT_WAIT_TIMEOUT_MS, Maximum number of milliseconds to wait during initialization for a CDC connection from the host (negative means indefinite) during initialization, default=0, group=pico_stdio_usb #ifndef PICO_STDIO_USB_CONNECT_WAIT_TIMEOUT_MS #define PICO_STDIO_USB_CONNECT_WAIT_TIMEOUT_MS 0 diff --git a/src/rp2_common/pico_stdio_usb/stdio_usb_descriptors.c b/src/rp2_common/pico_stdio_usb/stdio_usb_descriptors.c index 95796f6ac..fd4b62fe9 100644 --- a/src/rp2_common/pico_stdio_usb/stdio_usb_descriptors.c +++ b/src/rp2_common/pico_stdio_usb/stdio_usb_descriptors.c @@ -53,7 +53,7 @@ #define USBD_PRODUCT "Pico" #endif -#if !PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE +#if !PICO_ENABLE_USB_RESET_VIA_VENDOR_INTERFACE #define USBD_DESC_LEN (TUD_CONFIG_DESC_LEN + TUD_CDC_DESC_LEN) #else #define USBD_DESC_LEN (TUD_CONFIG_DESC_LEN + TUD_CDC_DESC_LEN + TUD_RPI_RESET_DESC_LEN) @@ -67,11 +67,11 @@ #endif #define USBD_ITF_CDC (0) // needs 2 interfaces -#if !PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE +#if !PICO_ENABLE_USB_RESET_VIA_VENDOR_INTERFACE #define USBD_ITF_MAX (2) #else #define USBD_ITF_RPI_RESET (2) -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"); +static_assert(USBD_ITF_RPI_RESET == PICO_USB_RESET_INTERFACE_MS_OS_20_DESCRIPTOR_ITF, "USBD_ITF_RPI_RESET must be equal to PICO_USB_RESET_INTERFACE_MS_OS_20_DESCRIPTOR_ITF"); #define USBD_ITF_MAX (3) #endif @@ -97,7 +97,7 @@ static const tusb_desc_device_t usbd_desc_device = { // This is only needed for driverless access to the reset interface - the CDC interface doesn't require these descriptors // for driverless access, but will still not work if bcdUSB = 0x210 and no descriptor is provided. Therefore always // use bcdUSB = 0x200 if the Microsoft OS 2.0 descriptor isn't enabled -#if PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE && PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR +#if PICO_ENABLE_USB_RESET_VIA_VENDOR_INTERFACE && PICO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR .bcdUSB = 0x0210, #else .bcdUSB = 0x0200, @@ -122,7 +122,7 @@ static const uint8_t usbd_desc_cfg[USBD_DESC_LEN] = { TUD_CDC_DESCRIPTOR(USBD_ITF_CDC, USBD_STR_CDC, USBD_CDC_EP_CMD, USBD_CDC_CMD_MAX_SIZE, USBD_CDC_EP_OUT, USBD_CDC_EP_IN, USBD_CDC_IN_OUT_MAX_SIZE), -#if PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE +#if PICO_ENABLE_USB_RESET_VIA_VENDOR_INTERFACE TUD_RPI_RESET_DESCRIPTOR(USBD_ITF_RPI_RESET, USBD_STR_RPI_RESET), #endif }; @@ -134,7 +134,7 @@ static const char *const usbd_desc_str[] = { [USBD_STR_PRODUCT] = USBD_PRODUCT, [USBD_STR_SERIAL] = usbd_serial_str, [USBD_STR_CDC] = "Board CDC", -#if PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE +#if PICO_ENABLE_USB_RESET_VIA_VENDOR_INTERFACE [USBD_STR_RPI_RESET] = "Reset", #endif }; diff --git a/src/rp2_common/pico_usb_reset_interface/BUILD.bazel b/src/rp2_common/pico_usb_reset_interface/BUILD.bazel index 3ec1fcd82..2515d29a1 100644 --- a/src/rp2_common/pico_usb_reset_interface/BUILD.bazel +++ b/src/rp2_common/pico_usb_reset_interface/BUILD.bazel @@ -1,5 +1,5 @@ -load("//bazel:defs.bzl", "compatible_with_config", "compatible_with_rp2", "incompatible_with_config") -load("//bazel/util:sdk_define.bzl", "pico_sdk_define") +load("@rules_cc//cc:cc_library.bzl", "cc_library") +load("//bazel:defs.bzl", "compatible_with_rp2") package(default_visibility = ["//visibility:public"]) @@ -13,8 +13,8 @@ cc_library( ], target_compatible_with = compatible_with_rp2(), deps = [ - "//src/common/pico_usb_reset_interface_headers", "//bazel/config:PICO_TINYUSB_LIB", + "//src/common/pico_usb_reset_interface_headers", "//src/rp2_common/hardware_watchdog", "//src/rp2_common/pico_bootrom", ], diff --git a/src/rp2_common/pico_usb_reset_interface/usb_reset_interface.c b/src/rp2_common/pico_usb_reset_interface/usb_reset_interface.c index ee22b4585..3ddb545b3 100644 --- a/src/rp2_common/pico_usb_reset_interface/usb_reset_interface.c +++ b/src/rp2_common/pico_usb_reset_interface/usb_reset_interface.c @@ -9,16 +9,16 @@ #include "pico/bootrom.h" #include "pico/usb_reset_interface_device.h" -#if PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE && !(PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_BOOTSEL || PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_FLASH_BOOT) -#warning PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE has been selected but neither PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_BOOTSEL nor PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_FLASH_BOOT have been selected. +#if PICO_ENABLE_USB_RESET_VIA_VENDOR_INTERFACE && !(PICO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_BOOTSEL || PICO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_FLASH_BOOT) +#warning PICO_ENABLE_USB_RESET_VIA_VENDOR_INTERFACE has been selected but neither PICO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_BOOTSEL nor PICO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_FLASH_BOOT have been selected. #endif -#if PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE +#if PICO_ENABLE_USB_RESET_VIA_VENDOR_INTERFACE #include "hardware/watchdog.h" static uint8_t itf_num; -#if PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR +#if PICO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR // Support for Microsoft OS 2.0 descriptor #define BOS_TOTAL_LEN (TUD_BOS_DESC_LEN + TUD_BOS_MICROSOFT_OS_DESC_LEN) @@ -45,7 +45,7 @@ static const uint8_t desc_ms_os_20[] = // Set header: length, type, windows version, total length 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), - RPI_RESET_MS_OS_20_DESCRIPTOR(PICO_STDIO_USB_RESET_INTERFACE_MS_OS_20_DESCRIPTOR_ITF) + RPI_RESET_MS_OS_20_DESCRIPTOR(PICO_USB_RESET_INTERFACE_MS_OS_20_DESCRIPTOR_ITF) }; TU_VERIFY_STATIC(sizeof(desc_ms_os_20) == MS_OS_20_DESC_LEN, "Incorrect size"); @@ -93,29 +93,29 @@ bool usb_reset_interface_control_xfer_cb(uint8_t __unused rhport, uint8_t stage, if (request->wIndex == itf_num) { -#if PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_BOOTSEL +#if PICO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_BOOTSEL if (request->bRequest == RESET_REQUEST_BOOTSEL) { -#ifdef PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED - int gpio = PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED; - bool active_low = PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED_ACTIVE_LOW; +#ifdef PICO_USB_RESET_BOOTSEL_ACTIVITY_LED + int gpio = PICO_USB_RESET_BOOTSEL_ACTIVITY_LED; + bool active_low = PICO_USB_RESET_BOOTSEL_ACTIVITY_LED_ACTIVE_LOW; #else int gpio = -1; bool active_low = false; #endif -#if !PICO_STDIO_USB_RESET_BOOTSEL_FIXED_ACTIVITY_LED +#if !PICO_USB_RESET_BOOTSEL_FIXED_ACTIVITY_LED if (request->wValue & 0x100) { gpio = request->wValue >> 9u; } active_low = request->wValue & 0x200; #endif - rom_reset_usb_boot_extra(gpio, (request->wValue & 0x7f) | PICO_STDIO_USB_RESET_BOOTSEL_INTERFACE_DISABLE_MASK, active_low); + rom_reset_usb_boot_extra(gpio, (request->wValue & 0x7f) | PICO_USB_RESET_BOOTSEL_INTERFACE_DISABLE_MASK, active_low); // does not return, otherwise we'd return true } #endif -#if PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_FLASH_BOOT +#if PICO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_FLASH_BOOT if (request->bRequest == RESET_REQUEST_FLASH) { - watchdog_reboot(0, 0, PICO_STDIO_USB_RESET_RESET_TO_FLASH_DELAY_MS); + watchdog_reboot(0, 0, PICO_USB_RESET_RESET_TO_FLASH_DELAY_MS); return true; } #endif @@ -128,7 +128,7 @@ bool usb_reset_interface_xfer_cb(uint8_t __unused rhport, uint8_t __unused ep_ad return true; } -#if PICO_STDIO_USB_RESET_INCLUDE_DEFAULT_APP_DRIVER_CB +#if PICO_USB_RESET_INCLUDE_DEFAULT_APP_DRIVER_CB // Implement callback to add our custom driver usbd_class_driver_t const *usbd_app_driver_get_cb(uint8_t *driver_count) { *driver_count = 1; @@ -137,18 +137,18 @@ usbd_class_driver_t const *usbd_app_driver_get_cb(uint8_t *driver_count) { #endif #endif -#if PICO_STDIO_USB_ENABLE_RESET_VIA_BAUD_RATE +#if PICO_ENABLE_USB_RESET_VIA_BAUD_RATE // Support for default BOOTSEL reset by changing baud rate void tud_cdc_line_coding_cb(__unused uint8_t itf, cdc_line_coding_t const* p_line_coding) { - if (p_line_coding->bit_rate == PICO_STDIO_USB_RESET_MAGIC_BAUD_RATE) { -#ifdef PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED - int gpio = PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED; - bool active_low = PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED_ACTIVE_LOW; + if (p_line_coding->bit_rate == PICO_USB_RESET_MAGIC_BAUD_RATE) { +#ifdef PICO_USB_RESET_BOOTSEL_ACTIVITY_LED + int gpio = PICO_USB_RESET_BOOTSEL_ACTIVITY_LED; + bool active_low = PICO_USB_RESET_BOOTSEL_ACTIVITY_LED_ACTIVE_LOW; #else int gpio = -1; bool active_low = false; #endif - rom_reset_usb_boot_extra(gpio, PICO_STDIO_USB_RESET_BOOTSEL_INTERFACE_DISABLE_MASK, active_low); + rom_reset_usb_boot_extra(gpio, PICO_USB_RESET_BOOTSEL_INTERFACE_DISABLE_MASK, active_low); } } #endif From ec402b7246484b4e04d1dafd330ffa5e94797473 Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Fri, 22 May 2026 17:02:45 +0100 Subject: [PATCH 15/22] Merge pico_stdio_usb: fix overlap between activity-LED GPIO and active_low bit (#2947) commit 97ed432d39da36146ea423ad7b0a175b3add1590 Author: Graham Sanderson Date: Tue May 19 17:37:03 2026 -0500 grr commit 90c5d5a023f5d0ae38efbb47b1a4b7efe289abb3 Author: Graham Sanderson Date: Tue May 19 17:36:27 2026 -0500 missing ) in comment commit 082e45980f52cfef103ac92700868d3bd8614020 Author: Graham Sanderson Date: Tue May 19 17:35:37 2026 -0500 Re-arrange bit patterns to be more backwards compatible commit e2436165ad8d1cd286afc577efbda62bf253febb Author: Andrii Anoshyn Date: Sat May 16 14:29:23 2026 +0300 pico_stdio_usb: fix overlap between activity-LED GPIO and active_low bit The bootsel reset USB control transfer encodes the activity-LED GPIO in wValue. The current layout reads: if (request->wValue & 0x100) { gpio = request->wValue >> 9u; } active_low = request->wValue & 0x200; Bit 9 (0x200) is the active_low flag, but `gpio = wValue >> 9` also makes bit 9 the low bit of the extracted GPIO number. As a result: - Any odd-numbered activity-LED GPIO is silently flagged active_low. - Any client wanting active_low has the GPIO number's low bit forced. The active_low line was added in commit 5a988894 (\"add rom_reset_usb_boot_extra which supports >32 pins and ACTIVE_LOW\") on top of the original \"gpio = wValue >> 9\" encoding from commit 383e88ea, without shifting the gpio over by an extra bit to make room. See #2713. Shift the GPIO extraction to (wValue >> 10) so bit 9 is reserved for active_low alone. The resulting GPIO field is 6 bits (0-63), enough for RP2040 (30 GPIOs) and RP2350 (48 GPIOs). The canonical client (picotool) only sends wValue=disable_mask with bits 0-1 set, so this does not change any in-tree behavior; the change is only visible to out-of-tree clients that build wValue with the GPIO-specified bit set. Fixes #2713. --- .../pico_usb_reset_interface/usb_reset_interface.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/rp2_common/pico_usb_reset_interface/usb_reset_interface.c b/src/rp2_common/pico_usb_reset_interface/usb_reset_interface.c index 3ddb545b3..c202b63d8 100644 --- a/src/rp2_common/pico_usb_reset_interface/usb_reset_interface.c +++ b/src/rp2_common/pico_usb_reset_interface/usb_reset_interface.c @@ -103,12 +103,17 @@ bool usb_reset_interface_control_xfer_cb(uint8_t __unused rhport, uint8_t stage, bool active_low = false; #endif #if !PICO_USB_RESET_BOOTSEL_FIXED_ACTIVITY_LED + // wValue layout: + // bits 0-1 : forwarded as the bootrom disable_interface_mask + // bit 7 : 1 if the activity-LED GPIO is active-low + // bit 8 : 1 if an activity-LED GPIO is being specified + // bits 9-15 : activity-LED GPIO number (0-127) if (request->wValue & 0x100) { gpio = request->wValue >> 9u; + active_low = request->wValue & 0x80; } - active_low = request->wValue & 0x200; #endif - rom_reset_usb_boot_extra(gpio, (request->wValue & 0x7f) | PICO_USB_RESET_BOOTSEL_INTERFACE_DISABLE_MASK, active_low); + rom_reset_usb_boot_extra(gpio, (request->wValue & 0x3) | PICO_USB_RESET_BOOTSEL_INTERFACE_DISABLE_MASK, active_low); // does not return, otherwise we'd return true } #endif From 08d1c49b8a55c7e83e422e9e6d2080986dadc269 Mon Sep 17 00:00:00 2001 From: will-v-pi <108662275+will-v-pi@users.noreply.github.com> Date: Fri, 22 May 2026 17:06:06 +0100 Subject: [PATCH 16/22] fix search & replace typo --- .../include/pico/usb_reset_interface_config.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface_config.h b/src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface_config.h index 4b535d4ee..41a22467a 100644 --- a/src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface_config.h +++ b/src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface_config.h @@ -71,7 +71,7 @@ #endif #endif -// PICO_CONFIG: PICO_USB_RESET_INCLUDE_DEFAULT_APP_DRIVER_CB, Set to 0 if your application defines its own usbd_app_driver_get_cb function, type=bool, default=1 when using pico_usb_reset_interface, 0 otherwise, group=pico_usb_reset_interface +// PICO_CONFIG: PICO_USB_RESET_INCLUDE_DEFAULT_APP_DRIVER_CB, Set to 0 if your application defines its own usbd_app_driver_get_cb function, type=bool, default=1 when using pico_stdio_usb, 0 otherwise, group=pico_usb_reset_interface #ifndef PICO_USB_RESET_INCLUDE_DEFAULT_APP_DRIVER_CB #ifdef PICO_STDIO_USB_RESET_INCLUDE_DEFAULT_APP_DRIVER_CB // backwards compatibility with SDK <= 2.2.0 #define PICO_USB_RESET_INCLUDE_DEFAULT_APP_DRIVER_CB PICO_STDIO_USB_RESET_INCLUDE_DEFAULT_APP_DRIVER_CB From 2a4d3156fbe0b02a543bf603fd3a5e59cb024986 Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Wed, 27 May 2026 09:58:50 +0100 Subject: [PATCH 17/22] Rename library to pico_usb_reset, and move headers into rp2_common --- docs/index.h | 2 +- src/cmake/rp2_common.cmake | 2 +- .../BUILD.bazel | 3 - src/rp2_common/pico_stdio_usb/CMakeLists.txt | 2 +- .../pico_stdio_usb/stdio_usb_descriptors.c | 6 +- .../BUILD.bazel | 13 ++-- src/rp2_common/pico_usb_reset/CMakeLists.txt | 13 ++++ .../pico_usb_reset/include/pico/usb_reset.h} | 16 ++--- .../include/pico/usb_reset_config.h} | 60 +++++++++---------- .../include/pico/usb_reset_tusb.h} | 4 +- .../usb_reset.c} | 14 ++--- .../pico_usb_reset_interface/CMakeLists.txt | 11 ---- 12 files changed, 75 insertions(+), 71 deletions(-) rename src/rp2_common/{pico_usb_reset_interface => pico_usb_reset}/BUILD.bazel (60%) create mode 100644 src/rp2_common/pico_usb_reset/CMakeLists.txt rename src/{common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface_device.h => rp2_common/pico_usb_reset/include/pico/usb_reset.h} (69%) rename src/{common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface_config.h => rp2_common/pico_usb_reset/include/pico/usb_reset_config.h} (67%) rename src/{common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface_tusb.h => rp2_common/pico_usb_reset/include/pico/usb_reset_tusb.h} (97%) rename src/rp2_common/{pico_usb_reset_interface/usb_reset_interface.c => pico_usb_reset/usb_reset.c} (90%) delete mode 100644 src/rp2_common/pico_usb_reset_interface/CMakeLists.txt diff --git a/docs/index.h b/docs/index.h index b7b480131..0eff88b51 100644 --- a/docs/index.h +++ b/docs/index.h @@ -128,6 +128,6 @@ * \cond boot_picoboot_headers \defgroup boot_picoboot_headers boot_picoboot_headers \endcond * \cond boot_uf2_headers \defgroup boot_uf2_headers boot_uf2_headers \endcond * \cond pico_usb_reset_interface_headers \defgroup pico_usb_reset_interface_headers pico_usb_reset_interface_headers \endcond - * \cond pico_usb_reset_interface \defgroup pico_usb_reset_interface pico_usb_reset_interface \endcond + * \cond pico_usb_reset \defgroup pico_usb_reset pico_usb_reset \endcond * @} */ diff --git a/src/cmake/rp2_common.cmake b/src/cmake/rp2_common.cmake index 40359ee8f..4a6d36092 100644 --- a/src/cmake/rp2_common.cmake +++ b/src/cmake/rp2_common.cmake @@ -124,7 +124,7 @@ if (NOT PICO_BARE_METAL) endif() pico_add_subdirectory(rp2_common/tinyusb) pico_add_subdirectory(rp2_common/pico_stdio_usb) - pico_add_subdirectory(rp2_common/pico_usb_reset_interface) + pico_add_subdirectory(rp2_common/pico_usb_reset) pico_add_subdirectory(rp2_common/pico_i2c_slave) # networking libraries - note dependency order is important diff --git a/src/common/pico_usb_reset_interface_headers/BUILD.bazel b/src/common/pico_usb_reset_interface_headers/BUILD.bazel index a840f0c8f..12df0f6b2 100644 --- a/src/common/pico_usb_reset_interface_headers/BUILD.bazel +++ b/src/common/pico_usb_reset_interface_headers/BUILD.bazel @@ -6,9 +6,6 @@ cc_library( name = "pico_usb_reset_interface_headers", hdrs = [ "include/pico/usb_reset_interface.h", - "include/pico/usb_reset_interface_config.h", - "include/pico/usb_reset_interface_device.h", - "include/pico/usb_reset_interface_tusb.h", ], includes = ["include"], ) diff --git a/src/rp2_common/pico_stdio_usb/CMakeLists.txt b/src/rp2_common/pico_stdio_usb/CMakeLists.txt index cad6a1453..c9770d23b 100644 --- a/src/rp2_common/pico_stdio_usb/CMakeLists.txt +++ b/src/rp2_common/pico_stdio_usb/CMakeLists.txt @@ -12,7 +12,7 @@ if (TARGET tinyusb_device_unmarked) pico_stdio pico_time pico_unique_id - pico_usb_reset_interface + pico_usb_reset ) target_link_libraries(pico_stdio_usb INTERFACE tinyusb_device_unmarked diff --git a/src/rp2_common/pico_stdio_usb/stdio_usb_descriptors.c b/src/rp2_common/pico_stdio_usb/stdio_usb_descriptors.c index fd4b62fe9..7e5b200f2 100644 --- a/src/rp2_common/pico_stdio_usb/stdio_usb_descriptors.c +++ b/src/rp2_common/pico_stdio_usb/stdio_usb_descriptors.c @@ -27,7 +27,7 @@ */ #include "pico/stdio_usb.h" -#include "pico/usb_reset_interface_device.h" +#include "pico/usb_reset.h" #include "pico/unique_id.h" #include "tusb.h" @@ -71,7 +71,7 @@ #define USBD_ITF_MAX (2) #else #define USBD_ITF_RPI_RESET (2) -static_assert(USBD_ITF_RPI_RESET == PICO_USB_RESET_INTERFACE_MS_OS_20_DESCRIPTOR_ITF, "USBD_ITF_RPI_RESET must be equal to PICO_USB_RESET_INTERFACE_MS_OS_20_DESCRIPTOR_ITF"); +static_assert(USBD_ITF_RPI_RESET == PICO_USB_RESET_MS_OS_20_DESCRIPTOR_ITF, "USBD_ITF_RPI_RESET must be equal to PICO_USB_RESET_MS_OS_20_DESCRIPTOR_ITF"); #define USBD_ITF_MAX (3) #endif @@ -97,7 +97,7 @@ static const tusb_desc_device_t usbd_desc_device = { // This is only needed for driverless access to the reset interface - the CDC interface doesn't require these descriptors // for driverless access, but will still not work if bcdUSB = 0x210 and no descriptor is provided. Therefore always // use bcdUSB = 0x200 if the Microsoft OS 2.0 descriptor isn't enabled -#if PICO_ENABLE_USB_RESET_VIA_VENDOR_INTERFACE && PICO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR +#if PICO_ENABLE_USB_RESET_VIA_VENDOR_INTERFACE && PICO_USB_RESET_SUPPORT_MS_OS_20_DESCRIPTOR .bcdUSB = 0x0210, #else .bcdUSB = 0x0200, diff --git a/src/rp2_common/pico_usb_reset_interface/BUILD.bazel b/src/rp2_common/pico_usb_reset/BUILD.bazel similarity index 60% rename from src/rp2_common/pico_usb_reset_interface/BUILD.bazel rename to src/rp2_common/pico_usb_reset/BUILD.bazel index 2515d29a1..e35a5b849 100644 --- a/src/rp2_common/pico_usb_reset_interface/BUILD.bazel +++ b/src/rp2_common/pico_usb_reset/BUILD.bazel @@ -4,17 +4,22 @@ load("//bazel:defs.bzl", "compatible_with_rp2") package(default_visibility = ["//visibility:public"]) cc_library( - name = "pico_usb_reset_interface", + name = "pico_usb_reset", srcs = [ - "usb_reset_interface.c", + "usb_reset.c", + ], + hdrs = [ + "include/pico/usb_reset.h", + "include/pico/usb_reset_config.h", + "include/pico/usb_reset_tusb.h", ], defines = [ - "LIB_PICO_USB_RESET_INTERFACE=1", + "LIB_PICO_USB_RESET=1", ], target_compatible_with = compatible_with_rp2(), deps = [ "//bazel/config:PICO_TINYUSB_LIB", - "//src/common/pico_usb_reset_interface_headers", + "//src/common/pico_usb_reset_headers", "//src/rp2_common/hardware_watchdog", "//src/rp2_common/pico_bootrom", ], diff --git a/src/rp2_common/pico_usb_reset/CMakeLists.txt b/src/rp2_common/pico_usb_reset/CMakeLists.txt new file mode 100644 index 000000000..b4cebe1db --- /dev/null +++ b/src/rp2_common/pico_usb_reset/CMakeLists.txt @@ -0,0 +1,13 @@ +if (TARGET tinyusb_device_unmarked) + pico_add_library(pico_usb_reset) + + target_sources(pico_usb_reset INTERFACE + ${CMAKE_CURRENT_LIST_DIR}/usb_reset.c + ) + + target_include_directories(pico_usb_reset_headers SYSTEM INTERFACE ${CMAKE_CURRENT_LIST_DIR}/include) + + target_link_libraries(pico_usb_reset INTERFACE tinyusb_device_unmarked) + + target_link_libraries(pico_usb_reset_headers INTERFACE pico_usb_reset_interface_headers) +endif() diff --git a/src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface_device.h b/src/rp2_common/pico_usb_reset/include/pico/usb_reset.h similarity index 69% rename from src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface_device.h rename to src/rp2_common/pico_usb_reset/include/pico/usb_reset.h index be5dabda4..883873b43 100644 --- a/src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface_device.h +++ b/src/rp2_common/pico_usb_reset/include/pico/usb_reset.h @@ -4,11 +4,11 @@ * SPDX-License-Identifier: BSD-3-Clause */ -#ifndef _PICO_USB_RESET_INTERFACE_DEVICE_H -#define _PICO_USB_RESET_INTERFACE_DEVICE_H +#ifndef _PICO_USB_RESET_H +#define _PICO_USB_RESET_H -/** \file usb_reset_interface_device.h - * \defgroup pico_usb_reset_interface pico_usb_reset_interface +/** \file usb_reset.h + * \defgroup pico_usb_reset pico_usb_reset * * \brief Functionality to enable the RP-series microcontroller to be reset over the USB interface. * @@ -17,7 +17,7 @@ * This functionality is included by default when using the `pico_stdio_usb` library and not using TinyUSB directly. * * To add this functionality to a project using TinyUSB directly, you need to: - * 1. Link the pico_usb_reset_interface library, and include the `pico/usb_reset_interface_device.h` header file where needed. + * 1. Link the pico_usb_reset library, and include the `pico/usb_reset.h` header file where needed. * 2. Define PICO_ENABLE_USB_RESET_VIA_VENDOR_INTERFACE=1 * 3. Add `TUD_RPI_RESET_DESCRIPTOR(, )` to your USB descriptors (length is `TUD_RPI_RESET_DESC_LEN`) * 4. Check if your project has an existing `usbd_app_driver_get_cb` function: @@ -25,11 +25,11 @@ * - If it does not, and you aren't using the `pico_stdio_usb` library, you need to define `PICO_USB_RESET_INCLUDE_DEFAULT_APP_DRIVER_CB=1` * 5. Check if your project has an existing Microsoft OS 2.0 Descriptor: * - If it does, you need to add the Function Subset header `RPI_RESET_MS_OS_20_DESCRIPTOR()` to your Microsoft OS 2.0 Descriptor (length is `RPI_RESET_MS_OS_20_DESC_LEN`) - * - If it does not, you need to define `PICO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR=1` and `PICO_USB_RESET_INTERFACE_MS_OS_20_DESCRIPTOR_ITF=` + * - If it does not, you need to define `PICO_USB_RESET_SUPPORT_MS_OS_20_DESCRIPTOR=1` and `PICO_USB_RESET_MS_OS_20_DESCRIPTOR_ITF=` */ #include "pico/usb_reset_interface.h" -#include "pico/usb_reset_interface_config.h" -#include "pico/usb_reset_interface_tusb.h" +#include "pico/usb_reset_config.h" +#include "pico/usb_reset_tusb.h" #endif \ No newline at end of file diff --git a/src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface_config.h b/src/rp2_common/pico_usb_reset/include/pico/usb_reset_config.h similarity index 67% rename from src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface_config.h rename to src/rp2_common/pico_usb_reset/include/pico/usb_reset_config.h index 41a22467a..edd3da619 100644 --- a/src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface_config.h +++ b/src/rp2_common/pico_usb_reset/include/pico/usb_reset_config.h @@ -4,15 +4,15 @@ * SPDX-License-Identifier: BSD-3-Clause */ -#ifndef _PICO_USB_RESET_INTERFACE_CONFIG_H -#define _PICO_USB_RESET_INTERFACE_CONFIG_H +#ifndef _PICO_USB_RESET_CONFIG_H +#define _PICO_USB_RESET_CONFIG_H -// PICO_CONFIG: PICO_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_usb_reset_interface +// PICO_CONFIG: PICO_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_usb_reset #ifdef PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED // backwards compatibility with SDK <= 2.2.0 #define PICO_USB_RESET_BOOTSEL_ACTIVITY_LED PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED #endif // default is undefined -// PICO_CONFIG: PICO_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_usb_reset_interface +// PICO_CONFIG: PICO_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_usb_reset #ifndef PICO_USB_RESET_BOOTSEL_ACTIVITY_LED_ACTIVE_LOW #ifdef PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED_ACTIVE_LOW // backwards compatibility with SDK <= 2.2.0 #define PICO_USB_RESET_BOOTSEL_ACTIVITY_LED_ACTIVE_LOW PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED_ACTIVE_LOW @@ -21,7 +21,7 @@ #endif #endif -// PICO_CONFIG: PICO_USB_RESET_BOOTSEL_FIXED_ACTIVITY_LED, Whether the pin specified by PICO_USB_RESET_BOOTSEL_ACTIVITY_LED is fixed or can be modified by picotool over the VENDOR USB interface, type=bool, default=0, group=pico_usb_reset_interface +// PICO_CONFIG: PICO_USB_RESET_BOOTSEL_FIXED_ACTIVITY_LED, Whether the pin specified by PICO_USB_RESET_BOOTSEL_ACTIVITY_LED is fixed or can be modified by picotool over the VENDOR USB interface, type=bool, default=0, group=pico_usb_reset #ifndef PICO_USB_RESET_BOOTSEL_FIXED_ACTIVITY_LED #ifdef PICO_STDIO_USB_RESET_BOOTSEL_FIXED_ACTIVITY_LED // backwards compatibility with SDK <= 2.2.0 #define PICO_USB_RESET_BOOTSEL_FIXED_ACTIVITY_LED PICO_STDIO_USB_RESET_BOOTSEL_FIXED_ACTIVITY_LED @@ -31,7 +31,7 @@ #endif // Any modes disabled here can't be re-enabled by picotool via VENDOR_INTERFACE. -// PICO_CONFIG: PICO_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_usb_reset_interface +// PICO_CONFIG: PICO_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_usb_reset #ifndef PICO_USB_RESET_BOOTSEL_INTERFACE_DISABLE_MASK #ifdef PICO_STDIO_USB_RESET_BOOTSEL_INTERFACE_DISABLE_MASK // backwards compatibility with SDK <= 2.2.0 #define PICO_USB_RESET_BOOTSEL_INTERFACE_DISABLE_MASK PICO_STDIO_USB_RESET_BOOTSEL_INTERFACE_DISABLE_MASK @@ -40,7 +40,7 @@ #endif #endif -// PICO_CONFIG: PICO_ENABLE_USB_RESET_VIA_BAUD_RATE, Enable/disable resetting into BOOTSEL mode if the host sets the baud rate to a magic value (PICO_USB_RESET_MAGIC_BAUD_RATE), type=bool, default=1 if application is not using TinyUSB directly, group=pico_usb_reset_interface +// PICO_CONFIG: PICO_ENABLE_USB_RESET_VIA_BAUD_RATE, Enable/disable resetting into BOOTSEL mode if the host sets the baud rate to a magic value (PICO_USB_RESET_MAGIC_BAUD_RATE), type=bool, default=1 if application is not using TinyUSB directly, group=pico_usb_reset #ifndef PICO_ENABLE_USB_RESET_VIA_BAUD_RATE #ifdef PICO_STDIO_USB_ENABLE_RESET_VIA_BAUD_RATE // backwards compatibility with SDK <= 2.2.0 #define PICO_ENABLE_USB_RESET_VIA_BAUD_RATE PICO_STDIO_USB_ENABLE_RESET_VIA_BAUD_RATE @@ -51,7 +51,7 @@ #endif #endif -// PICO_CONFIG: PICO_USB_RESET_MAGIC_BAUD_RATE, Baud rate that if selected causes a reset into BOOTSEL mode (if PICO_ENABLE_USB_RESET_VIA_BAUD_RATE is set), default=1200, group=pico_usb_reset_interface +// PICO_CONFIG: PICO_USB_RESET_MAGIC_BAUD_RATE, Baud rate that if selected causes a reset into BOOTSEL mode (if PICO_ENABLE_USB_RESET_VIA_BAUD_RATE is set), default=1200, group=pico_usb_reset #ifndef PICO_USB_RESET_MAGIC_BAUD_RATE #ifdef PICO_STDIO_USB_RESET_MAGIC_BAUD_RATE // backwards compatibility with SDK <= 2.2.0 #define PICO_USB_RESET_MAGIC_BAUD_RATE PICO_STDIO_USB_RESET_MAGIC_BAUD_RATE @@ -60,7 +60,7 @@ #endif #endif -// PICO_CONFIG: PICO_ENABLE_USB_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_usb_reset_interface +// PICO_CONFIG: PICO_ENABLE_USB_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_usb_reset #ifndef PICO_ENABLE_USB_RESET_VIA_VENDOR_INTERFACE #ifdef PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE // backwards compatibility with SDK <= 2.2.0 #define PICO_ENABLE_USB_RESET_VIA_VENDOR_INTERFACE PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE @@ -71,7 +71,7 @@ #endif #endif -// PICO_CONFIG: PICO_USB_RESET_INCLUDE_DEFAULT_APP_DRIVER_CB, Set to 0 if your application defines its own usbd_app_driver_get_cb function, type=bool, default=1 when using pico_stdio_usb, 0 otherwise, group=pico_usb_reset_interface +// PICO_CONFIG: PICO_USB_RESET_INCLUDE_DEFAULT_APP_DRIVER_CB, Set to 0 if your application defines its own usbd_app_driver_get_cb function, type=bool, default=1 when using pico_stdio_usb, 0 otherwise, group=pico_usb_reset #ifndef PICO_USB_RESET_INCLUDE_DEFAULT_APP_DRIVER_CB #ifdef PICO_STDIO_USB_RESET_INCLUDE_DEFAULT_APP_DRIVER_CB // backwards compatibility with SDK <= 2.2.0 #define PICO_USB_RESET_INCLUDE_DEFAULT_APP_DRIVER_CB PICO_STDIO_USB_RESET_INCLUDE_DEFAULT_APP_DRIVER_CB @@ -80,25 +80,25 @@ #endif #endif -// PICO_CONFIG: PICO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_BOOTSEL, If vendor reset interface is included allow rebooting to BOOTSEL mode, type=bool, default=1, group=pico_usb_reset_interface -#ifndef PICO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_BOOTSEL +// PICO_CONFIG: PICO_USB_RESET_SUPPORT_RESET_TO_BOOTSEL, If vendor reset interface is included allow rebooting to BOOTSEL mode, type=bool, default=1, group=pico_usb_reset +#ifndef PICO_USB_RESET_SUPPORT_RESET_TO_BOOTSEL #ifdef PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_BOOTSEL // backwards compatibility with SDK <= 2.2.0 -#define PICO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_BOOTSEL PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_BOOTSEL +#define PICO_USB_RESET_SUPPORT_RESET_TO_BOOTSEL PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_BOOTSEL #else -#define PICO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_BOOTSEL 1 +#define PICO_USB_RESET_SUPPORT_RESET_TO_BOOTSEL 1 #endif #endif -// PICO_CONFIG: PICO_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_usb_reset_interface -#ifndef PICO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_FLASH_BOOT +// PICO_CONFIG: PICO_USB_RESET_SUPPORT_RESET_TO_FLASH_BOOT, If vendor reset interface is included allow rebooting with regular flash boot, type=bool, default=1, group=pico_usb_reset +#ifndef PICO_USB_RESET_SUPPORT_RESET_TO_FLASH_BOOT #ifdef PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_FLASH_BOOT // backwards compatibility with SDK <= 2.2.0 -#define PICO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_FLASH_BOOT PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_FLASH_BOOT +#define PICO_USB_RESET_SUPPORT_RESET_TO_FLASH_BOOT PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_FLASH_BOOT #else -#define PICO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_FLASH_BOOT 1 +#define PICO_USB_RESET_SUPPORT_RESET_TO_FLASH_BOOT 1 #endif #endif -// PICO_CONFIG: PICO_USB_RESET_RESET_TO_FLASH_DELAY_MS, Delay in ms before rebooting via regular flash boot, default=100, group=pico_usb_reset_interface +// PICO_CONFIG: PICO_USB_RESET_RESET_TO_FLASH_DELAY_MS, Delay in ms before rebooting via regular flash boot, default=100, group=pico_usb_reset #ifndef PICO_USB_RESET_RESET_TO_FLASH_DELAY_MS #ifdef PICO_STDIO_USB_RESET_RESET_TO_FLASH_DELAY_MS // backwards compatibility with SDK <= 2.2.0 #define PICO_USB_RESET_RESET_TO_FLASH_DELAY_MS PICO_STDIO_USB_RESET_RESET_TO_FLASH_DELAY_MS @@ -107,25 +107,25 @@ #endif #endif -// PICO_CONFIG: PICO_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 if application is not using TinyUSB directly, 0 otherwise, group=pico_usb_reset_interface -#ifndef PICO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR +// PICO_CONFIG: PICO_USB_RESET_SUPPORT_MS_OS_20_DESCRIPTOR, If vendor reset interface is included add support for Microsoft OS 2.0 Descriptor, type=bool, default=1 if application is not using TinyUSB directly, 0 otherwise, group=pico_usb_reset +#ifndef PICO_USB_RESET_SUPPORT_MS_OS_20_DESCRIPTOR #ifdef PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR // backwards compatibility with SDK <= 2.2.0 -#define PICO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR +#define PICO_USB_RESET_SUPPORT_MS_OS_20_DESCRIPTOR PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR #elif !LIB_TINYUSB_HOST && !LIB_TINYUSB_DEVICE -#define PICO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR 1 +#define PICO_USB_RESET_SUPPORT_MS_OS_20_DESCRIPTOR 1 #else -#define PICO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR 0 +#define PICO_USB_RESET_SUPPORT_MS_OS_20_DESCRIPTOR 0 #endif #endif -// PICO_CONFIG: PICO_USB_RESET_INTERFACE_MS_OS_20_DESCRIPTOR_ITF, If vendor reset interface is included this specifies the USB interface number for the reset interface, type=int, default=2 if application is not using TinyUSB directly, undefined otherwise, group=pico_usb_reset_interface -#ifndef PICO_USB_RESET_INTERFACE_MS_OS_20_DESCRIPTOR_ITF +// PICO_CONFIG: PICO_USB_RESET_MS_OS_20_DESCRIPTOR_ITF, If vendor reset interface is included this specifies the USB interface number for the reset interface, type=int, default=2 if application is not using TinyUSB directly, undefined otherwise, group=pico_usb_reset +#ifndef PICO_USB_RESET_MS_OS_20_DESCRIPTOR_ITF #ifdef PICO_STDIO_USB_RESET_INTERFACE_MS_OS_20_DESCRIPTOR_ITF // backwards compatibility with SDK <= 2.2.0 -#define PICO_USB_RESET_INTERFACE_MS_OS_20_DESCRIPTOR_ITF PICO_STDIO_USB_RESET_INTERFACE_MS_OS_20_DESCRIPTOR_ITF +#define PICO_USB_RESET_MS_OS_20_DESCRIPTOR_ITF PICO_STDIO_USB_RESET_INTERFACE_MS_OS_20_DESCRIPTOR_ITF #elif !LIB_TINYUSB_HOST && !LIB_TINYUSB_DEVICE -#define PICO_USB_RESET_INTERFACE_MS_OS_20_DESCRIPTOR_ITF 2 -#elif PICO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR -#error Must set PICO_USB_RESET_INTERFACE_MS_OS_20_DESCRIPTOR_ITF to the reset interface number when using PICO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR with custom USB descriptors +#define PICO_USB_RESET_MS_OS_20_DESCRIPTOR_ITF 2 +#elif PICO_USB_RESET_SUPPORT_MS_OS_20_DESCRIPTOR +#error Must set PICO_USB_RESET_MS_OS_20_DESCRIPTOR_ITF to the reset interface number when using PICO_USB_RESET_SUPPORT_MS_OS_20_DESCRIPTOR with custom USB descriptors #endif #endif diff --git a/src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface_tusb.h b/src/rp2_common/pico_usb_reset/include/pico/usb_reset_tusb.h similarity index 97% rename from src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface_tusb.h rename to src/rp2_common/pico_usb_reset/include/pico/usb_reset_tusb.h index 5adaded6e..1ef73d7a4 100644 --- a/src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface_tusb.h +++ b/src/rp2_common/pico_usb_reset/include/pico/usb_reset_tusb.h @@ -4,8 +4,8 @@ * SPDX-License-Identifier: BSD-3-Clause */ -#ifndef _PICO_USB_RESET_INTERFACE_TUSB_H -#define _PICO_USB_RESET_INTERFACE_TUSB_H +#ifndef _PICO_USB_RESET_TUSB_H +#define _PICO_USB_RESET_TUSB_H // Interface descriptor #define TUD_RPI_RESET_DESC_LEN 9 diff --git a/src/rp2_common/pico_usb_reset_interface/usb_reset_interface.c b/src/rp2_common/pico_usb_reset/usb_reset.c similarity index 90% rename from src/rp2_common/pico_usb_reset_interface/usb_reset_interface.c rename to src/rp2_common/pico_usb_reset/usb_reset.c index c202b63d8..804d5ffac 100644 --- a/src/rp2_common/pico_usb_reset_interface/usb_reset_interface.c +++ b/src/rp2_common/pico_usb_reset/usb_reset.c @@ -7,10 +7,10 @@ #if !defined(LIB_TINYUSB_HOST) || (defined(LIB_TINYUSB_HOST) && defined(CFG_TUH_RPI_PIO_USB)) #include "pico/bootrom.h" -#include "pico/usb_reset_interface_device.h" +#include "pico/usb_reset.h" -#if PICO_ENABLE_USB_RESET_VIA_VENDOR_INTERFACE && !(PICO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_BOOTSEL || PICO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_FLASH_BOOT) -#warning PICO_ENABLE_USB_RESET_VIA_VENDOR_INTERFACE has been selected but neither PICO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_BOOTSEL nor PICO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_FLASH_BOOT have been selected. +#if PICO_ENABLE_USB_RESET_VIA_VENDOR_INTERFACE && !(PICO_USB_RESET_SUPPORT_RESET_TO_BOOTSEL || PICO_USB_RESET_SUPPORT_RESET_TO_FLASH_BOOT) +#warning PICO_ENABLE_USB_RESET_VIA_VENDOR_INTERFACE has been selected but neither PICO_USB_RESET_SUPPORT_RESET_TO_BOOTSEL nor PICO_USB_RESET_SUPPORT_RESET_TO_FLASH_BOOT have been selected. #endif #if PICO_ENABLE_USB_RESET_VIA_VENDOR_INTERFACE @@ -18,7 +18,7 @@ static uint8_t itf_num; -#if PICO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR +#if PICO_USB_RESET_SUPPORT_MS_OS_20_DESCRIPTOR // Support for Microsoft OS 2.0 descriptor #define BOS_TOTAL_LEN (TUD_BOS_DESC_LEN + TUD_BOS_MICROSOFT_OS_DESC_LEN) @@ -45,7 +45,7 @@ static const uint8_t desc_ms_os_20[] = // Set header: length, type, windows version, total length 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), - RPI_RESET_MS_OS_20_DESCRIPTOR(PICO_USB_RESET_INTERFACE_MS_OS_20_DESCRIPTOR_ITF) + RPI_RESET_MS_OS_20_DESCRIPTOR(PICO_USB_RESET_MS_OS_20_DESCRIPTOR_ITF) }; TU_VERIFY_STATIC(sizeof(desc_ms_os_20) == MS_OS_20_DESC_LEN, "Incorrect size"); @@ -93,7 +93,7 @@ bool usb_reset_interface_control_xfer_cb(uint8_t __unused rhport, uint8_t stage, if (request->wIndex == itf_num) { -#if PICO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_BOOTSEL +#if PICO_USB_RESET_SUPPORT_RESET_TO_BOOTSEL if (request->bRequest == RESET_REQUEST_BOOTSEL) { #ifdef PICO_USB_RESET_BOOTSEL_ACTIVITY_LED int gpio = PICO_USB_RESET_BOOTSEL_ACTIVITY_LED; @@ -118,7 +118,7 @@ bool usb_reset_interface_control_xfer_cb(uint8_t __unused rhport, uint8_t stage, } #endif -#if PICO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_FLASH_BOOT +#if PICO_USB_RESET_SUPPORT_RESET_TO_FLASH_BOOT if (request->bRequest == RESET_REQUEST_FLASH) { watchdog_reboot(0, 0, PICO_USB_RESET_RESET_TO_FLASH_DELAY_MS); return true; diff --git a/src/rp2_common/pico_usb_reset_interface/CMakeLists.txt b/src/rp2_common/pico_usb_reset_interface/CMakeLists.txt deleted file mode 100644 index f2f7d307a..000000000 --- a/src/rp2_common/pico_usb_reset_interface/CMakeLists.txt +++ /dev/null @@ -1,11 +0,0 @@ -if (TARGET tinyusb_device_unmarked) - pico_add_impl_library(pico_usb_reset_interface) - - target_sources(pico_usb_reset_interface INTERFACE - ${CMAKE_CURRENT_LIST_DIR}/usb_reset_interface.c - ) - - target_link_libraries(pico_usb_reset_interface INTERFACE - tinyusb_device_unmarked - ) -endif() From b13ad90cd2ddb171a46ffdcf2c953bf88b292be7 Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Wed, 27 May 2026 10:09:39 +0100 Subject: [PATCH 18/22] Fix bazel build, and remove some unnecessary backwards compatibility for new defines --- src/rp2_common/pico_usb_reset/BUILD.bazel | 3 ++- .../pico_usb_reset/include/pico/usb_reset_config.h | 8 +------- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/src/rp2_common/pico_usb_reset/BUILD.bazel b/src/rp2_common/pico_usb_reset/BUILD.bazel index e35a5b849..7fb4acca9 100644 --- a/src/rp2_common/pico_usb_reset/BUILD.bazel +++ b/src/rp2_common/pico_usb_reset/BUILD.bazel @@ -13,13 +13,14 @@ cc_library( "include/pico/usb_reset_config.h", "include/pico/usb_reset_tusb.h", ], + includes = ["include"], defines = [ "LIB_PICO_USB_RESET=1", ], target_compatible_with = compatible_with_rp2(), deps = [ "//bazel/config:PICO_TINYUSB_LIB", - "//src/common/pico_usb_reset_headers", + "//src/common/pico_usb_reset_interface_headers", "//src/rp2_common/hardware_watchdog", "//src/rp2_common/pico_bootrom", ], diff --git a/src/rp2_common/pico_usb_reset/include/pico/usb_reset_config.h b/src/rp2_common/pico_usb_reset/include/pico/usb_reset_config.h index edd3da619..ff475c0cb 100644 --- a/src/rp2_common/pico_usb_reset/include/pico/usb_reset_config.h +++ b/src/rp2_common/pico_usb_reset/include/pico/usb_reset_config.h @@ -73,12 +73,8 @@ // PICO_CONFIG: PICO_USB_RESET_INCLUDE_DEFAULT_APP_DRIVER_CB, Set to 0 if your application defines its own usbd_app_driver_get_cb function, type=bool, default=1 when using pico_stdio_usb, 0 otherwise, group=pico_usb_reset #ifndef PICO_USB_RESET_INCLUDE_DEFAULT_APP_DRIVER_CB -#ifdef PICO_STDIO_USB_RESET_INCLUDE_DEFAULT_APP_DRIVER_CB // backwards compatibility with SDK <= 2.2.0 -#define PICO_USB_RESET_INCLUDE_DEFAULT_APP_DRIVER_CB PICO_STDIO_USB_RESET_INCLUDE_DEFAULT_APP_DRIVER_CB -#else #define PICO_USB_RESET_INCLUDE_DEFAULT_APP_DRIVER_CB LIB_PICO_STDIO_USB #endif -#endif // PICO_CONFIG: PICO_USB_RESET_SUPPORT_RESET_TO_BOOTSEL, If vendor reset interface is included allow rebooting to BOOTSEL mode, type=bool, default=1, group=pico_usb_reset #ifndef PICO_USB_RESET_SUPPORT_RESET_TO_BOOTSEL @@ -120,9 +116,7 @@ // PICO_CONFIG: PICO_USB_RESET_MS_OS_20_DESCRIPTOR_ITF, If vendor reset interface is included this specifies the USB interface number for the reset interface, type=int, default=2 if application is not using TinyUSB directly, undefined otherwise, group=pico_usb_reset #ifndef PICO_USB_RESET_MS_OS_20_DESCRIPTOR_ITF -#ifdef PICO_STDIO_USB_RESET_INTERFACE_MS_OS_20_DESCRIPTOR_ITF // backwards compatibility with SDK <= 2.2.0 -#define PICO_USB_RESET_MS_OS_20_DESCRIPTOR_ITF PICO_STDIO_USB_RESET_INTERFACE_MS_OS_20_DESCRIPTOR_ITF -#elif !LIB_TINYUSB_HOST && !LIB_TINYUSB_DEVICE +#if !LIB_TINYUSB_HOST && !LIB_TINYUSB_DEVICE #define PICO_USB_RESET_MS_OS_20_DESCRIPTOR_ITF 2 #elif PICO_USB_RESET_SUPPORT_MS_OS_20_DESCRIPTOR #error Must set PICO_USB_RESET_MS_OS_20_DESCRIPTOR_ITF to the reset interface number when using PICO_USB_RESET_SUPPORT_MS_OS_20_DESCRIPTOR with custom USB descriptors From 89b77e2a34471ad59ca573c6b20ea432740ff68d Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Wed, 27 May 2026 10:18:09 +0100 Subject: [PATCH 19/22] fix bazel formatting --- src/rp2_common/pico_usb_reset/BUILD.bazel | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rp2_common/pico_usb_reset/BUILD.bazel b/src/rp2_common/pico_usb_reset/BUILD.bazel index 7fb4acca9..1eb5f439b 100644 --- a/src/rp2_common/pico_usb_reset/BUILD.bazel +++ b/src/rp2_common/pico_usb_reset/BUILD.bazel @@ -13,10 +13,10 @@ cc_library( "include/pico/usb_reset_config.h", "include/pico/usb_reset_tusb.h", ], - includes = ["include"], defines = [ "LIB_PICO_USB_RESET=1", ], + includes = ["include"], target_compatible_with = compatible_with_rp2(), deps = [ "//bazel/config:PICO_TINYUSB_LIB", From 8ad2840988d9e8b49807ab3b85b615af1ba4562d Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Wed, 27 May 2026 11:16:50 +0100 Subject: [PATCH 20/22] Reorder pico_config defines Place vendor interface defines after PICO_ENABLE_USB_RESET_VIA_VENDOR_INTERFACE, and bootsel defines after PICO_USB_RESET_SUPPORT_RESET_TO_BOOTSEL --- .../include/pico/usb_reset_config.h | 106 +++++++++--------- 1 file changed, 53 insertions(+), 53 deletions(-) diff --git a/src/rp2_common/pico_usb_reset/include/pico/usb_reset_config.h b/src/rp2_common/pico_usb_reset/include/pico/usb_reset_config.h index ff475c0cb..fe6afcc1f 100644 --- a/src/rp2_common/pico_usb_reset/include/pico/usb_reset_config.h +++ b/src/rp2_common/pico_usb_reset/include/pico/usb_reset_config.h @@ -7,39 +7,6 @@ #ifndef _PICO_USB_RESET_CONFIG_H #define _PICO_USB_RESET_CONFIG_H -// PICO_CONFIG: PICO_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_usb_reset -#ifdef PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED // backwards compatibility with SDK <= 2.2.0 -#define PICO_USB_RESET_BOOTSEL_ACTIVITY_LED PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED -#endif // default is undefined - -// PICO_CONFIG: PICO_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_usb_reset -#ifndef PICO_USB_RESET_BOOTSEL_ACTIVITY_LED_ACTIVE_LOW -#ifdef PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED_ACTIVE_LOW // backwards compatibility with SDK <= 2.2.0 -#define PICO_USB_RESET_BOOTSEL_ACTIVITY_LED_ACTIVE_LOW PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED_ACTIVE_LOW -#else -#define PICO_USB_RESET_BOOTSEL_ACTIVITY_LED_ACTIVE_LOW 0 -#endif -#endif - -// PICO_CONFIG: PICO_USB_RESET_BOOTSEL_FIXED_ACTIVITY_LED, Whether the pin specified by PICO_USB_RESET_BOOTSEL_ACTIVITY_LED is fixed or can be modified by picotool over the VENDOR USB interface, type=bool, default=0, group=pico_usb_reset -#ifndef PICO_USB_RESET_BOOTSEL_FIXED_ACTIVITY_LED -#ifdef PICO_STDIO_USB_RESET_BOOTSEL_FIXED_ACTIVITY_LED // backwards compatibility with SDK <= 2.2.0 -#define PICO_USB_RESET_BOOTSEL_FIXED_ACTIVITY_LED PICO_STDIO_USB_RESET_BOOTSEL_FIXED_ACTIVITY_LED -#else -#define PICO_USB_RESET_BOOTSEL_FIXED_ACTIVITY_LED 0 -#endif -#endif - -// Any modes disabled here can't be re-enabled by picotool via VENDOR_INTERFACE. -// PICO_CONFIG: PICO_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_usb_reset -#ifndef PICO_USB_RESET_BOOTSEL_INTERFACE_DISABLE_MASK -#ifdef PICO_STDIO_USB_RESET_BOOTSEL_INTERFACE_DISABLE_MASK // backwards compatibility with SDK <= 2.2.0 -#define PICO_USB_RESET_BOOTSEL_INTERFACE_DISABLE_MASK PICO_STDIO_USB_RESET_BOOTSEL_INTERFACE_DISABLE_MASK -#else -#define PICO_USB_RESET_BOOTSEL_INTERFACE_DISABLE_MASK 0u -#endif -#endif - // PICO_CONFIG: PICO_ENABLE_USB_RESET_VIA_BAUD_RATE, Enable/disable resetting into BOOTSEL mode if the host sets the baud rate to a magic value (PICO_USB_RESET_MAGIC_BAUD_RATE), type=bool, default=1 if application is not using TinyUSB directly, group=pico_usb_reset #ifndef PICO_ENABLE_USB_RESET_VIA_BAUD_RATE #ifdef PICO_STDIO_USB_ENABLE_RESET_VIA_BAUD_RATE // backwards compatibility with SDK <= 2.2.0 @@ -71,6 +38,26 @@ #endif #endif +// PICO_CONFIG: PICO_USB_RESET_SUPPORT_MS_OS_20_DESCRIPTOR, If vendor reset interface is included add support for Microsoft OS 2.0 Descriptor, type=bool, default=1 if application is not using TinyUSB directly, 0 otherwise, group=pico_usb_reset +#ifndef PICO_USB_RESET_SUPPORT_MS_OS_20_DESCRIPTOR +#ifdef PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR // backwards compatibility with SDK <= 2.2.0 +#define PICO_USB_RESET_SUPPORT_MS_OS_20_DESCRIPTOR PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR +#elif !LIB_TINYUSB_HOST && !LIB_TINYUSB_DEVICE +#define PICO_USB_RESET_SUPPORT_MS_OS_20_DESCRIPTOR 1 +#else +#define PICO_USB_RESET_SUPPORT_MS_OS_20_DESCRIPTOR 0 +#endif +#endif + +// PICO_CONFIG: PICO_USB_RESET_MS_OS_20_DESCRIPTOR_ITF, If vendor reset interface is included this specifies the USB interface number for the reset interface, type=int, default=2 if application is not using TinyUSB directly, undefined otherwise, group=pico_usb_reset +#ifndef PICO_USB_RESET_MS_OS_20_DESCRIPTOR_ITF +#if !LIB_TINYUSB_HOST && !LIB_TINYUSB_DEVICE +#define PICO_USB_RESET_MS_OS_20_DESCRIPTOR_ITF 2 +#elif PICO_USB_RESET_SUPPORT_MS_OS_20_DESCRIPTOR +#error Must set PICO_USB_RESET_MS_OS_20_DESCRIPTOR_ITF to the reset interface number when using PICO_USB_RESET_SUPPORT_MS_OS_20_DESCRIPTOR with custom USB descriptors +#endif +#endif + // PICO_CONFIG: PICO_USB_RESET_INCLUDE_DEFAULT_APP_DRIVER_CB, Set to 0 if your application defines its own usbd_app_driver_get_cb function, type=bool, default=1 when using pico_stdio_usb, 0 otherwise, group=pico_usb_reset #ifndef PICO_USB_RESET_INCLUDE_DEFAULT_APP_DRIVER_CB #define PICO_USB_RESET_INCLUDE_DEFAULT_APP_DRIVER_CB LIB_PICO_STDIO_USB @@ -85,6 +72,39 @@ #endif #endif +// PICO_CONFIG: PICO_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_usb_reset +#ifdef PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED // backwards compatibility with SDK <= 2.2.0 +#define PICO_USB_RESET_BOOTSEL_ACTIVITY_LED PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED +#endif // default is undefined + +// PICO_CONFIG: PICO_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_usb_reset +#ifndef PICO_USB_RESET_BOOTSEL_ACTIVITY_LED_ACTIVE_LOW +#ifdef PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED_ACTIVE_LOW // backwards compatibility with SDK <= 2.2.0 +#define PICO_USB_RESET_BOOTSEL_ACTIVITY_LED_ACTIVE_LOW PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED_ACTIVE_LOW +#else +#define PICO_USB_RESET_BOOTSEL_ACTIVITY_LED_ACTIVE_LOW 0 +#endif +#endif + +// PICO_CONFIG: PICO_USB_RESET_BOOTSEL_FIXED_ACTIVITY_LED, Whether the pin specified by PICO_USB_RESET_BOOTSEL_ACTIVITY_LED is fixed or can be modified by picotool over the VENDOR USB interface, type=bool, default=0, group=pico_usb_reset +#ifndef PICO_USB_RESET_BOOTSEL_FIXED_ACTIVITY_LED +#ifdef PICO_STDIO_USB_RESET_BOOTSEL_FIXED_ACTIVITY_LED // backwards compatibility with SDK <= 2.2.0 +#define PICO_USB_RESET_BOOTSEL_FIXED_ACTIVITY_LED PICO_STDIO_USB_RESET_BOOTSEL_FIXED_ACTIVITY_LED +#else +#define PICO_USB_RESET_BOOTSEL_FIXED_ACTIVITY_LED 0 +#endif +#endif + +// Any modes disabled here can't be re-enabled by picotool via VENDOR_INTERFACE. +// PICO_CONFIG: PICO_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_usb_reset +#ifndef PICO_USB_RESET_BOOTSEL_INTERFACE_DISABLE_MASK +#ifdef PICO_STDIO_USB_RESET_BOOTSEL_INTERFACE_DISABLE_MASK // backwards compatibility with SDK <= 2.2.0 +#define PICO_USB_RESET_BOOTSEL_INTERFACE_DISABLE_MASK PICO_STDIO_USB_RESET_BOOTSEL_INTERFACE_DISABLE_MASK +#else +#define PICO_USB_RESET_BOOTSEL_INTERFACE_DISABLE_MASK 0u +#endif +#endif + // PICO_CONFIG: PICO_USB_RESET_SUPPORT_RESET_TO_FLASH_BOOT, If vendor reset interface is included allow rebooting with regular flash boot, type=bool, default=1, group=pico_usb_reset #ifndef PICO_USB_RESET_SUPPORT_RESET_TO_FLASH_BOOT #ifdef PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_FLASH_BOOT // backwards compatibility with SDK <= 2.2.0 @@ -103,24 +123,4 @@ #endif #endif -// PICO_CONFIG: PICO_USB_RESET_SUPPORT_MS_OS_20_DESCRIPTOR, If vendor reset interface is included add support for Microsoft OS 2.0 Descriptor, type=bool, default=1 if application is not using TinyUSB directly, 0 otherwise, group=pico_usb_reset -#ifndef PICO_USB_RESET_SUPPORT_MS_OS_20_DESCRIPTOR -#ifdef PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR // backwards compatibility with SDK <= 2.2.0 -#define PICO_USB_RESET_SUPPORT_MS_OS_20_DESCRIPTOR PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR -#elif !LIB_TINYUSB_HOST && !LIB_TINYUSB_DEVICE -#define PICO_USB_RESET_SUPPORT_MS_OS_20_DESCRIPTOR 1 -#else -#define PICO_USB_RESET_SUPPORT_MS_OS_20_DESCRIPTOR 0 -#endif -#endif - -// PICO_CONFIG: PICO_USB_RESET_MS_OS_20_DESCRIPTOR_ITF, If vendor reset interface is included this specifies the USB interface number for the reset interface, type=int, default=2 if application is not using TinyUSB directly, undefined otherwise, group=pico_usb_reset -#ifndef PICO_USB_RESET_MS_OS_20_DESCRIPTOR_ITF -#if !LIB_TINYUSB_HOST && !LIB_TINYUSB_DEVICE -#define PICO_USB_RESET_MS_OS_20_DESCRIPTOR_ITF 2 -#elif PICO_USB_RESET_SUPPORT_MS_OS_20_DESCRIPTOR -#error Must set PICO_USB_RESET_MS_OS_20_DESCRIPTOR_ITF to the reset interface number when using PICO_USB_RESET_SUPPORT_MS_OS_20_DESCRIPTOR with custom USB descriptors -#endif -#endif - #endif \ No newline at end of file From 69e98805717d4625cb2efc9d73faadc41015f853 Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Wed, 27 May 2026 11:19:04 +0100 Subject: [PATCH 21/22] Mention that active_low is ignored on RP2040 --- src/rp2_common/pico_usb_reset/include/pico/usb_reset_config.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rp2_common/pico_usb_reset/include/pico/usb_reset_config.h b/src/rp2_common/pico_usb_reset/include/pico/usb_reset_config.h index fe6afcc1f..6084cdb0e 100644 --- a/src/rp2_common/pico_usb_reset/include/pico/usb_reset_config.h +++ b/src/rp2_common/pico_usb_reset/include/pico/usb_reset_config.h @@ -77,7 +77,7 @@ #define PICO_USB_RESET_BOOTSEL_ACTIVITY_LED PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED #endif // default is undefined -// PICO_CONFIG: PICO_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_usb_reset +// PICO_CONFIG: PICO_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 (ignored on RP2040), type=bool, default=0, group=pico_usb_reset #ifndef PICO_USB_RESET_BOOTSEL_ACTIVITY_LED_ACTIVE_LOW #ifdef PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED_ACTIVE_LOW // backwards compatibility with SDK <= 2.2.0 #define PICO_USB_RESET_BOOTSEL_ACTIVITY_LED_ACTIVE_LOW PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED_ACTIVE_LOW From 448402b08650f6021e8b5670650ef999de2c5462 Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Wed, 27 May 2026 11:27:17 +0100 Subject: [PATCH 22/22] Make wValue parsing better match the comment --- src/rp2_common/pico_usb_reset/usb_reset.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rp2_common/pico_usb_reset/usb_reset.c b/src/rp2_common/pico_usb_reset/usb_reset.c index 804d5ffac..f40a16969 100644 --- a/src/rp2_common/pico_usb_reset/usb_reset.c +++ b/src/rp2_common/pico_usb_reset/usb_reset.c @@ -108,9 +108,9 @@ bool usb_reset_interface_control_xfer_cb(uint8_t __unused rhport, uint8_t stage, // bit 7 : 1 if the activity-LED GPIO is active-low // bit 8 : 1 if an activity-LED GPIO is being specified // bits 9-15 : activity-LED GPIO number (0-127) - if (request->wValue & 0x100) { + if (request->wValue & (1u << 8)) { + active_low = request->wValue & (1u << 7); gpio = request->wValue >> 9u; - active_low = request->wValue & 0x80; } #endif rom_reset_usb_boot_extra(gpio, (request->wValue & 0x3) | PICO_USB_RESET_BOOTSEL_INTERFACE_DISABLE_MASK, active_low);