From 30e90bdfd281bc2cd5ee025f1509cca40847c110 Mon Sep 17 00:00:00 2001 From: MCUdude Date: Wed, 14 Dec 2022 20:11:43 +0100 Subject: [PATCH] Add alternative USB PID for PICkit4/SNAP in PIC mode --- src/jtag3.c | 10 ++++++++++ src/usbdevs.h | 36 +++++++++++++++++++----------------- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/src/jtag3.c b/src/jtag3.c index 7e660b92..f541fc60 100644 --- a/src/jtag3.c +++ b/src/jtag3.c @@ -1497,6 +1497,11 @@ int jtag3_open_common(PROGRAMMER *pgm, const char *port) { pinfo.usbinfo.vid = USB_VENDOR_MICROCHIP; pinfo.usbinfo.pid = USB_DEVICE_SNAP_PIC_MODE; int pic_mode = serial_open(port, pinfo, &pgm->fd); + if(pic_mode < 0) { + // Retry with alternative USB PID + pinfo.usbinfo.pid = USB_DEVICE_SNAP_PIC_MODE_ALT; + pic_mode = serial_open(port, pinfo, &pgm->fd); + } if(pic_mode >= 0) { msg_error("\n"); pmsg_error("MPLAB SNAP in PIC mode detected!\n"); @@ -1507,6 +1512,11 @@ int jtag3_open_common(PROGRAMMER *pgm, const char *port) { pinfo.usbinfo.vid = USB_VENDOR_MICROCHIP; pinfo.usbinfo.pid = USB_DEVICE_PICKIT4_PIC_MODE; int pic_mode = serial_open(port, pinfo, &pgm->fd); + if(pic_mode < 0) { + // Retry with alternative USB PID + pinfo.usbinfo.pid = USB_DEVICE_PICKIT4_PIC_MODE_ALT; + pic_mode = serial_open(port, pinfo, &pgm->fd); + } if(pic_mode >= 0) { msg_error("\n"); pmsg_error("PICkit4 in PIC mode detected!\n"); diff --git a/src/usbdevs.h b/src/usbdevs.h index f801e01b..8eafc126 100644 --- a/src/usbdevs.h +++ b/src/usbdevs.h @@ -25,24 +25,26 @@ #ifndef usbdevs_h #define usbdevs_h -#define USB_VENDOR_ATMEL 0x03EB -#define USB_VENDOR_MICROCHIP 0x04D8 +#define USB_VENDOR_ATMEL 0x03EB +#define USB_VENDOR_MICROCHIP 0x04D8 -#define USB_DEVICE_JTAGICEMKII 0x2103 -#define USB_DEVICE_AVRISPMKII 0x2104 -#define USB_DEVICE_STK600 0x2106 -#define USB_DEVICE_AVRDRAGON 0x2107 -#define USB_DEVICE_JTAGICE3 0x2110 -#define USB_DEVICE_XPLAINEDPRO 0x2111 -#define USB_DEVICE_JTAG3_EDBG 0x2140 -#define USB_DEVICE_ATMEL_ICE 0x2141 -#define USB_DEVICE_POWERDEBUGGER 0x2144 -#define USB_DEVICE_XPLAINEDMINI 0x2145 -#define USB_DEVICE_PKOBN 0x2175 -#define USB_DEVICE_PICKIT4_AVR_MODE 0x2177 -#define USB_DEVICE_PICKIT4_PIC_MODE 0x9012 -#define USB_DEVICE_SNAP_AVR_MODE 0x2180 -#define USB_DEVICE_SNAP_PIC_MODE 0x9018 +#define USB_DEVICE_JTAGICEMKII 0x2103 +#define USB_DEVICE_AVRISPMKII 0x2104 +#define USB_DEVICE_STK600 0x2106 +#define USB_DEVICE_AVRDRAGON 0x2107 +#define USB_DEVICE_JTAGICE3 0x2110 +#define USB_DEVICE_XPLAINEDPRO 0x2111 +#define USB_DEVICE_JTAG3_EDBG 0x2140 +#define USB_DEVICE_ATMEL_ICE 0x2141 +#define USB_DEVICE_POWERDEBUGGER 0x2144 +#define USB_DEVICE_XPLAINEDMINI 0x2145 +#define USB_DEVICE_PKOBN 0x2175 +#define USB_DEVICE_PICKIT4_AVR_MODE 0x2177 +#define USB_DEVICE_PICKIT4_PIC_MODE 0x9012 +#define USB_DEVICE_PICKIT4_PIC_MODE_ALT 0x9017 +#define USB_DEVICE_SNAP_AVR_MODE 0x2180 +#define USB_DEVICE_SNAP_PIC_MODE 0x9018 +#define USB_DEVICE_SNAP_PIC_MODE_ALT 0x9019 #define USB_VENDOR_FTDI 0x0403 #define USB_DEVICE_FT2232 0x6010