Sunday, April 27, 2008

pk2cmd Linux Port under Fedora Core 6

Here is a mini-howto to get pk2cmd Linux port to work under Fedora Core 6. It should work for Fedora Core 5 and Fedora 7 as well. Hopefully it also works for Fedora 8. I have never used Fedora 8 since it failed to boot on my machine because of the conflict with FreeBSD.
http://mcuee.blogspot.com/2007/11/new-fc8-install-hangs-at-message.html

1) Download pk2cmdLinux from Jeff Post's website.
Download link: http://home.pacbell.net/theposts/picmicro/

Edit in 09/2009: new download link
http://www.microchip.com/pickit2

As of this writing, the version is 0.8.

2) Preparation to get pk2cmd working is easy under FC6.

You need to have g++ and make. You also need to install libusb-devel package. You can use yum (yum install libusb-devel) as root to install this package.

3) Edit the Makefile and then build it using make.

You need to edit the Makefile to to define the proper CFLAGs.
FC6 is usingLinux kernel 2.6.x and support udev rules. So we will use the following option.

# ----- Use the following for Linux kernel 2.6.x: -----
CFLAGS=$(OPTS) -I$(LIBUSB)/include -DLINUX -DUSE_DETACH -DCLAIM_USB

Now we can build pk2cmdLinux. Just type "make".

4) Test it as root and it should just work.

5) In order to run pk2cmdLinux as a normal user, we need to set up udev rules.

FC6 uses udev with PAM. You can read the file 'usbhotplug.txt'bundled with the pk2cmdLinux source package for more details. A more up-to-date document is presented in the Gphto project website:
http://www.gphoto.org/doc/manual/permissions-usb.html

Firstly you need to create the file/etc/udev/rules.d/26-microchip.rules with thefollowing content.

#PICKit2SUBSYSTEM=="usb_device", ACTION=="add", SYSFS{idVendor}=="04d8",SYSFS{idProduct}=="0033", SYMLINK+="pickit2-%k"

Secondly, you need to create the file/etc/security/console.perms.d/pickit2.perms
with thefollowing content:

=/dev/pickit2* 0600 0600 root

6) After this unplug and then plug PICkit 2 back in the USB port andit should work.
If not, reboot the machine.

Now we can test pk2cmdLinux under FC6. Here are some examples.

[mcuee@localhost pk2cmdLinux-0.8]$ ./pk2cmd -?V
Executable Version: 1.01.00 (Linux/Mac port 0.8)
Device File Version: 1.42.00OS
Firmware Version: 2.30.01
Operation Succeeded

[mcuee@localhost pk2cmdLinux-0.8]$ ./pk2cmd -PPIC16F690 -I
Device ID = 1403
Operation Succeeded

[mcuee@localhost pk2cmdLinux-0.8]$ ./pk2cmd -PPIC16F690 -GFlowpindemo.hex
Read successfully.
Operation Succeeded

[mcuee@localhost pk2cmdLinux-0.8]$ ./pk2cmd -PPIC16F690 -Y -Flowpindemo.hex
PICkit 2 Verify Report
27-4-2008, 11:49:37
Device Type: PIC16F690
Verify Succeeded.
Operation Succeeded

[mcuee@localhost pk2cmdLinux-0.8]$ ./pk2cmd -PPIC16F690 -T
Operation Succeeded

No comments: