Skip to content
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

Add support for resetting RP2040 via the USB connection when using pi… #197

Merged
merged 1 commit into from
Mar 1, 2021

Conversation

kilograham
Copy link
Contributor

…co_stdio_usb

- setting baud rate to magic value (default=1200) will cause a reset to BOOTSEL mode
- a VENDOR interface along side the CDC interface can be used to reset via refular flash boot, or into
  BOOTSEL mode with control for the reset_usb_boot parameters for the latter

either method can be configured/enabled/disabled via #define

@kilograham kilograham added this to the 1.0.2 milestone Feb 28, 2021
@kilograham kilograham self-assigned this Feb 28, 2021
…co_stdio_usb

	- setting baud rate to magic value (default=1200) will cause a reset to BOOTSEL mode
	- a VENDOR interface along side the CDC interface can be used to reset via refular flash boot, or into
	  BOOTSEL mode with control for the reset_usb_boot parameters for the latter
either method can be configured/enabled/disabled via #define
@kilograham
Copy link
Contributor Author

fixes #112

#define PICO_STDIO_USB_RESET_MAGIC_BAUD_RATE 1200
#endif

// PICO_CONFIG: PICO_STDIO_USB_ENABLE_RESET_VIA_BAUD_RATE, Enable/disable resetting into BOOTSEL mode via an additional VENDOR USB interface - enables picotool based reset, type=bool, default=1, group=pico_stdio_usb
Copy link
Contributor

Choose a reason for hiding this comment

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

PICO_STDIO_USB_ENABLE_RESET_VIA_BAUD_RATE here should be PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE

Copy link
Contributor

Choose a reason for hiding this comment

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

(this was fixed in #206 )

@liamfraser
Copy link
Contributor

Looks good. I didn't realise you could implement your own vendor driver like that!


// PICO_CONFIG: PICO_STDIO_USB_RESET_RESET_TO_FLASH_DELAY_MS, delays 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
Copy link
Contributor

@lurch lurch Mar 1, 2021

Choose a reason for hiding this comment

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

Just out of curiosity, why would somebody ever need/want to change this?
(especially given that there's no similar "reset delay" for RESET_TO_BOOTSEL)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the probably don't, but no harm in creating a define since I picked an arbitrary value

if (request->wValue & 0x100) {
gpio_mask = 1u << (request->wValue >> 9u);
}
reset_usb_boot(gpio_mask, request->wValue & 0x7f);
Copy link
Contributor

Choose a reason for hiding this comment

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

Does there need to be some comments about what request->wValue can be set to, or will that be covered by the picotool source-code?

@kadamski
Copy link

kadamski commented Mar 1, 2021

Is there a related change to picotool that make use of this vendor interface? Or some other simple test script?

@kilograham kilograham merged commit 73751b8 into develop Mar 1, 2021
@kilograham kilograham deleted the stdio-usb-reset-to-bootsel branch March 1, 2021 14:36
@kilograham
Copy link
Contributor Author

Looks good. I didn't realise you could implement your own vendor driver like that!

I didn't either until I found out the default one forced you to use endpoints (also this way pulls in much less code)

@raspberrypi raspberrypi deleted a comment from lurch Mar 1, 2021
@kilograham
Copy link
Contributor Author

Is there a related change to picotool that make use of this vendor interface? Or some other simple test script?

not public yet; i tested it locally within picotool, so i could release this, but the picotool changes will come soon separately

@laf0rge
Copy link

laf0rge commented May 18, 2023

The big question with this is now: How can the actual application (i.e. what I as a user of the SDK write) implement custom class drivers in my application? It looks like the pico SDK is using this feature of tiny-usb for internal purposes?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pico_stdio_usb should (optionally) support a mechanism to reboot the RP2040 device
5 participants