Skip to content

Improve forced commands for RP2040 and custom vid/pid #263

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

Draft
wants to merge 5 commits into
base: develop
Choose a base branch
from

Conversation

will-v-pi
Copy link
Contributor

@will-v-pi will-v-pi commented Jul 22, 2025

Allow forced commands with RP2040 on Windows - they will not deactivate the mass storage device, to ensure Zadig still works

Also fix forced commands with custom vid/pid (as they will change in bootsel mode), by removing vid/pid filters after reboot and just filtering on serial number

Fixes #260 and #261

@will-v-pi will-v-pi added this to the 2.3.0 milestone Jul 22, 2025
The vid/pid will typically change when switching to BOOTSEL mode, so remove those filters and just filter on serial number if present

Fixes #261
Calling GET_INFO when not available sometimes causes issues with forced commands

Also improve libusb error messages when debugging
@will-v-pi will-v-pi changed the title Remove vid/pid filter when using forced commands Improve forced commands for RP2040 and custom vid/pid Aug 6, 2025
Comment on lines +8776 to +8777
// also skip vid/pid filtering, as that should change in BOOTSEL mode, and could be white-labelled on RP2350
settings.pid = -1;
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems slightly confusing that the comment-line talks about "vid/pid filtering", but the code-line only mentions settings.pid?

Comment on lines +8776 to +8780
// also skip vid/pid filtering, as that should change in BOOTSEL mode, and could be white-labelled on RP2350
settings.pid = -1;
// still filter for rpi vid/pid if we don't have a serial number, as that is an RP2040 running a no_flash binary, so will
// have a standard rpi vid/pid in BOOTSEL mode
settings.vid = settings.ser.empty() ? -1 : 0; // 0 means skip vid/pid filtering entirely, -1 means filter for rpi vid/pid
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps something like this is slightly less confusing? 🤷‍♂️

Suggested change
// also skip vid/pid filtering, as that should change in BOOTSEL mode, and could be white-labelled on RP2350
settings.pid = -1;
// still filter for rpi vid/pid if we don't have a serial number, as that is an RP2040 running a no_flash binary, so will
// have a standard rpi vid/pid in BOOTSEL mode
settings.vid = settings.ser.empty() ? -1 : 0; // 0 means skip vid/pid filtering entirely, -1 means filter for rpi vid/pid
if (settings.ser.empty()) {
// still filter for rpi vid/pid if we don't have a serial number, as that is an RP2040 running a no_flash binary, so will
// have a standard rpi vid/pid in BOOTSEL mode
settings.vid = -1; // -1 means filter for rpi vid/pid
settings.pid = -1;
} else {
// also skip vid/pid filtering, as that should change in BOOTSEL mode, and could be white-labelled on RP2350
settings.vid = 0; // 0 means skip vid/pid filtering entirely
settings.pid = -1;
}

@lurch
Copy link
Contributor

lurch commented Aug 7, 2025

I think the "Use RP2040 workarounds on Windows when using custom vid/pid (ignored on other platforms)" stuff is assuming that if you're running a UF2 on an RP2350 with a custom VID/PID, then you'll have also modified the RP2350's OTP to report the same VID/PID in BOOTSEL mode? But I guess that might not always be the case? 🤔

@will-v-pi
Copy link
Contributor Author

I think the "Use RP2040 workarounds on Windows when using custom vid/pid (ignored on other platforms)" stuff is assuming that if you're running a UF2 on an RP2350 with a custom VID/PID, then you'll have also modified the RP2350's OTP to report the same VID/PID in BOOTSEL mode? But I guess that might not always be the case? 🤔

Nope, the workaround is just to not disable the MSD, nothing to do with the actual vid/pid - if you have RP2040 stdio_usb vid/pid it autodetects that and does it automatically, but if you're using custom vid/pid then you need to tell it you have an RP2040 as it can't detect it from the vid/pid

@lurch
Copy link
Contributor

lurch commented Aug 7, 2025

I think the "Use RP2040 workarounds on Windows when using custom vid/pid (ignored on other platforms)" stuff is assuming that if you're running a UF2 on an RP2350 with a custom VID/PID, then you'll have also modified the RP2350's OTP to report the same VID/PID in BOOTSEL mode? But I guess that might not always be the case? 🤔

Nope, the workaround is just to not disable the MSD, nothing to do with the actual vid/pid - if you have RP2040 stdio_usb vid/pid it autodetects that and does it automatically, but if you're using custom vid/pid then you need to tell it you have an RP2040 as it can't detect it from the vid/pid

Okay, and how is the situation different on RP2350?

@will-v-pi
Copy link
Contributor Author

Okay, and how is the situation different on RP2350?

RP2350 bootrom has the correct MS_OS_20 USB descriptors so works on Windows out of the box - whereas RP2040 doesn’t so requires drivers installed by Zadig, which only work properly when the RP2040 in bootsel mode has the MSD enabled

@lurch
Copy link
Contributor

lurch commented Aug 7, 2025

RP2350 bootrom has the correct MS_OS_20 USB descriptors so works on Windows out of the box - whereas RP2040 doesn’t so requires drivers installed by Zadig, which only work properly when the RP2040 in bootsel mode has the MSD enabled

Ahhhh! I knew it'd probably be something obvious that I'd forgotten 😂 Thanks for the explanation.

@@ -593,6 +594,7 @@ auto device_selection =
(option("--vid") & integer("vid").set(settings.vid).if_missing([] { return "missing vid"; })) % "Filter by vendor id" +
(option("--pid") & integer("pid").set(settings.pid)) % "Filter by product id" +
(option("--ser") & value("ser").set(settings.ser)) % "Filter by serial number"
+ option("--rp2040").set(settings.force_rp2040) % "Use RP2040 workarounds on Windows when using custom vid/pid (ignored on other platforms)"
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
+ option("--rp2040").set(settings.force_rp2040) % "Use RP2040 workarounds on Windows when using custom vid/pid (ignored on other platforms)"
+ option("--rp2040").set(settings.force_rp2040) % "Use RP2040-specific workarounds when using a custom vid/pid on Windows (ignored on other platforms)"

? (it niggled me slightly that "on other platforms" was so far away from "Windows", that it wasn't entirely clear what "other platforms" was referring to 😉 )

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.

2 participants