From ccb51c985b7637c6fab31db516c0f4ce3f5425d4 Mon Sep 17 00:00:00 2001 From: Tom Mloduchowski Date: Mon, 13 Nov 2023 11:08:53 -0500 Subject: [PATCH] Support rebooting picoprobe CMSIS-DAP v2 devices (requires FarProbe's fork of picoprobe --- main.cpp | 13 ++++++++++--- picoboot_connection/picoboot_connection.c | 3 +++ picoboot_connection/picoboot_connection.h | 1 + 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/main.cpp b/main.cpp index 1f38c24..46c2e85 100644 --- a/main.cpp +++ b/main.cpp @@ -2110,7 +2110,12 @@ static int reboot_device(libusb_device *device, bool bootsel, uint disable_mask= bool reboot_command::execute(device_map &devices) { if (settings.force) { - reboot_device(devices[dr_vidpid_stdio_usb][0].first, settings.reboot_usb); + if (!devices[dr_vidpid_stdio_usb].empty()) { + reboot_device(devices[dr_vidpid_stdio_usb][0].first, settings.reboot_usb); + } + if (!devices[dr_vidpid_cmsis].empty()) { + reboot_device(devices[dr_vidpid_cmsis][0].first, settings.reboot_usb); + } if (!quiet) { if (settings.reboot_usb) { std::cout << "The device was asked to reboot into BOOTSEL mode.\n"; @@ -2242,7 +2247,7 @@ int main(int argc, char **argv) { // fall thru case cmd::device_support::one: if (devices[dr_vidpid_bootrom_ok].empty() && - (!settings.force || devices[dr_vidpid_stdio_usb].empty())) { + (!settings.force || (devices[dr_vidpid_stdio_usb].empty() && devices[dr_vidpid_cmsis].empty()) )) { bool had_note = false; fos << missing_device_string(tries>0); if (tries > 0) { @@ -2270,6 +2275,8 @@ int main(int argc, char **argv) { #endif printer(dr_vidpid_picoprobe, " appears to be a RP2040 PicoProbe device not in BOOTSEL mode."); + printer(dr_vidpid_cmsis, + " appears to be a RP2040 CMSIS-DAP device not in BOOTSEL mode."); printer(dr_vidpid_micropython, " appears to be a RP2040 MicroPython device not in BOOTSEL mode."); if (selected_cmd->force_requires_pre_reboot()) { @@ -2306,7 +2313,7 @@ int main(int argc, char **argv) { } if (!rc) { if (settings.force && ctx) { // actually ctx should never be null as we are targeting device if force is set, but still - if (devices[dr_vidpid_stdio_usb].size() != 1) { + if (devices[dr_vidpid_stdio_usb].size() + devices[dr_vidpid_cmsis].size() != 1) { fail(ERROR_NOT_POSSIBLE, "Forced command requires a single rebootable RP2040 device to be targeted."); } diff --git a/picoboot_connection/picoboot_connection.c b/picoboot_connection/picoboot_connection.c index d1f2bee..64cb2db 100644 --- a/picoboot_connection/picoboot_connection.c +++ b/picoboot_connection/picoboot_connection.c @@ -25,6 +25,7 @@ static bool verbose; #define PRODUCT_ID_PICOPROBE 0x0004u #define PRODUCT_ID_MICROPYTHON 0x0005u #define PRODUCT_ID_STDIO_USB 0x000au +#define PRODUCT_ID_CMSIS 0x000cu uint32_t crc32_for_byte(uint32_t remainder) { const uint32_t POLYNOMIAL = 0x4C11DB7; @@ -75,6 +76,8 @@ enum picoboot_device_result picoboot_open_device(libusb_device *device, libusb_d return dr_vidpid_picoprobe; case PRODUCT_ID_STDIO_USB: return dr_vidpid_stdio_usb; + case PRODUCT_ID_CMSIS: + return dr_vidpid_cmsis; case PRODUCT_ID_RP2_USBBOOT: break; default: diff --git a/picoboot_connection/picoboot_connection.h b/picoboot_connection/picoboot_connection.h index ebdabfc..0d7e9b2 100644 --- a/picoboot_connection/picoboot_connection.h +++ b/picoboot_connection/picoboot_connection.h @@ -26,6 +26,7 @@ enum picoboot_device_result { dr_vidpid_unknown, dr_error, dr_vidpid_stdio_usb, + dr_vidpid_cmsis, }; enum picoboot_device_result picoboot_open_device(libusb_device *device, libusb_device_handle **dev_handle);