-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add library for reset interface #2629
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
will-v-pi
wants to merge
12
commits into
raspberrypi:develop
Choose a base branch
from
will-v-pi:reset-lib
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
e7b430d
Allow use of reset interface with custom descriptors
will-v-pi e14bb98
Fix pico_config assertion error
will-v-pi 0223656
Create separate library for reset interface
will-v-pi f901baf
Move pico_usb_reset_interface library into separate folder
will-v-pi d50659c
Fix bazel build
will-v-pi 36ae2eb
Move ms_os_20_desc into header
will-v-pi 0410fa6
CFG_TUD_VENDOR isn't actually used
will-v-pi c5615f1
Add documentation to usb_reset_interface.h
will-v-pi af13646
Change #if PICO_ON_DEVICE -> #if LIB_PICO_USB_RESET_INTERFACE
will-v-pi 7c3274f
Rename publically accessible functions
will-v-pi e3c11e1
Move LIB_PICO_USB_RESET_INTERFACE only headers into separate files
will-v-pi ff769aa
Make new usb_reset_interface_device header so old usb_reset_interface…
will-v-pi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
75 changes: 75 additions & 0 deletions
75
src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface_config.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -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 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Perhaps this is slightly more readable? |
||||||
#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 |
35 changes: 35 additions & 0 deletions
35
src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface_device.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this new |
||
* | ||
* \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(<ITF_NUM>, <STR_IDX>)` 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(<ITF_NUM>)` 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=<ITF_NUM>` | ||
*/ | ||
|
||
#include "pico/usb_reset_interface.h" | ||
#include "pico/usb_reset_interface_config.h" | ||
#include "pico/usb_reset_interface_tusb.h" | ||
|
||
#endif |
64 changes: 64 additions & 0 deletions
64
src/common/pico_usb_reset_interface_headers/include/pico/usb_reset_interface_tusb.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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", | ||
], | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe? 🤷♂️