PICkit2 Software on Linux

Overview of PICkit2 command line software and device file versions on Linux

Introduction

The Microchip PICkit2 hardware programmer for PIC microcontrollers uses either PICkit2 V2.61 for Windows or the pk2cmd command line software that can be compiled on Linux and Mac OS. Both depend upon a separate device file that defines which PICs can be programmed. This page will focus on pk2cmd on Linux, and associated device files.

The PICkit2 hardware programmer is now long obsolete, so why use it? Because cheap PICkit2 clones are available on Amazon and Ebay, and alongside the pk2cmd software it is a simple way to programme Microchip PIC microcontrollers on Linux. You can, however, use PICkit3 and PICkit4 with MPLAB X, but PICkit4 is expensive and my old laptop struggles to run MPLAB X. On Windows I'd just use the official PICkit2 V2.61 GUI software with an updated device file.

My system: 2010 Acer Laptop, Linux Mint 19.3 (Linux kernal 5.3.0-46-generic), and official Microchip PICkit2 programmer with firmware version 2.32.00. I will test the system with a PIC18F46K22 microcontroller.

PICkit2 GUI application downloads

PICkit 2 v2.6.1
Windows, comes with device file 1.61.

This works well in Windows 7 and 8.1 (not tried it in Windows 10). The device file it comes with (1.61) is out of date and doesn't support many newer PICs such as most of the 18FxxK22 and 18Fxxk50 series.

This software runs in Wine on Linux, but, as you can see below, it cannot see the PICkit2 hardware.

PICkit 2 v.2.6.1 in Wine

PICkit 2 v.2.6.1 in Wine

PICkit2 command line application downloads

  1. PK2CMD v1.20 PICkit 2 Command Line Interface A
    Windows, device file 1.55
    Not tested, out of date device file. Use PICkit 2 v2.6.1 instead on Windows.

  2. PK2CMD V1.20 Linux & Mac OS X Source
    Linux, device file 1.55
    This does work on Linux, but it doesn't recognise device files 1.61 or newer. Do not use this version of pk2cmd.

  3. PICkit2_PK2CMD_WIN32_SourceV1-21_RC1
    Linux, device file 1.61.
    This works on Linux and supports all tested device files.

  4. pk2cmd on Github
    Linux, device file 1.62.14
    This works on Linux and supports all tested device files.

I recommend item 4 because it comes with a newer device file. Item 3 looks as though it also includes item 1. Both items 3 and 4 seem to work well on Linux.

Installing pk2cmd on Linux

I will describe how to install pk2cmd on Github on Linux Mint/Ubuntu, although the process is the same for items 2, 3 and 4 above.

1. Download pk2cmd

Download pk2cmd on Github and unzip.

2. Compile pk2cmd

First install the g++ compiler and libusb-dev if you don't already have them (g++ is part of the build-essential package), then navigate to the directory that contains the pk2cmd source code and compile with make linux.

sudo apt install build-essential libusb-dev
cd ~/Downloads/pk2cmd-master/pk2cmd
make linux

pk2cmd will now compile new binary files into same directory. If all goes well, you should see two or three warnings, but no errors.

You can run pk2cmd from the same directory (plug in your PICkit2 hardware before trying this):

sudo ./pk2cmd -?V -B./
Check pk2cmd installed correctly and can see the PICkit2 hardware

Check pk2cmd installed correctly and can see the PICkit2 hardware

-B./ tells pk2cmd where to find the device file (PK2DeviceFile.dat). In this instance, the device file is in the same directory as pk2cmd, hence ./. -?V tells pk2cmd to display version information.

If you have the PICkit2 connected to a PIC, try auto-detecting the PIC:

sudo ./pk2cmd -B./ -I -P
Auto-detecting a connected PIC

Auto-detecting a connected PIC

-P auto-detects PIC, and -I displays information about that PIC.

3. Install pk2cmd

Once you have compiled and tested pk2cmd, you can install it somewhere more convenient, so it can be run from anywhere without typing sudo or the full path to pk2cmd.

make install copies pk2cmd into /usr/local/bin, and copies PK2DeviceFile.dat into /usr/share/pk2. The third line adds /usr/share/pk2 to the PATH so pk2cmd can find it:

cd ~/Downloads/pk2cmd-master/pk2cmd/
make install
echo 'export PATH="$PATH:/usr/share/pk2"' >> ~/.bashrc

Close and reopen your terminal and test the newly installed pk2cmd:

cd
pk2cmd -?V
Check the install worked

Check the install worked

As you can see, I have already updated my device file to a newer version.

4. Replacing the device file

You will likely want to replace the device file for a newer version (see below for where to get them from). It is easily done:

sudo mv /usr/share/pk2/PK2DeviceFile.dat /usr/share/PK2DeviceFile.dat_OLD
sudo cp ~/Downloads/PK2DeviceFile.dat /usr/share/pk2/PK2DeviceFile.dat

This first renames the current device file in /usr/share/pk2 before copying in the newly downloaded device file from ~/Downloads.

Alternatively, you can use the -B option to tell pk2cmd where to look for the device file:

Use -B to specify a different device file

Use -B to specify a different device file

Here, you can see that I have told pk2cmd to use an older device file, for no particular reason other than to demonstrate it is possible without copying a device file into /usr/share/pk2.

5. PICkit2 hardware not found?

Sometimes when I plug in my PICkit2 to my computer's USB port, I get the following message:

PICkit 2 not found

PICkit 2 not found

I then check dmesg for USB errors:

dmesg USB errors

dmesg USB errors

It seems that sometimes, my computer fails to enumerate the PICkit2 as a USB device. I have no idea if this is a problem with my PICkit2, my computer or the particular version of Linux I am using.

After replugging the PICkit2 once or twice, it always succeeds:

dmesg USB success

dmesg USB success

And now pk2cmd will work.

Using pk2cmd

Here are some common actions.

Checking versions

pk2cmd -?V

Use -B/path/to/device/file to set the path to the device file. Without this, /usr/share/pk2/PKDeviceFile.dat will be used.

If a device file cannot be found, you need to either use the -B option or add export PATH="$PATH:/usr/share/pk2" to your .bashrc file.

List supported PICs

Display a list PICs supported with the current device file:

pk2cmd -?P

Use this command with -B to list the devices a device file supports.

Auto-detect PIC and display info

pk2cmd -P -I

-P will try to auto-detect the PIC
-I displays info about the connected PIC

Blank check a PIC

pk2cmd -P -C

-C will check if the PIC is blank

Power a PIC and release it from reset

This combination of options powers the PIC from the PICkit2 hardware and releases it from reset so the PIC can run without an external power supply.

pk2cmd -P -A5 -T -R

-Ax sets the voltage to supply (replace x with volts), e.g. -A5 to power with 5V.
-T tells PICkit2 to provide power to the PIC after an operation.
-R releases the PIC from reset after an operation (DON'T FORGET THIS OPTION!)

There is no specific option included in the above command. It automatically detects the PIC, sets the voltage to 5V, turns on power to the PIC, and releases the PIC from reset.

Program a PIC

pk2cmd -PPIC18f46k22 -T -A5 -R -J -Z -M -Fmain.hex

-M programmes the PIC
-F specifies the HEX to programme PIC with
-J displays progress as a percentage
-Z preserves EEPROM memory on PIC (to overwrite EEPROM, remove this option)

Programming a PIC

Programming a PIC

Programming succeeded

Programming succeeded

Read from a PIC

pk2cmd -PPIC18f46k22 -A5 -T -R -J -GFfrompic.hex

-GF<filename> reads contents of PIC (including EEPROM) to the specified HEX file
-GI reads ID memory and displays on screen
-GC reads configuration memory and displays on screen (as below)

Read configuration memory

Read configuration memory

Read EEPROM

pk2cmd -Ppic18f46k22 -R -J -GE00-1F

-GE<start>-<end> where <start> and <end> are in hex.

For example, the above command reads from byte 0 (=0 in hex) to byte 31 (=1F in hex):

Reading EEPROM

Reading EEPROM

PICkit2 device file downloads

Each PICkit2 software download inlcudes a device file (that are sometimes out of date), but you can still download updated device files:

  1. Device file version 1.62.14
    October 2011

  2. Device file version 1.62.14
    November 2011

  3. Device file version 1.62.14
    January 2014

  4. Device file version 1.63.148
    Octover 2013

  5. Device file version 1.63.148
    October 2015

Device file supported devices

Version 1.55

Support for:

PIC10F200 PIC10F202 PIC10F204 PIC10F206 PIC10F220 PIC10F222 PIC12F508 PIC12F509 PIC12F510 PIC12F519 PIC16F54 PIC16F57 PIC16F59 PIC16F505 PIC16F506 PIC16F526 PIC12F609 PIC12F615 PIC12F629 PIC12F635 PIC12F675 PIC12F683 PIC12HV609 PIC12HV615 PIC16F72 PIC16F73 PIC16F74 PIC16F76 PIC16F77 PIC16F84A PIC16F87 PIC16F88 PIC16F610 PIC16F616 PIC16F627 PIC16F627A PIC16F628 PIC16F628A PIC16F630 PIC16F631 PIC16F636 PIC16F648A PIC16F676 PIC16F677 PIC16F684 PIC16F685 PIC16F687 PIC16F688 PIC16F689 PIC16F690 PIC16F716 PIC16F737 PIC16F747 PIC16F767 PIC16F777 PIC16F785 PIC16F818 PIC16F819 PIC16F870 PIC16F871 PIC16F872 PIC16F873 PIC16F873A PIC16F874 PIC16F874A PIC16F876 PIC16F876A PIC16F877 PIC16F877A PIC16F882 PIC16F883 PIC16F884 PIC16F886 PIC16F887 PIC16F913 PIC16F914 PIC16F916 PIC16F917 PIC16F946 PIC16HV610 PIC16HV616 PIC16HV785 PIC16F722 PIC16F723 PIC16F724 PIC16F726 PIC16F727 PIC16F1933 PIC16F1934 PIC16F1936 PIC16F1937 PIC16F1938 PIC16F1939 PIC16LF722 PIC16LF723 PIC16LF724 PIC16LF726 PIC16LF727 PIC16LF1933 PIC16LF1934 PIC16LF1936 PIC16LF1937 PIC16LF1938 PIC16LF1939 PIC18F242 PIC18F248 PIC18F252 PIC18F258 PIC18F442 PIC18F448 PIC18F452 PIC18F458 PIC18F1220 PIC18F1230 PIC18F1320 PIC18F1330 PIC18F1330 PIC18F2220 PIC18F2221 PIC18F2320 PIC18F2321 PIC18F2331 PIC18F2410 PIC18F2420 PIC18F2423 PIC18F2431 PIC18F2450 PIC18F2455 PIC18F2458 PIC18F2480 PIC18F2510 PIC18F2515 PIC18F2520 PIC18F2523 PIC18F2525 PIC18F2550 PIC18F2553 PIC18F2580 PIC18F2585 PIC18F2610 PIC18F2620 PIC18F2680 PIC18F2682 PIC18F2685 PIC18F4220 PIC18F4221 PIC18F4320 PIC18F4321 PIC18F4331 PIC18F4410 PIC18F4420 PIC18F4423 PIC18F4431 PIC18F4450 PIC18F4455 PIC18F4458 PIC18F4480 PIC18F4510 PIC18F4515 PIC18F4520 PIC18F4523 PIC18F4525 PIC18F4550 PIC18F4553 PIC18F4580 PIC18F4585 PIC18F4610 PIC18F4620 PIC18F4680 PIC18F4682 PIC18F4685 PIC18F6310 PIC18F6390 PIC18F6393 PIC18F6410 PIC18F6490 PIC18F6493 PIC18F6520 PIC18F6525 PIC18F6527 PIC18F6585 PIC18F6620 PIC18F6621 PIC18F6622 PIC18F6627 PIC18F6628 PIC18F6680 PIC18F6720 PIC18F6722 PIC18F6723 PIC18F8310 PIC18F8390 PIC18F8393 PIC18F8410 PIC18F8490 PIC18F8493 PIC18F8520 PIC18F8525 PIC18F8527 PIC18F8585 PIC18F8620 PIC18F8621 PIC18F8622 PIC18F8627 PIC18F8628 PIC18F8680 PIC18F8720 PIC18F8722 PIC18F8723 PIC18LF6520 PIC18LF8520 PIC18F24J10 PIC18F24J11 PIC18F24J50 PIC18F25J10 PIC18F25J11 PIC18F25J50 PIC18F26J11 PIC18F26J50 PIC18F44J10 PIC18F44J11 PIC18F44J50 PIC18F45J10 PIC18F45J11 PIC18F45J50 PIC18F46J11 PIC18F46J50 PIC18F63J11 PIC18F63J90 PIC18F64J11 PIC18F64J90 PIC18F65J10 PIC18F65J11 PIC18F65J15 PIC18F65J50 PIC18F65J90 PIC18F66J10 PIC18F66J11 PIC18F66J15 PIC18F66J16 PIC18F66J50 PIC18F66J55 PIC18F66J60 PIC18F66J65 PIC18F66J90 PIC18F67J10 PIC18F67J11 PIC18F67J50 PIC18F67J60 PIC18F67J90 PIC18F83J11 PIC18F83J90 PIC18F84J11 PIC18F84J90 PIC18F85J10 PIC18F85J11 PIC18F85J15 PIC18F85J50 PIC18F85J90 PIC18F86J10 PIC18F86J11 PIC18F86J15 PIC18F86J16 PIC18F86J50 PIC18F86J55 PIC18F86J60 PIC18F86J65 PIC18F86J90 PIC18F87J10 PIC18F87J11 PIC18F87J50 PIC18F87J60 PIC18F87J90 PIC18F96J60 PIC18F96J65 PIC18F97J60 PIC18LF24J10 PIC18LF24J11 PIC18LF24J50 PIC18LF25J10 PIC18LF25J11 PIC18LF25J50 PIC18LF26J11 PIC18LF26J50 PIC18LF44J10 PIC18LF44J11 PIC18LF44J50 PIC18LF45J10 PIC18LF45J11 PIC18LF45J50 PIC18LF46J11 PIC18LF46J50 PIC18F13K22 PIC18F13K50 PIC18F14K22 PIC18F14K50 PIC18F14K50 PIC18F23K20 PIC18F24K20 PIC18F25K20 PIC18F26K20 PIC18F43K20 PIC18F44K20 PIC18F45K20 PIC18F46K20 PIC18LF13K22 PIC18LF13K50 PIC18LF14K22 PIC18LF14K50 PIC18LF14K50 PIC24FJ16GA002 PIC24FJ16GA004 PIC24FJ32GA002 PIC24FJ32GA004 PIC24FJ48GA002 PIC24FJ48GA004 PIC24FJ64GA002 PIC24FJ64GA004 PIC24FJ64GA006 PIC24FJ64GA008 PIC24FJ64GA010 PIC24FJ64GB106 PIC24FJ64GB108 PIC24FJ64GB110 PIC24FJ96GA006 PIC24FJ96GA008 PIC24FJ96GA010 PIC24FJ128GA006 PIC24FJ128GA008 PIC24FJ128GA010 PIC24FJ128GA106 PIC24FJ128GA108 PIC24FJ128GA110 PIC24FJ128GB106 PIC24FJ128GB108 PIC24FJ128GB110 PIC24FJ192GA106 PIC24FJ192GA108 PIC24FJ192GA110 PIC24FJ192GB106 PIC24FJ192GB108 PIC24FJ192GB110 PIC24FJ256GA106 PIC24FJ256GA108 PIC24FJ256GA110 PIC24FJ256GB106 PIC24FJ256GB108 PIC24FJ256GB110 PIC24HJ12GP201 PIC24HJ12GP202 PIC24HJ16GP304 PIC24HJ32GP202 PIC24HJ32GP204 PIC24HJ32GP302 PIC24HJ32GP304 PIC24HJ64GP202 PIC24HJ64GP204 PIC24HJ64GP206 PIC24HJ64GP210 PIC24HJ64GP502 PIC24HJ64GP504 PIC24HJ64GP506 PIC24HJ64GP510 PIC24HJ128GP202 PIC24HJ128GP204 PIC24HJ128GP206 PIC24HJ128GP210 PIC24HJ128GP306 PIC24HJ128GP310 PIC24HJ128GP502 PIC24HJ128GP504 PIC24HJ128GP506 PIC24HJ128GP510 PIC24HJ256GP206 PIC24HJ256GP210 PIC24HJ256GP610 DSPIC33FJ06GS101 DSPIC33FJ06GS102 DSPIC33FJ06GS202 DSPIC33FJ12GP201 DSPIC33FJ12GP202 DSPIC33FJ12MC201 DSPIC33FJ12MC202 DSPIC33FJ16GP304 DSPIC33FJ16GS402 DSPIC33FJ16GS404 DSPIC33FJ16GS502 DSPIC33FJ16GS504 DSPIC33FJ16MC304 DSPIC33FJ32GP202 DSPIC33FJ32GP204 DSPIC33FJ32GP302 DSPIC33FJ32GP304 DSPIC33FJ32MC202 DSPIC33FJ32MC204 DSPIC33FJ32MC302 DSPIC33FJ32MC304 DSPIC33FJ64GP202 DSPIC33FJ64GP204 DSPIC33FJ64GP206 DSPIC33FJ64GP306 DSPIC33FJ64GP310 DSPIC33FJ64GP706 DSPIC33FJ64GP708 DSPIC33FJ64GP710 DSPIC33FJ64GP802 DSPIC33FJ64GP804 DSPIC33FJ64MC202 DSPIC33FJ64MC204 DSPIC33FJ64MC506 DSPIC33FJ64MC508 DSPIC33FJ64MC510 DSPIC33FJ64MC706 DSPIC33FJ64MC710 DSPIC33FJ64MC802 DSPIC33FJ64MC804 DSPIC33FJ128GP202 DSPIC33FJ128GP204 DSPIC33FJ128GP206 DSPIC33FJ128GP306 DSPIC33FJ128GP310 DSPIC33FJ128GP706 DSPIC33FJ128GP708 DSPIC33FJ128GP710 DSPIC33FJ128GP802 DSPIC33FJ128GP804 DSPIC33FJ128MC202 DSPIC33FJ128MC204 DSPIC33FJ128MC506 DSPIC33FJ128MC510 DSPIC33FJ128MC706 DSPIC33FJ128MC708 DSPIC33FJ128MC710 DSPIC33FJ128MC802 DSPIC33FJ128MC804 DSPIC33FJ256GP506 DSPIC33FJ256GP510 DSPIC33FJ256GP710 DSPIC33FJ256MC510 DSPIC33FJ256MC710 DSPIC30F2010 DSPIC30F2011 DSPIC30F2012 DSPIC30F3010 DSPIC30F3011 DSPIC30F3012 DSPIC30F3013 DSPIC30F3014 DSPIC30F4011 DSPIC30F4012 DSPIC30F4013 DSPIC30F5011 DSPIC30F5013 DSPIC30F5015 DSPIC30F5016 DSPIC30F6010A DSPIC30F6011A DSPIC30F6012A DSPIC30F6013A DSPIC30F6014A DSPIC30F6015 DSPIC30F1010 DSPIC30F2020 DSPIC30F2023 PIC32MX320F032H PIC32MX320F064H PIC32MX320F128H PIC32MX320F128L PIC32MX340F128H PIC32MX340F128L PIC32MX340F256H PIC32MX360F256L PIC32MX360F512L PIC32MX420F032H PIC32MX440F128H PIC32MX440F128L PIC32MX440F256H PIC32MX440F512H PIC32MX460F256L PIC32MX460F512L HCS200 HCS201 HCS300 HCS301 HCS320 HCS360 HCS361 HCS362 11LC010 11LC020 11LC040 11LC080 11LC160 24LC00 24LC01B 24LC02B 24LC04B 24LC08B 24LC16B 24LC32A 24LC64 24LC128 24LC256 24LC512 24LC1025 25LC010A 25LC020A 25LC040A 25LC080A 25LC080B 25LC128 25LC160A 25LC160B 25LC256 25LC320A 25LC512 25LC640A 25LC1024 93LC46A 93LC56A 93LC66A 93LC76A 93LC86A 93LC46B 93LC56B 93LC66B 93LC76B 93LC86B MCP25020 MCP25025 MCP25050 MCP25055

Version 1.61

Additional support for:

PIC24F04KA200 PIC24F04KA201 PIC24F08KA101 PIC24F08KA102 PIC24F16KA101 PIC24F16KA102 PIC24FJ32GA102 PIC24FJ32GA104 PIC24FJ32GB002 PIC24FJ32GB004 PIC24FJ64GA102 PIC24FJ64GA104 PIC24FJ64GB002 PIC24FJ64GB004 PIC32MX340F512H

Version 1.62.14

Additional support for:

PIC12F617 PIC12F752 PIC12HV752 PIC10F320 PIC10F322 PIC10LF320 PIC10LF322 PIC12F1822 PIC12F1840 PIC12LF1822 PIC12LF1840 PIC16F707 PIC16F720 PIC16F721 PIC16F722A PIC16F723A PIC16F1503 PIC16F1507 PIC16F1508 PIC16F1509 PIC16F1516 PIC16F1517 PIC16F1518 PIC16F1519 PIC16F1526 PIC16F1527 PIC16F1782 PIC16F1783 PIC16F1823 PIC16F1824 PIC16F1825 PIC16F1826 PIC16F1827 PIC16F1828 PIC16F1829 PIC16F1847 PIC16F1946 PIC16F1947 PIC16LF707 PIC16LF720 PIC16LF721 PIC16LF722A PIC16LF723A PIC16LF1503 PIC16LF1507 PIC16LF1508 PIC16LF1509 PIC16LF1516 PIC16LF1517 PIC16LF1518 PIC16LF1519 PIC16LF1526 PIC16LF1527 PIC16LF1782 PIC16LF1783 PIC16LF1823 PIC16LF1824 PIC16LF1825 PIC16LF1826 PIC16LF1827 PIC16LF1828 PIC16LF1829 PIC16LF1847 PIC16LF1902 PIC16LF1903 PIC16LF1904 PIC16LF1906 PIC16LF1907 PIC16LF1946 PIC16LF1947 PIC18F23K22 PIC18F24K22 PIC18F25K22 PIC18F26K22 PIC18F26K80 PIC18F43K22 PIC18F44K22 PIC18F45K22 PIC18F46K22 PIC18LF23K22 PIC18LF24K22 PIC18LF25K22 PIC18LF26K22 PIC18LF43K22 PIC18LF44K22 PIC18LF45K22 PIC18LF46K22 PIC33FJ256GP506A PIC33FJ256GP510A PIC33FJ256GP710A

Version 1.63.148

Additional support for:

PIC16F527 PIC16C83 PIC16C84 PIC16F83 PIC16F84 PIC12F1501 PIC12LF1501 PIC16F1784 PIC16F1786 PIC16F1787 PIC16LF1784 PIC16LF1786 PIC16LF1787 PIC16F1454 PIC16F1455 PIC16F1459 PIC16LF1454 PIC16LF1455 PIC16LF1459 PIC18F26J13 PIC18F26J53 PIC18F27J13 PIC18F27J53 PIC18F46J13 PIC18F46J53 PIC18F47J13 PIC18F47J53 PIC18LF26J13 PIC18LF26J53 PIC18LF27J13 PIC18LF27J53 PIC18LF46J13 PIC18LF46J53 PIC18LF47J13 PIC18LF47J53 PIC18F24K50 PIC18F25K50 PIC18F45K50 PIC18F46K50 PIC18LF24K50 PIC18LF25K50 PIC18LF26K50 PIC18LF45K50 PIC18LF46K50 PIC18F25K80 PIC18F26K80 PIC18F45K80 PIC18F46K80 PIC18F65K80 PIC18F66K80 PIC18LF25K80 PIC18LF26K80 PIC18LF45K80 PIC18LF46K80 PIC18LF65K80 PIC18LF66K80 PIC33FJ64GS608