From 14446950dfdef305c4e40512434640f6188a2535 Mon Sep 17 00:00:00 2001 From: MCUdude Date: Thu, 20 Oct 2022 00:13:37 +0200 Subject: [PATCH] Check for PICkit4 or SNAP in PIC mode --- src/jtag3.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/jtag3.c b/src/jtag3.c index e3e39fbe..3ca5f4e3 100644 --- a/src/jtag3.c +++ b/src/jtag3.c @@ -1504,6 +1504,30 @@ int jtag3_open_common(PROGRAMMER *pgm, const char *port) { } #endif if (rv < 0) { + // Check if SNAP or PICkit4 is in PIC mode + for(LNODEID ln=lfirst(pgm->id); ln; ln=lnext(ln)) { + if (matches(ldata(ln), "snap")) { + 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) { + msg_error("\n"); + pmsg_error("MPLAB SNAP in PIC mode detected!\n"); + imsg_error("Use MPLAB X or Microchip Studio to switch to AVR mode\n\n"); + return -1; + } + } else if(matches(ldata(ln), "pickit4")) { + 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) { + msg_error("\n"); + pmsg_error("PICkit4 in PIC mode detected!\n"); + imsg_error("Use MPLAB X or Microchip Studio to switch to AVR mode\n\n"); + return -1; + } + } + } pmsg_error("did not find any device matching VID 0x%04x and PID list: ", (unsigned) pinfo.usbinfo.vid); int notfirst = 0;