Why do I have to disconnect and reconnect the Microchip ICD3 after every programming?

I'm having a problem with the Microchip ICD3 programmer.

I'm getting connection problems, connecting to the programmer itself, even when using the selftest mode with the Microchip-provided selftest hardware board.

After plugging the ICD3 into my laptop, it always works the first time I run the selftest.

The second time, I get this error message:

"Could not connect to the selected hardware tool. Please make sure the tool is not being used by another project in MPLAB X."

If I unplug and replug the ICD3 to the laptop, it works again one more time.

I'm running Linux Mint Qiana. I've tried it in Windows 7, and there it works reliably every time. I've also tried it in Debian Jessie, and there it fails like in Linux Mint Qiana. I've also tried it on Redhat Fedora Core 22, and there the computer hangs at the end of the MPLabX install (screen goes black, computer becomes unresponsive).

I've been using MPLabX version v3.05 (I've tried it with version 2.x-something as well, but it fails in the same way with a slightly different error message).

So, the above eliminates the following causes:

• My PIC program/PIC (since it isn't even involved)
• My ICD3 hardware (since it works in Windows)

So the problem must be in my linux installation. I'm assuming Microchip, being a large and quality-minded company, must be testing their software before release. So I'm assuming the ICD3 worked at one time for a Microchip-employee. So my question is basically, what Linux distro were they using, and what differs between that and mine so that mine doesn't work?

• Have you contacted Microchip support, or asked on the Microchip forums? Jul 8, 2015 at 9:14
• No, maybe that's a better place to start. Jul 8, 2015 at 9:51
• As you say, "Microchip being a large and quality-minded company", in my limited experience when I had similar issues with a PICKit3, the Microchip telephone support was fast and efficient. Jul 8, 2015 at 9:53
• Microchip contacted me, with some follow up questions and ideas to try! I'm very happy with their support so far. Jul 15, 2015 at 16:43

At present you want to stay with 2.15, if you want your debugger to work on Linux. USB driver was faulty before this version, then MC fixed it and then regressed. It definitely works on 64-bit jessie with 32-bit libs, in 2 places I'm aware of.

• Do you get the same problem as I do when you try out MPLabX 3.x? Jul 9, 2015 at 21:26
• I don't try anything at the moment - in my not-so-humble opinion this it a silly thing to do. A colleague has a ticket open with MC and helping them testing (he's unix person more than EE). In return, they are expected to make him aware of a stable version when it becomes available. Jul 9, 2015 at 21:52
• What I meant to ask was if you have the same problem. I take it that the unix person you mentioned does? Maybe I'll just wait then. Jul 9, 2015 at 21:54
• AFAIK it started with the version after 2.15. I only attempted 2.20 and 2.30, they would show the debugger but give an error as soon as I tried to use it. Jul 9, 2015 at 22:34

I haven't really solved the problem, but I've found a rather ugly workaround that is just barely better than nothing.

I've written the following python-script to reset the USB-port. This gets the ICD 3 working again when it stops working, without having to unplug and plug it again.

import os
import sys
import fcntl
import re
if not lsusb:
print "No ICD3 seems to be connected."
sys.exit(0)
bus,busid,device,deviceid=re.split(r'[\t :]',lsusb)[:4]
if bus.lower()!="bus" or device.lower()!="device": raise Exception("Unexpected output from lsusb command. Maybe it doesn't work as is expected by this program, any longer")
dev="/dev/bus/usb/%s/%s"%(busid,deviceid)
print "Resetting USB ICD3 device at",dev
fd=os.open(dev,os.O_WRONLY)
USBDEVFS_RESET = ord('U') << (4*2) | 20
fcntl.ioctl(fd,USBDEVFS_RESET,0)
os.close(fd)


Stackexchange isn't the optimum format to deliver python-programs, but I believe copy-pasting the above to a file called fixicd3.py, and then runnig it using:

python fixicd3.py


will work. This is for linux only, and may not work with USB-hubs (I haven't tried). Also, the program is a complete and utter hack.

Adding the above script as a "Run after build" command in MPLabX works almost ok for programming the board. However, for debugging, it doesn't solve the problem, since when connection is lost during a debugging session, resetting the USB device does no good (you can't continue with the same debugging session then).

There's a setting in MPLabX:

"Maintain active connection to Hardware Tool", under Tools->Options->Embedded->Generic Settings

Checking this box resolves the problem.

Occasionally I get this in the MPLAB-IDE console in Ubuntu. Its misleading because it tells you the problem is on the target board. It's not. It's a permissions problem with the usb driver.

Transmission on endpoint 2 failed
The target circuit may require more power than
the debug tool can provide. An external power
supply might be necessary.
Connection Failed.
If the problem persists, please disconnect and
reconnect the ICD 3 to the USB cable. If this
does not fix the problem verify that the proper
MPLAB X USB drivers have been installed.


This fixes it.

$cd /dev/bus/usb$ sudo chmod 777 *