Showing posts with label PICKit. Show all posts
Showing posts with label PICKit. Show all posts

Sunday, February 21, 2010

FreeBSD 8.0 First Impression

Now I used FreeBSD 8.0-Release (updated to 8.0-RELEASE-p2) and it seems to be much better than last time, especially in the USB front. I also like the freebsd-update capability. It seems to be faster than last time.

What I like compare to Linux: maybe the BSD license itself. But now I feel GPL/LGPL are not bad either.

What is not working: my SATA DVD-RW is not recognized at all. This is an Acer M1641 desktop with NVidia 620i/Geforce 7050 based chipset and FreeBSD seems to have big problems with NForce 620i and 630i.

What I do not like: the port system. I have since removed most of the packages initially installed (LXDE, KDE3, KDE 4, QT33, QT4, etc) due to the mass upgrade of libjpeg. It caused big problems to many packages. So now I have a bare-minimum Gnome 2.26 based desktop (dare not update to 2.28). Mass upgrade takes a long time and often the ports are broken. ARCH seems to do a much better job since binary updates are provided. I still like Ubuntu's package system (deb/apt, Synaptic) the best.

My libusb testing on FreeBSD: pk2cmd seems to behave like last time, but now I do not need to recompile the kernel. libusb based programs work better but there are still problems.
http://old.nabble.com/LibUSB-on-FreeBSD--current-%288.x%29-td21642051.html

My OpenOCD test on FreeBSD: FT2232D seems to work, J-Link V3 does not work. J-Link V7 seems to work. All of them works under Linux.
https://lists.berlios.de/pipermail/openocd-development/2010-February/014864.html

My main interests with FreeBSD will be more libusb/MCU related -- to get OpenOCD (J-Link and FTDI, for ARM MCU development) and PICkit 2 (and other PIC related things, for PIC development) to work well under FreeBSD. Now it seems that FreeBSD is an possible platform for MCU development.

Monday, February 15, 2010

FreeBSD 8.0 Installed

After about 1.5 years gap with FreeBSDs, yesterday I finally got FreeBSD 8.0 Release version installed. My main interests are to get some libusb based programs to work under FreeBSD, including the USB demos from Microchip, pk2cmd for PICkit 2.

The installation itself is not flawless. Initially I tried with ACPI disabled (last time it helped) but this resulted in General Protection Fault on this Acer M1641 PC (Nvidia 620i/Geforce 7050 integrated chipset). With ACPI enabled, the install CD can boot up. But the installed could not find the SATA DVD-RW. Luckily the network card was recognized. So I used network install and it was not too bad, faster than I expected. I then spent some time to get Nvidia driver port to work. I have to disable the Linux emulation support in nvidia-driver since I could not download the large Linux emulation base packages (linux_base-f10) due to dead mirrors.

There are some other minor things to fix up, like I need to mount procfs to /proc (edit /etc/fstab) to get the gdm login screen to be able to properly shutdown/reboot the PC.

I tried a few simple programs based on libusb 0.1 and they seem to work fine under FreeBSD 8.0 release. Last time I had to patch the kernel and use the then alternative USB stack from Hans Petter Selasky (FreeBSD USB developer).

Then I tried to build pk2cmd and it seemed to work. The "-s" option does not see to work just as the release note of pk2cmd 1.20 says. I have not tried updating the firmware which was not working last time I tried it.

libusb 1.0 API has not fully been synced by the FreeBSD /usr/include/libusb.h. Luckily Hans says that he will make the libusb 1.0 compatible layer available to FreeBSD.

USB permision setup is now much easier than last time. By default, it seems USB device will have a ugen driver associated. The /dev/ugen* device belong to the operator group. So it is quite easy to add the user to the operator group and then the user can run libusb based program without root privilege.

I had problems to build OpenOCD git code, luckily Tomek Cedro provided a port so that I could build OpenOCD 0.4.0-rc2. I had to update the port system to build libftdi 0.17. This seems to be a prerequisite for OpenOCD.

Overall this time I have more positive views about FreeBSD. It is not as smooth as Ubuntu, but at least it is quite usable.

$ uname -a
FreeBSD MyFreeBSD.WORKGROUP 8.0-RELEASE-p2 FreeBSD 8.0-RELEASE-p2 #0: Tue Jan 5 16:02:27 UTC 2010 root@i386-builder.daemonology.net:/usr/obj/usr/src/sys/GENERIC i386

[mcuee@MyFreeBSD /usr/home/mcuee/Desktop/build/pk2cmd/pk2cmdv1.20LinuxMacSource]$ ./pk2cmd -?V

Executable Version: 1.20.00
Device File Version: 1.55.00
OS Firmware Version: 2.32.00

Operation Succeeded

Friday, April 17, 2009

PICkit 2 under Arch Linux with pk2cmd

Now that Microchip released pk2cmd source codes for Windows, Linux and Mac OS X, things become very easy to get PICkit 2 to work under Linux. I just tried it under Arch Linux and it works very well.

Source code download: http://www.microchip.com/pickit2 (now it is of version V1.20)

It is recommended that you build the binary by yourself since the released binary may not work for certain Linux distributions. You need to have gcc and libusb installed to build the source. Just type "make linux" and you will get the binary. For me I prefer to copy pk2cmd and PK2DeviceFile.dat to my ~/bin directory. You can also put them to places like /usr/local/bin.

In order to run pk2cmd as normal user, then you need to write the udev rules as following. You can use the following page. I've added the section for Arch Linux.
http://piklab.wiki.sourceforge.net/USB+Port+Problems

[mcuee@myhost rules.d]$ cd
[mcuee@myhost ~]$ cat /etc/udev/rules.d/26-microchip.rules
#PICKit 1
ATTR{idVendor}=="04d8", ATTR{idProduct}=="0032", OWNER:="root", GROUP:="microchip",MODE:="0660"
#PICKit 2
ATTR{idVendor}=="04d8", ATTR{idProduct}=="0033", OWNER:="root", GROUP:="microchip",MODE:="0660"
#ICD2
ATTR{idVendor}=="04d8", ATTR{idProduct}=="8000", OWNER:="root", GROUP:="microchip",MODE:="0660"
#ICD21
ATTR{idVendor}=="04d8", ATTR{idProduct}=="8001", OWNER:="root", GROUP:="microchip",MODE:="0660"
#PICDEM FS USB Bootloader
ATTR{idVendor}=="04d8", ATTR{idProduct}=="000b", OWNER:="root", GROUP:="microchip",MODE:="0660"

[mcuee@myhost ~]$ groups mcuee
lp wheel network video audio optical storage hal camera fuse microchip users

[mcuee@myhost ~]$ pk2cmd -PPIC16F690 -I
Device ID = 1400
Revision = 0003
Device Name = PIC16F690

Operation Succeeded

Friday, August 1, 2008

Two Trivial Patches now in Linux Kernel 2.6.26

I am not a Linux kernel hacker, actually I am not even a programmer.
But I've got two trivial patches about USB PICs in Linux kernel 2.6.26.
So it seems we can help the open source community no matter how minor
the contributions are.

http://www.kernel.org/pub/linux/kernel/v2.6/ChangeLog-2.6.26
********************************************************
commit 5fc89390f74ac42165db477793fb30f6a200e79c
Author: Xiaofan Chen
Date: Tue May 13 21:52:00 2008 +0800

USB: remove PICDEM FS USB demo (04d8:000c) device from ldusb

Microchip has changed the PICDEM FS USB demo device (0x04d8:000c)
to use bulk transfer and not interrupt transfer. So I've updated the
libusb based program here (Post #31).
http://forum.microchip.com/tm.aspx?m=106426&mpage=2

So I believe that the in-kernel ldusb driver will no longer work with the
demo firmware. It should be removed.


Signed-off-by: Xiaofan Chen
Cc: Michael Hund
Cc: stable
Signed-off-by: Greg Kroah-Hartman
********************************************************

********************************************************
commit f4971031f4acd98423a2903c6517fb3ef1aea8dc
Author: Xiaofan Chen
Date: Tue May 13 17:11:59 2008 +0200

HID: add Microchip PICKit 1 and PICkit 2 to blacklist

Microchip PICkit 1 and PICKit 2 USB Programmers are USB HID class of device but
they are not real HID device. They are now supported by libusb based programs
like the following programs.

pk2 and pk2cmd Linux port:
http://home.pacbell.net/theposts/picmicro/
usb_pickit:
http://tfc.duke.free.fr/pickit.html
usb_pickit original version:
http://charm.cs.uiuc.edu/users/olawlor/projects/2003/microchip/

Therefore it is preferred to blacklist them.

Signed-off-by: Xiaofan Chen
Signed-off-by: Jiri Kosina
********************************************************

Reference:
http://www.ohloh.net/p/linux/contributors/13492639826017

Wednesday, July 2, 2008

Cross-platform pk2cmd 1.10 released

Microchip has released a cross-platform version of pk2cmd
V1.10. It works under Windows, Mac OS X and Linux. It is
also partially working under FreeBSD. I am proud to
have contributed the development by providing some ideas
and carry out quite some testing under Linux and FreeBSD.


Announcement:
http://forum.microchip.com/tm.aspx?m=349078

Download:
http://www.microchip.com/pickit2

My blog has quite some articles about pk2cmd under
Linux and FreeBSD.
http://mcuee.blogspot.com/search/label/PICKit

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

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

Thursday, April 24, 2008

pk2cmd Linux port under Ubuntu

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

Download link:
http://home.pacbell.net/theposts/picmicro/

As of this writing, the version is 0.8. I've tested the following under Ubuntu 6.06 and 7.10. It should work for 7.04 as well. For Ubuntu 5.04 and maybe 5.10, you should use hotplug rules instead of udev rules. But I no longer use these older versions.

How to build it from the downloaded source? You need to have gcc, g++, make (sudo apt-get install build-essential) and libusb-dev (sudo apt-get install libusb-dev).

You will also need to edit the Makefile and choose the following option.
# ----- Use the following for Linux kernel 2.6.x: -----
CFLAGS=$(OPTS) -I$(LIBUSB)/include -DLINUX -DUSE_DETACH -DCLAIM_USB

After that, just type "make" and you should have pk2cmd Linux port built.

You will need to set up proper udev rules to run pk2cmd as a normal user and not using sudo.

More detailed steps.
1) Create a group called microchip, add your user name to it.
GUI method: System --> Administration --> Users and Groups -->
Manage Groups --> Add Group
Group name : microchip
Group member: add your user name (mine is "mcuee").

To confirm that this is a success.
mcuee@ubuntu710:~$ groups mcuee
mcuee : mcuee adm dialout cdrom floppy audio dip video plugdev scanner
lpadmin admin netdev powerdev microchip

Take note that the output has "microchip" in it.

The command line way of doing this.
mcuee@ubuntu710:~$ sudo groupadd microchip
mcuee@ubuntu710:~$ sudo gpasswd -a mcuee microchip
(Replace mcuee with your username linuxdev).
mcuee@ubuntu710:~$ groups mcuee
mcuee : mcuee adm dialout cdrom floppy audio dip video plugdev scanner lpadmin admin netdev powerdev microchip

2) Create the udev rule 026_microchip.rules in the directory
/etc/udev/rules.d. You can use gedit.
mcuee@ubuntu710:~$ sudo gedit /etc/udev/rules.d/026_microchip.rules
Here is my udev rules for PICKit 2 and some other Microchip USB tools.

Edit: please follow Peter Restall's comments and use ATTRS{} instead of SYSFS{}. SYSFS{} is deprecated in later version of udev.

mcuee@ubuntu710:/etc/udev/rules.d$ cat 026_microchip.rules
#PICKit 1
SYSFS{idVendor}=="04d8", SYSFS{idProduct}=="0032", MODE="0660",
GROUP="microchip"
#PICKit 2
SYSFS{idVendor}=="04d8", SYSFS{idProduct}=="0033", MODE="0660",
GROUP="microchip"

#ICD2
SYSFS{idVendor}=="04d8", SYSFS{idProduct}=="8000", MODE="0660",
GROUP="microchip"
#ICD21
SYSFS{idVendor}=="04d8", SYSFS{idProduct}=="8001", MODE="0660",
GROUP="microchip"

#PICDEM FS USB Bootload
SYSFS{idVendor}=="04d8", SYSFS{idProduct}=="000b", MODE="0660",
GROUP="microchip"
#PICDEM FS USB Demo
SYSFS{idVendor}=="04d8", SYSFS{idProduct}=="000c", MODE="0660",
GROUP="microchip"
#PICDEM FS USB CDC-ACM
SYSFS{idVendor}=="04d8", SYSFS{idProduct}=="000a", MODE="0660",
GROUP="microchip"

3) Unplug and plug PICkit 2 and check if the udev rules work or not. If not, you may reboot and check again. Actually a better way is to restart udev and then unplug and plug in PICkit 2.

mcuee@ubuntu710:~$ sudo /etc/init.d/udev restart
* Loading additional hardware drivers... [ OK ]

mcuee@ubuntu710:~$ lsusb
Bus 003 Device 001: ID 0000:0000
Bus 002 Device 001: ID 0000:0000
Bus 001 Device 003: ID 04d8:0033 Microchip Technology, Inc.
Bus 001 Device 004: ID 04d8:000c Microchip Technology, Inc.
Bus 001 Device 001: ID 0000:0000

mcuee@ubuntu710:~$ ls -la /dev/bus/usb/001
total 0
drwxr-xr-x 2 root root 100 2008-04-24 15:26 .
drwxr-xr-x 5 root root 100 2008-04-24 15:26 ..
crw-rw-r-- 1 root root 189, 0 2008-04-24 15:26 001
crw-rw-r-- 1 root microchip 189, 2 2008-04-24 15:26 003
crw-rw-r-- 1 root microchip 189, 3 2008-04-24 15:26 004

Now you can see that PICkit 2 is in Bus 001 and it belongs
to root user but group member of microchip have read
and write access to it.

4) now you should be able to run pk2cmd as normal user.
mcuee@ubuntu710:~/Desktop/build/pk2cmd/pk2cmdLinux-0.8$./pk2cmd -PPIC16F690 -I
Device ID = 1403

Operation Succeeded

Friday, January 11, 2008

How to Get Help for Microchip MCU Related Questions

Someone just leaves a comments about asking for PIC related issues through Email. I'd suggest that one tries the following places.

1. Microchip Forum: generic problems with PIC MCUs and associated development tools
http://forum.microchip.com

2. PIClist
http://www.piclist.com

3. For Open Source PIC development tools under Linux or Windows: GNUPIC
http://www.gnupic.org

4. For PICkit 2 under Linux
http://groups.google.com/group/pickit-devel

Saturday, December 22, 2007

NetBSD 4.0 upgrade -- smooth process

I installed NetBSD 3.1 sometime ago. I also used the pkgsrc binary CD to install GNOME so that I had a basic working installation.

One of the annoying 'feature' of NetBSD 3.1 is that it is not compliant to multi-boot so that grub will not be able to pass the kernel parameters to it. Therefore I need to answer several questions before I can boot into NetBSD. Somehow pkg_add did not work well with ftp.netbsd.org.

So now NetBSD 4.0 is just out. So I update the existing installation to it today. It is a very smooth process. More importantly, it is compatible with multiboot and grub has no problem to boot NetBSD 4.0 now. The existing 3.1 binary packages are still working. pkg_add is now working as well with ftp.netbsd.org even though it still prints out some error messages.

Since I have got PICkit 2 to work under FreeBSD (with HPS USB stack), I will try to get it to work under NetBSD. But I have never used NetBSD before, this might take some time.

Saturday, December 8, 2007

USB Programmers for PICs

http://forum.microchip.com/tm.aspx?m=283491

As someone who has used PICKit 1, PICkit 2, ICD2, Promate II and Promate III and a follower of PICkit 2, I find it interesting that people still want to create yet another simple USB programmer.

Anyway, here are my classification of USB PIC programmers. I might miss many programmers in the lists but it pretty much show you the pictures. After class 3, then there are many high end programmers from Data I/O, BP or similar for mass production.

Class 1: Simple USB programmers (not as good as PICkit 2 and USBprog):
1. picsquirt http://www.p10link.net/plugwash/picsquirt/
2. GTP USB lite (somewhat like a USB version of Wouter's WISP628A) http://www.hobbypic.com/index.php?option=com_content&task=view&id=12&Itemid=35

Class 2: Good for personal and lab use
1. PICKit 2, good and cheap, supports many PICs and double as a debugger.
http://www.microchip.com/pickit2

2. Another good USB programmer is the Amadeus.
The author is aparently very knowledgeable about PIC programming specifications. Not many people understand it as thoughly as him. Olin may be one of them. http://home.arcor.de/bernhard.michelis/

3. The author of WinPIC800 software has the GTP USB+ Programmer which seems to be a decent programmer as well.
http://www.winpic800.com/index.php?lang=en

4. USBprog is a kind of higher-end PICkit 2 in terms of hardware functionality. USBprog hits a good spot between PICkit 2 and Promate III but I find its chip support a bit limitted compared to PICKit 2.
http://www.embedinc.com/products/eusb2/index.htm

Class 3: low quantity production quality programmer After class 2 then you have higher-end USB programmers like Promate III and SoftLog ICP2. SoftLog ICP2 seems to be a serious contender to PM3 at much lower cost.

Between USBProg and Promate III, there are still quite some good gaps. SoftLog ICP2 is a good attempt.
https://www.microchipdirect.com/ProductDetails.aspx?Catalog=BuyMicrochip&Category=Programmers&mid=13

Some PICkit 2 Links

PICKit 2 website:
http://www.microchip.com/pickit2

PICkit 2 Faq:
http://forum.microchip.com/tm.aspx?m=270347

PICKit 2 Wishlist:
http://forum.microchip.com/tm.aspx?m=260540

PICkit 2 under Linux, pk2 and pk2cmd Linux port:
http://home.pacbell.net/theposts/picmicro/

PICkit 2 versus ICD2:
http://forum.microchip.com/tm.aspx?m=287314
http://forum.microchip.com/tm.aspx?m=282776

Sunday, November 11, 2007

Setting up permissions for USB ports to use libusb for FreeBSD

During the testing of pk2cmd port for FreeBSD, I found a great resource on setting up permissions for USB ports to use libusb or other programs under Linux/BSD.
http://www.gphoto.org/doc/manual/permissions-usb.html

There is no udev under FreeBSD. It is called devfs rule. To set up proper usb device persimmion so that I can run pk2cmd without being root, I need to do the following.

Steps:
1. Create group "usb" and add the user name to it.
[Added on 22-Dec-2007]
http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/users-groups.html
[mcuee@localhost /usr/home/mcuee]$ su -
Password:
localhost# pw groupadd usb (this may not be necessary for FreeBSD 7.0 Beta)
localhost# pw groupmod usb -M mcuee (your_user_name here, mine is "mcuee")
localhost# pw groupshow usb
usb:*:1003:mcuee

2. Edit /etc/devfs.rules to add the following lines.
[usb_devices=10]
add path 'ugen*' mode 0660 group usb
add path 'da*s*' mode 0660 group usb
3. Edit /etc/devfs.conf and add following lines: [Confirmed that this
is necessary]
perm usb0 0660
own usb0 root:usb
perm usb1 0660
own usb1 root:usb
4. Edit /etc/rc.conf and add the following lines:
# Set the default devfs ruleset.
devfs_system_ruleset="usb
_devices"
5. Activate the changes by running the following command (no reboot required):
localhost# /etc/rc.d/devfs start

6. Testing:
localhost# exit
logout

===[mcuee] ~/Desktop/build/pk2cmd4bsd # ls -la /dev/ugen0*
crw-rw---- 1 root usb 0, 138 Nov 1 22:31 /dev/ugen0
crw-rw---- 1 root usb 0, 120 Nov 1 22:56 /dev/ugen0

[Added on 22-Dec-2007]
===[mcuee] ~/Desktop/build/pk2cmd4bsd # lsusb
Bus /dev/usb1 Device /dev/ugen0: ID 04d8:0033 Microchip Technology, Inc.

===[mcuee] ~/Desktop/build/pk2cmd4bsd # ./pk2cmd -PPIC12F675 -I

Locating USB Microchip PICkit2 (vendor 0x04d8/product 0x0033)
Found USB PICkit as device '/dev/ugen0' on USB bus /dev/usb1
Communication established. PICkit2 firmware version is 2.10.0

Device ID = 0FC3

Operation Succeeded

Thursday, November 1, 2007

PK2CMD Ported to Linux and FreeBSD

PK2CMD is a 32-bit command line interface for the PICkit 2 Programmer. It is available for download from the PICkit 2 webpage: http://www.microchip.com/pickit2 .

Microchip has released the source code here:
http://ww1.microchip.com/downloads/en/DeviceDoc/PICkit2_PK2CMD_SourceV1_00.zip

Jeff Post has since released the Linux port of PK2CMD here:
http://home.pacbell.net/theposts/picmicro/pk2cmdLinux-0.1.tar.gz

Take note that CFLAGS -fpermissive may need to be added to avoid compiling error with later version of g++ (for example: under Ubuntu 7.04/7.10).

It might needs some modification to work under Mac OS X.

I've also tried it under FreeBSD 7.0 Beta. I need to get the alternative USB Stack from Hans Petter Selasky (HPS) to get it work. It should work under other version of FreeBSD which HPS stack supports.

To get the HPS USB stack for FreeBSD, follow the following instruction.

svn --username anonsvn --password anonsvn checkout svn://svn.turbocat.net/i4b
cd i4b/trunk/i4b/FreeBSD.usb
make S=../src package
make install
Follow the "make help" instructions.

One patch required is the file "ugen.c". In the function
"ugen_open_pipe_read()",
find the line "case UE_INTERRUPT:" and then some lines further down you will find:
/* first transfer clears stall */
sce->read_stall = 1; //---> Chaneg this to "0".
Then recompile and install the "ugen" module and/or kernel.

PICkit 2 with FreeBSD (old):
http://lists.freebsd.org/pipermail/freebsd-usb/2007-April/003177.html

PICkit 2 with FreeBSD (new):
http://lists.freebsd.org/pipermail/freebsd-usb/2007-October/004057.html

Sample running session:
===[mcuee] ~/Desktop/build/pk2cmd4bsd # uname -a
FreeBSD FreeBsd.Mshome 7.0-BETA1 FreeBSD 7.0-BETA1 #2: Thu Nov 1
19:56:07 SGT 2007
root@FreeBsd.Mshome:/home/obj/home/src/sys
/USBDEBUG i386
===[mcuee] ~/Desktop/build/pk2cmd4bsd # sudo ./pk2cmd -PPIC12F675 -I

Locating USB Microchip PICkit2 (vendor 0x04d8/product 0x0033)
Found USB PICkit as device '/dev/ugen0' on USB bus /dev/usb1
Communication established. PICkit2 firmware version is 2.10.0

Device ID = 0FC3

Operation Succeeded
===[mcuee] ~/Desktop/build/pk2cmd4bsd # sudo ./pk2cmd -PPIC12F675 -GF12F675.hex

Locating USB Microchip PICkit2 (vendor 0x04d8/product 0x0033)
Found USB PICkit as device '/dev/ugen0' on USB bus /dev/usb1
Communication established. PICkit2 firmware version is 2.10.0

Read successfully.

Operation Succeeded
===[mcuee] ~/Desktop/build/pk2cmd4bsd # sudo ./pk2cmd -PPIC12F675 -Y
-F12F675.hex

Locating USB Microchip PICkit2 (vendor 0x04d8/product 0x0033)
Found USB PICkit as device '/dev/ugen0' on USB bus /dev/usb1
Communication established. PICkit2 firmware version is 2.10.0

PICkit 2 Verify Report
1-11-2007, 20:04:10
Device Type: PIC12F675

Verify Succeeded.

Operation Succeeded

Wednesday, July 11, 2007

PICkit 2 as a USB Learning Tool

1. Brad Minch's Lab 2 HID example using gputils
http://www.curdes.com/gnupic/GnuPic.html

2. PICKit 2 CDC emulation ported from Microchip's PICDEM FS USB
http://forum.microchip.com/tm.aspx?m=267849

3. Mark Rages' PICKit 2 as a SPI Protocol Analyser Hack
http://vivara.net/blog/?p=55
The code is written in SDCC.
http://vivara.net/software/pickit_spi/pickit-spi.tar.gz

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 (http://www.microchip.com/pickit2) 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 (http://ww1.microchip.com/downloads/en/DeviceDoc/PICkit%202%20Readme%20v2-30.txt).

Microchip has kindly published the source codes for PICkit 2 firmware and the standardalone PC application (http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1960).

PICkit 2 works under Linux thanks to the efforts from several developers. The easiest to start with is pk2 from Jeff Post (http://home.pacbell.net/theposts/picmicro/). 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.

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

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: -----
CFLAGS=$(OPTS) -I$(LIBUSB)/include -DLINUX -DUSE_DETACH -DCLAIM_USB

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.
http://piklab.sourceforge.net/wiki/index.php/Port_connection_problems
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 (http://groups.google.com/group/pickit-devel). Take note that you should ask general questions about PICkit 2 in Microchip Forum (http://forum.microchip.com/tt.aspx?forumid=15). 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 (http://forum.microchip.com/tm.aspx?m=245280). Only Step 2 is necessary.

8) How to help out?
From Jeff Post: http://home.pacbell.net/theposts/picmicro/helping.html

Note on 10-April-2009: it is now better to use pk2cmd at Microchip PICkit 2 websites.
http://www.microchip.com/pickit2