Thursday, May 1, 2008

pk2cmd Linux Port under PCLinuxOS 2007

Here is a mini-howto to get pk2cmd Linux port to work under PCLinuxOS 2007.

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 PCLinuxOS 2007.

You need to have g++ (provided by package gcc-c++) and make (provided by package "make"). You also need to install libusb-devel package. You can use Synaptic (GUI) to install these packages and their dependencies. You can also use apt (apt-get 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.
PCLinuxOS 2007 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. PCLinuxOS 2007 has done the udev rules for the users. So it is easier than other Linux distros. The only thing you need to do it to add you user name to the group "usb".

Go to PCLinuxOS Control Center and choose "Add, remove or change users of the system", right
click your user name and choose "Edit" and select "Groups". Check "usb" and you are done.

To confirm this, run "group yourusername".

[mcuee@localhost pk2cmdLinux-0.8]$ groups mcuee
mcuee : mcuee tty lp wheel uucp cdrom usb cdwriter audio video users

[mcuee@localhost pk2cmdLinux-0.8]$ lsusb
Bus 003 Device 001: ID 0000:0000
Bus 002 Device 003: ID 04d8:000c Microchip Technology, Inc.
Bus 002 Device 001: ID 0000:0000
Bus 001 Device 002: ID 04d8:0033 Microchip Technology, Inc.
Bus 001 Device 001: ID 0000:0000

[mcuee@localhost pk2cmdLinux-0.8]$ ls -la /dev/bus/usb/001/
total 0
drwxr-xr-x 2 root root 80 May 1 09:09 ./
drwxr-xr-x 5 root root 100 May 1 2008 ../
crw-rw---- 1 mcuee usb 189, 0 May 1 2008 001
crw-rw---- 1 mcuee root 189, 1 May 1 09:12 002

Now you can run pk2cmd as a normal user.

[mcuee@localhost pk2cmdLinux-0.8]$ ./pk2cmd -?V

Executable Version: 1.01.00 (Linux/Mac port 0.8)
Device File Version: 1.42.00
OS Firmware Version: 2.30.01
Operation Succeeded

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

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

[mcuee@localhost pk2cmdLinux-0.8]$ ./pk2cmd -PPIC16F690 -Y -Fdemo.hex
PICkit 2 Verify Report
1-5-2008, 9:42:03
Device Type: PIC16F690

Verify Succeeded.
Operation Succeeded

3 comments:

Shylock_1 said...

As you can see I am logged in as root on Linux MeeGo OS as follow:
[root@localhost can]# uname -a
Linux localhost.localdomain 2.6.37.6-11.1-adaptation-connext #1 SMP PREEMPT Thu Dec 8 00:42:28 UTC 2011 i686 i686 i386 GNU/Linux
[root@localhost can]# lsusb
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 007: ID 413c:3012 Dell Computer Corp. Optical Wheel Mouse
Bus 002 Device 006: ID 413c:2106 Dell Computer Corp. Dell QuietKey Keyboard
Bus 002 Device 005: ID 1a40:0101 TERMINUS TECHNOLOGY INC. USB-2.0 4-Port HUB
Bus 002 Device 004: ID 04d8:0a30 Microchip Technology, Inc.
Bus 002 Device 003: ID 0403:6001 Future Technology Devices International, Ltd FT232 USB-Serial (UART) IC
Bus 002 Device 002: ID 1a40:0101 TERMINUS TECHNOLOGY INC. USB-2.0 4-Port HUB
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
--------------------------------------
But When I ran following cammand
[root@localhost can]# pk2cmd -?V

Executable Version: 1.20.00
Device File Version: 1.55.00
OS Firmware Version: PICkit 2 not found


Operation Succeeded
[root@localhost can]#

I get above response from pk2cmd utility.
My OS's kernel depict dmesg log as follow:

[ 23.593444] [EMGD] drm_init() returning 0
[ 23.601378] hub 1-0:1.0: unable to enumerate USB device on port 2
[ 23.644532] Inserting over stolen memory.
[ 23.745304] pci 0000:00:02.0: setting latency timer to 64
[ 23.759385] hub 1-0:1.0: unable to enumerate USB device on port 2
[ 23.917382] hub 1-0:1.0: unable to enumerate USB device on port 2
[ 23.927154] Inserting over stolen memory.
[ 23.928332] Inserting over stolen memory.
[ 23.928642] Inserting over stolen memory.
FT232RL
[ 38.168073] usb 2-2.2: Number of endpoints 2
[ 38.168083] usb 2-2.2: Endpoint 1 MaxPacketSize 64
[ 38.168093] usb 2-2.2: Endpoint 2 MaxPacketSize 64
[ 38.168102] usb 2-2.2: Setting MaxPacketSize 64
[ 38.172407] usb 2-2.2: FTDI USB Serial Device converter now attached to ttyUSB0
[ 38.172656] usbcore: registered new interface driver ftdi_sio
[ 38.172667] ftdi_sio: v1.6.0:USB FTDI Serial Converters Driver
[ 41.810943] hda-intel: Invalid position buffer, using LPIB read method instead.
[ 41.811039] hda-intel: IRQ timing workaround is activated for card #0. Suggest a bigger bdl_pos_adj.
[ 41.915159] sta2x11_msp 0000:06:00.7: Interrupt: Receive Overrun Error
[ 41.915177] RX overrun
[ 41.915193] sta2x11_msp 0000:06:00.7: unhandled irq ris: 29a
[ 2236.055473] usb 2-2.3: USB disconnect, address 4
[ 2240.608661] usb 2-2.3: new full speed USB device using ohci_hcd and address 8
[ 2240.718814] usb 2-2.3: New USB device found, idVendor=04d8, idProduct=0a30
[ 2240.718888] usb 2-2.3: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 2240.718945] usb 2-2.3: Product: Microchip CAN BUS Analyzer
[ 2240.718992] usb 2-2.3: Manufacturer: Microchip Technology Inc.

Shylock_1 said...

By the way I am using Microchip's APGDT002 CAN Analyser with PIC18F2550 and PIC18F2680.
Related to my previous mail.

Xiaofan said...

pk2cmd is only for PICkit 2, a different product than yours.