Tutorials

Setting up pk2cmd on Ubuntu

Last updated: Dec. 5, 2009, 9:32 p.m.

The trickiest part of getting Dwarf installed and working, I think, is installing the pk2cmd program, and configuring permissions for the PICKit2 Programmer. This tutorial runs through exactly how I do it on an Ubuntu system, but it should be applicable to most modern Linux distros as there are no Ubuntu specific tools involved here.

DISCLAIMER: This stuff involves altering system files and settings. I am not responsible for things going wrong on your system even if you're following this guide.

1. Get the tarball

The pk2cmd program is available from Microchip's website on the PICKit 2 page, you can find the link near the bottom of the page in the downloads, you almost certainly want the PK2CMD V... Linux Kernel 2.6 Executable Binary version, so if you're not sure get this one. (Unless your using a Mac of course, but I've not tried Dwarf on a Mac so your on your own.)

Note: In the readme it suggests getting the source tar and compiling it yourself. To do this you need to unzip the tar archive and run "make linux", then "sudo make install". To do this though you need to have a compiler and development libraries installed so I haven't suggested this method here.

2. Open the tar and copy the binaries

Open a terminal and go to the directory you saved the tar to, extract the tar with the command:

tar -zxvf pk2cmdv1-20Linux2-6.tar.gz (Note you may need to change the version number if newer releases are made.)

Change to the newly created directory:

cd pk2cmdv1-20Linux2-6

If you want details on the command take a look at the readme, it is very thorough. The install bit is chapter 7 if you're interested. Next, as root (use sudo on Ubuntu, you may want to use su on other distros) you need to copy the executable to /usr/local/bin:

chmod 0755 pk2cmd sudo cp pk2cmd /usr/local/bin/

The first command is needed because the default permissions in the download do not allow anyone other than the owner to execute the program, and once it's in the system folder that's only root.

Then the PK2DeviceFile.dat to /usr/share/pk2, note that you first need to make the folder:

chmod 0644 PK2DeviceFile.dat sudo mkdir /usr/share/pk2 sudo cp PK2DeviceFile.dat /usr/share/pk2/

(Again we had to change the permissions here so that you can read the file without being root once it's been copied.)

This new folder needs to be added to your PATH variable, so open the file called ".bashrc" in your home directory in a text editor (note because it starts with a "." on Linux it is a hidden file so you may need to enable viewing hidden files or on the command line use nano editor etc.) At the end of the file add:

export PATH=$PATH:/usr/share/pk2

It's good practice to make sure there's a blank line at the end of the file, then save it.

3. Setup permissions That's the program installed, but the tricky bit is setting up the USB device permissions so that you can use pk2cmd (and hence Dwarf) without using sudo. To do this you need to tell the system that its safe to let users (or a certain group of users) to write to this device directly. To do this, copy the file 70-microchip.rules that is attached to this article into /etc/udev/rules.d/ on your computer, then run the two commands:

sudo groupadd microchip sudo usermod -aG microchip your_user_name

Replacing your_user_name with your login name e.g. : sudo usermod -aG microchip nathan

The file you copied contains a rule telling the system to allow read and write access to a USB device with the specific device ID of the PICKit 2 programmer to members of the group microchip. The two commands then make this group, and add your user to it.

Before this takes effect though you need to log out and in again, and restart udev. The easiest way to do all this is just to reboot.

Section:
Tutorials
Tags:
linux,
USB,
PicKit2,
udev

Comments

Thanks, and "help" ! :)

28 Mar 2010 - 15:53 Andre

I followed your instructions, when executed as sudo , it works, but as user:
$ pk2cmd
bash: /usr/local/bin/pk2cmd: Permission denied

- pikdev cannot work properly as long this needs sudo
(Ubuntu 10.04)

Regards
André

Chmod most important

23 May 2010 - 23:16 nathan

Hi André,

Did you do the chmod 0755 pk2cmd line ?

If not you'll need to do sudo chmod 0755 /usr/local/bin/pk2cmd

Hope that helps.

Nathan

GUI for pk2cmd

16 Feb 2013 - 11:08 frankynov

Thank you for this post :)

I've designed a custom GUI for pk2cmd for both Linux and OSX.
You can check it out on microchip's forum :)
http://www.microchip.com/forums/m705796.aspx

Posting comments is not currently possible. If you want to discuss this article you can reach me on twitter or via email.


Contact

Email: nathan@nathandumont.com

Twitter: @hairymnstr

Links