Sunday, June 10, 2007

PICkit 2 under Linux Mini-Howto

Edit: please take note this Mini-How to is obsolete now. Please go to Microchip's PICkit 2 website to download pk2cmd codes. It now supports Linux and Mac OS X along with Windows.

PICkit 2 ( is a nice little USB programmer from Microchip. It now supports many Flash MCUs from Microchip. As of now, most of the PIC12F/16F/18F 8-bit PIC MCUs and PIC24/dsPIC30/dsPIC33 16bit MCUs are supported (

Microchip has kindly published the source codes for PICkit 2 firmware and the standardalone PC application (

PICkit 2 works under Linux thanks to the efforts from several developers. The easiest to start with is pk2 from Jeff Post ( pk2-2.04 only supports version 1.x (up to V1.21) firmware. The upcoming pk2-3.x will support version 2.x firmware.

The following is the simple procedure to get pk2-2.04 built under Linux.
1) Make sure you have the necessary compiler (gcc/make) and libusb development package. Normally they are already included in the distribution.

2) Download pk2-2.04. Apply the follow patch for the file pk2usb.c.

// latest libusb: interrupt mode, works with all kernels
# define PICKIT_USB(direction) usb_interrupt_##direction //only keep this line
// older libusb: bulk mode, will only work with older kernels
//# define PICKIT_USB(direction) usb_bulk_##direction

3) Modify the default Makefile. Normally you should be using kernel version Linux 2.6.x and you should use the following option.
# ----- Use the following for Linux kernel 2.6.x: -----

4) Built pk2 with the command "make"

5) Test out pk2. Normally you need to run as root if you have not setup the proper hotplug/udev rules.

6) If it is okay, set up the hotplug/udev rules. This will depend on your distribution. The following is a quick start for you.
You can read the bundled usbhotplug.txt by Linus Walleij for more information about udev/hotplug.

7) If you encounter problems with pk2, try to ask question in pickit-devel mailing list ( Take note that you should ask general questions about PICkit 2 in Microchip Forum ( There are some good information about PICkit 2 in the Microchip Forum. In paticular, if you encounter USB emuneration problem under Linux, try the hardware changes detailed in the post ( Only Step 2 is necessary.

8) How to help out?
From Jeff Post:

Note on 10-April-2009: it is now better to use pk2cmd at Microchip PICkit 2 websites.


Darrell said...

Xiaofan, I was real excited to see this post. But, alas, I think my issues are more fundamental.

Is there a particular location to put the pk2 source code? The reason is that I have tried both FC6 and FC7 and keeping running into issues of not finding certain .h files in the search path. Probably incorrectly, I add another -I option which fixes one "no such .h file" only to create another. So, I add another -I for that one, and so on. This surely is incorrect. It would seem that most folks just type "make" and things progress.

For example, the first one I encounter is not finding usb.h. I find it at /usr/src/kernels/2.6.20-1.2962.fc6-i686/include/linux so add a -I for this path. Next compile attempt then it seems that it can't find compiler.h which is in the directoty above where I found usb.h. So, I add a -I option for that. Clearly, this is nuts. What am I missing that is so fundamental here? Why would Fedora be so different from Ubuntu when it comes to compiling the source?

So, this is where I can use some help. Seems that "make" is a pretty big leap! It's probably obvious stuff for you experts but not for all of us ... some hints would be greatly appreciated.

Xiaofan Chen said...

This bas been solved in pickit-devel Google group. You need to havelibusb (and libusb-devel) installed.

Xiaofan Chen said...

pk2cmd Linux port is now the preferred application to get PICkit 2 to work under Linux.

Mario Xerxes Castelán Castro said...

Hash: SHA256

April 6th 2010 in article comments "PICkit 2 under
Linux Mini-Howto".

>Microchip has kindly published the source codes

Did you read the copyright notice?.

The microchip source code is propietary, they don't allows you to do
*anyting* with it. I wouldn't call it kindly.

Plus, You are talking about the GNU/Linux OS. Linux is only the
Version: GnuPG v1.4.9 (GNU/Linux)


Xiaofan said...

To Mario: you have your interpretation of the license. To me it is good enough for most users unless you are a GPL purist. I am an OS neutral guy.

And I do not like to use GNU/Linux as Linux is the more often used generic name for both the kernel and the distros.

You are of course free to refer it as GNU/Linux.