Skip to content

Add example for picotool reset #683

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
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions usb/device/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ add_subdirectory(${PICO_TINYUSB_PATH}/examples/device tinyusb_device_examples)
add_subdirectory_exclude_platforms(dev_hid_composite)
add_subdirectory_exclude_platforms(dev_lowlevel)
add_subdirectory_exclude_platforms(dev_multi_cdc)
add_subdirectory_exclude_platforms(dev_picotool_reset)
25 changes: 25 additions & 0 deletions usb/device/dev_picotool_reset/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
if (TARGET tinyusb_device)
add_executable(picotool_reset
picotool_reset.c
)

target_compile_definitions(picotool_reset PRIVATE
PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE=1
PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR=1
Comment on lines +7 to +8
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These defines are already set to 1 by default, so I'm not sure how this example differs from any of the other examples which use pico_enable_stdio_usb (eg hello_usb, hello_anything, hello_universal)? All of those examples already have support for picotool reset by default

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's useful to know how to add support for the reset interface if you have your own usb cdc setup? usb/device/dev_multi_cdc tries to do that but I seem to recall it doesn't quite work.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've just had a quick hack and got it working with dev_multi_cdc, but it'll need a few SDK changes too to allow using the reset interface without the stdio_usb default descriptors - will try more in a week or so

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of those examples already have support for picotool reset by default

Oh, I didn't realize that. I tried a long time with the usb examples and also those from tinyusb but the defines never worked on those. So once I finally tried them on the hello example it did work.
Then instead of my code changes, it might be useful to keep the readme changes and explicitly document that the hello example does indeed support the reset protocol.

I've just had a quick hack and got it working with dev_multi_cdc, but it'll need a few SDK changes too to allow using the reset interface without the stdio_usb default descriptors - will try more in a week or so

Cool, thanks!

)

# pull in common dependencies
target_link_libraries(picotool_reset pico_stdlib)

# enable usb interface, disable uart output
pico_enable_stdio_usb(picotool_reset 1)
pico_enable_stdio_uart(picotool_reset 0)

# create map/bin/hex/uf2 file etc.
pico_add_extra_outputs(picotool_reset)

# add url via pico_set_program_url
example_auto_set_url(picotool_reset)
elseif(PICO_ON_DEVICE)
message("Skipping picotool_reset because TinyUSB submodule is not initialized in the SDK")
endif()
15 changes: 15 additions & 0 deletions usb/device/dev_picotool_reset/picotool_reset.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
* Copyright (c) 2025 Framework Computer Inc
*
* SPDX-License-Identifier: BSD-3-Clause
*/

#include "pico/stdlib.h"

int main() {
stdio_init_all();

// Don't exit, wait for control transfer
while (true) {}
}