Sunday, December 30, 2007

PICDEM FS USB Demo Board under Linux

PICDEM FS-USB demo board is the demonstration and evaluation board for the PIC18F4550 family of Flash microcontrollers with full speed USB 2.0 interface

Back in 2005, people have developed application based on libusb to get it work under Linux. I have since patched them to work under Windows as well using libusb-win32.

Bootloader under Linux:
My latest patches:

Demo mode which includes my patches for libusb-win32:
My latest patches to detach kernel ldusb driver for later Linux kernels.

Interesting discussion about the ldusb driver issue.
Thread: [PATCH 70/78] USB: add picdem device to ldusb:

To me I think it is better to do this in user space using libusb. But the original submitter wants to keep it as he did not know the existence of the libusb based application and has already an in-house application based on the kernel driver.

CDC-ACM demo works fine under Linux. The HID mouse demo also works fine under Linux.

Interestingly, again someone wants to add the bootloader to the kernel. Hopefully this time it will not be included. The libusb based application should still work but why adding so many things to the kernel space when the user space libusb based application works fine.

One FAQ is how to run the libusb based application as a normal user (without root credential). This is a moving target under Linux. Hotplug, udev, udev with PAM and HAL rules are the methods to achieve the goal. You need to choose the right one for the Linux distro you are using.

The following is a good summary.

An older document which does not cover HAL:

Some examples (not really for PICDEM FS-USB but for PICkit 1/2 and ICD2) you can use as the starting point:

Saturday, December 29, 2007

Windows Vista First Impression

Windows Vista has been out for 1 year and many reviews on the Internet is still negative. XP is quite decent now that it has been in the market for quite some time. XP SP2 is pretty stable to use and many companies has not deployed Vista. Still most of the consumers are buying new PCs and most of them come with Vista bundled.

I just started playing with the Vista notebook bought 4 days ago. It is not bad, I will say. As the first step, I removed the two trial version software (Office 2007 and Norton). For antivirus, I installed AVG Free. For spyware detection, Vista comes with Windows Defender installed. With some education done, my wife is now a careful enough Windows user. I've used IE7 in my desktop so I have no problems with IE7 under Vista. Still I installed Firefox as an alternative. IE7 seems to be faster with Windows Live Hotmail.

I think 4GB of RAM helps so that I do not feel Vista is slow. My desktop is a 3 year old AMD64 single core with 1GB RAM running Linux/FreeBSD/Windows XP. So this notebook should not be slower anyway.

I do not like those eye candies so the sidebar feature is not so useful. My wife may like it. As for specially effect of Aero, I do not think it is any useful so that I have not tried it. Anyway, I do not like Compiz under Linux and always switched it off.

UAC is kind of annoying but I decided to leave it on as this will be used by my wife. I am just preparing the notebooks for her and getting familiar with Vista so that I can be he IT support helpdesk. Unfortunately the fine control of UAC options is not available for the Home Premium version of Vista.

Hardware compatibility is still a problem. My wife's Nokia 6280 Mobile Phone works (on the other hand, it did not work under my Linux Desktop. It originally did not work under XP with the same Desktop either but with the updated software it now works under XP). Her beloved Samsung SPP-2020 Photo Printer does not work even though Samsung claims Vista support in their website. I am still investigating this issue. Hopefully I can solve this issue with new software from Samsung or Vista SP1 (now under testing).

Edit: 10 minutes after I posted the blog, I found the solution. It work after deleting C:\windows\inf\INFCACHE.1 and reinstall the printer driver, it works now. It seems to be a common problem.

My newly bought cheap S$75 Orient MP4 player 2GB (looks like IPod Nano, MP3 sound quality is okay, but FM is pretty bad, anyway, I have my trusted Sony Radio.) failed to work (it works under XP and Linux by appearing as a USB storage device). Anyway, I think that is mainly a firmware fault. There are so may buggy USB device out there.

Edit: This again works now after getting SPP-2020 to work.

As this notebook is not intended for my use, I will not install development tools like MPLAB on the computer. Anyway, MPLAB and many other Microchip development tools are now supported under Vista 32bit.

Overall the first impression of Vista is that it seems to be okay. There is nothing too exciting but nothing too disappointed. Anyway, it is not that bad as reported.

New Vista Notebook

On Christmas day, we bought a notebook with Vista Home Premium. It is Compaq Presario V3619AU (GX855PA) with RAM upgraded to 4GB from 1GB as the promotion. It costs S$1299 for the base 1 year warantee option. Since I did not trust the quality of any notebook vendors due to my bad experience with Dell Inspiron 600M I bought back in 2003 (1st year HDD and motherboard gone but luckily under warantee. Now keyboard controller is bad so I have to put an external USB keyboard), I opted to upgrade to have 3 year warantee which cost another S$199. So alltogether it is S$1498.


Product Name: Compaq Presario V3619AU
Product Number: GX855PA
Microprocessor: 1.90 AMD Turion 64 X2 Dual-Core Mobile Technology TL-58
Microprocessor Cache: 512 KB + 512 KB L2 Cache
Memory: 1024 MB (2 x 512 MB) (now upgraded to 4GB)
Memory Max: Up to 4 GB
Video Graphics: NVIDIA GeForce Go 7150M
Video Memory: Up to 287 MB (not seem to correct now that it has 4GB RAM)
Hard Drive: 160 GB (5400 rpm)
Multimedia Drive: LightScribe SuperMulti 8X DVD±RW with Double Layer Support
Display: 14.1” WXGA High Definition BrightView Widescreen Display (1280 x 800)
Fax/Modem: High speed 56K modem
Network Card: Integrated 10/100BASE-T Ethernet LAN
Wireless Connectivity: 802.11 a/b/g WLANBluetooth wireless networking
Sound: Altec Lansing speakers
Keyboard: 101 key compatible keyboard with 1 Quick Launch Button
Pointing Device: Touch Pad with On/Off button and dedicated vertical and horizontal Scroll Up/Down pad

PC Card Slots: One ExpressCard/54 slot (also supports ExpressCard/34)

External Ports:
5-in-1 integrated Digital Media Reader for Secure Digital cards, MultiMedia cards, Memory Stick, Memory Stick Pro, or xD Picture cards
Headphone out
Microphone in
IEEE 1394 firewire
Consumer IR
S-Video TV out
Expansion port 3

Dimensions : 33.4 cm (L) x 23.7 cm (W) x 2.6 cm (min H) / 3.9 cm (max H)
Weight: 2.45 kg
65 W AC Power Adapter
6-cell Lithium-Ion (Li-Ion) battery

OS: Windows Vista Home Premium, Microsoft Works, etc

Bundled Junk:
Microsoft Office 2007 Home/Student (60 day Trial)
Norton Internet Security (60 days trial)

Tuesday, December 25, 2007

Serial Port Based Intelligent PIC Programmers

I have wrote about USB based PIC programmers and simple PIC programmers. It seems that with PICkit 2 coming out, it makes less sense to use other serial based intelligent PIC programmers. Still some of the users may already have those simple programmers and want to build their own intelligent PIC programmers. In that case, here are some recommendations.

1. Wisp628A:
You can build this relatively easily. Actually back in 2005, I've built two of this on a breadboard.
The alternative firmware and software from Rob Hamerling's xwisp2 ( is my preferred choice. It is cross-platform and supports OS/2, Windows, Linux, Mac OS X and FreeBSD.

You can either buy the kit and build your own or create your own based on the information on the site.

2. Easyprog:
The author (Olin Lathrop) provides the hardware design, firmware and software sources.
You can buy the kit and assemble by yourself. I do not think you would like to buy the ready-made kit since PICkit 2 may be cheaper and better. Embed Inc also has the ProProg
( which is aimed at production and USBProg ( which is aimed at profoessional lab and benchtop use. ProProg and USBprog seem to be both well designed.

3. Kitrus also has some kits.
The price may not be justified now that PICkit 2 is out and at only US$35 (not including tax and shipment).

4. Microchip PICstart+:
Some of the sites have the clones but I think this is not easy to be built by hobbyists and its feature is not as good as PICkit 2 even though it is more expensive than PICkit 2.

A survey of simple PIC programmers under Windows and Linux

Merry Christmas and Happy New Year!

I myself do not use any simple PIC programmers without a PIC as the brain of the programmer. Still some people think PICkit 2 is too expensive at US$35. So there is still a market for the simple programmers. Coupled with bootloader, it can still be useful for some hobbyists. Of course I will still recommend PICkit 2 to those who can afford the US$35, it is well worth the money and save you a lot of troubles with the simple programmers.

Windows simple PIC programmer software sites often links to the supported hardware. Some of them are based on Parallel port (eg: Tait), some of them are based on Serial port (eg: JDM), very few of them are based on USB. Parallel port and serial port start to disappear from many laptop computers. And many of the serial port based programmers will not work properly with common USB-to-Serial converters. Almost all Parallel port based programmers will not work with common USB-to-Parallel converter (often made for old printer). Some of the very simple programs only support LVP (low voltage programming) which only applies to very few PICs (but some of the PICs are popular). So far I can see that most simple programmers do not support 3V only PICs like PIC18J/18K and PIC24/dsPIC33 which PICkit 2 support well.

WinPIC supports many 5V PICs and its manual seems to be quite good. Another advantage is that the author also provides the source packages.

It claims the support of most Flash PICs and can rival some of the features of PICkit 2. But take note that its main supported programmer GTP-USB+ is actually an intelligent PIC programmer and at 60 Euro it is much more expensive than PICkit 2 which costs US$35 . If you are using the simple programmer, I am not so sure if it still supports the same number of device.

PICPGM also supports quite some PICs. One interesting thing is that it has an FT245BL based USB programmer which unfortunately only supports LVP.

IC-Prog is perhaps one of the most popular programing software in the web. However, its support of PICs is actually one of the weakest from the website.

pikdev supports many simple programmers and PICs under Linux.

piklab supports many simple programmers and PICs under Linux. Of course, it also supports many other programmers, including Microchip MPLAB ICD2.

This is different from the maybe-better-known picprg ( but it is actually much better than that one.

It only supports Parallel port based programmer. But anyway, parallel-port based simple programmers is said to be more reliable than serial port based simple programmers.

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

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

Friday, December 21, 2007

fpusb -- Another libusb-0.1 replacement under Linux

The author is trying to solve the problems of libusb-0.1 but not going to use OpenUSB which is more ambitious.
  • Isochronous endpoint I/O
  • Asynchronous I/O with per-URB style callbacks
  • Zero threads (lightweight, uses main thread of calling application)
  • Exposure of poll fds to applications for good main loop integration
Right now it only works under Linux but it looks promising. Anyway, there is not much development of libusb-0.1 and libusb-1.0 now. OpenUSB is only partially working under Linux and Solaris right now.

What I am really hoping to have is a real cross platform HID API. libhid is supposed to be the one, unfortunately it is not really cross-platform.


GPLed dsPIC33 MP3 Decoder Based on MAD

Finally this is done by Alex B in Microchip Forum. I am not into dsPIC much yet but I think this is really outstanding.

Download (GPL licensed):

It is based on MAD.

Installing Ubuntu from a Unix/Linux System

This is nice guide and today I tried to install a Ubuntu 6.10 to a existing partition (which was used to test Vmware Player but I found Vmware Player is not my cup of tea since I prefer multi-boot) from a chroot environment under Ubuntu 6.06 LTS.

A fast mirror is nice to have in this case. For me I use either the default Singapore mirror ( or the Australia mirror (

I manually installed the following file, there may be new versions when you read this.

After that, I followed the guide and I have a working base installation in less than 20 minutes.

I found /etc/resolve.conf and etc/hostname was already set up properly for me.

After editing the grub.conf inside Ubuntu 6.06 LTS (I mainly use it along with 7.10) and rebooting, I ran the following two commands and then I had a almost fully working system. Strangely sound did not work under Gnome until power-down and then cold-boot the computer.
sudo apt-get install ubuntu-standard
sudo apt-get install ubuntu-desktop

Sunday, December 9, 2007

Nice Article: Forget the Linux Desktop, it's the Linux Laptop that matters!

OLPC, EEE and similar efforts are really bring Linux closer to the mainstream. Anyway, most of the people do not need the functionality of Office 2007 and do not need the Aero interface of Vista.

XP+Office XP (or Windows 2k+Office 2k) will be good for most home and business users. And now main stream Linux+OpenOffice is actually good enough for most home users. For business user, depending on the field, it may or may not be possible to ditch Windows XP which is really a very good OS with SP2 installed. But I believe OpenOffice is actually good enough for majority of the business users.

What is a Vista Home Basic Machine with 512MB RAM Good for?
Microsoft typically published their system requirement a bit too low for real world. But I've seen some Vista Home Basic machine with only 512M of RAM. What is that machine good for?

The best answer so far comes from Dell Singapore website.

It is great for " Booting the Operating System, without running applications or games".

Nice demo machine to show off Vista, huh? ;-) ;-)

Saturday, December 8, 2007

Impressions of Some Linux/BSD Distributions

Before Fall 2002, I was mainly playing with Linux (Slackware, Redhat, Mandrake, Corel, Caldera, etc) but still use Windows mostly at home. I was not using Linux between Fall 2002 and Spring 2005.

I started to try out Linux again with Ubuntu 5.04 and I liked it quite a lot. Then I was trying to 5.10 and it was not as good so I started to look at Fedora as well (Core 4). Soon I fixed the problem with 5.10 and then I found 6.06 LTS a great distribution that I am still running it as the main distribution now. I also tried Ubuntu 6.10/7.04 and they were good as well. Now I have Ubuntu 7.10 installed. Initially it is not good (problem with USplash screen) but I solved it. Firefox 1.5 under Ubuntu 6.06 is not that good but switching to swiftfox seems to solve the problem. Firefox 2.0 under Ubuntu 7.10 initially is very bad but once I remove xgl/compiz stuff it becomes better now.

On the other hand, FC5/FC6 and Fedora 7 were also not bad so I was using Fedora as the 2nd option to Ubuntu. Fedora 8 is a disaster (despite the flawless installation process) that it did not boot after installation due to the bug associated with FreeBSD partitions. So now I do not have a Fedora installation.

I tried to use OpenSuse as well, it is rather sophiscated but I feel it is relative slow. OpenSuse 10.2 installation is not good that it writes the Grub bootloader without asking and messed up my Grub. I have to boot to Ubuntu 6.06 and recover the bootloader. BTW, for Grub recover, it seems that Knoppix is good. OpenSuse 10.3 installation is flawless but trying compiz caused the system not to boot so I gave up.

I tried to use Arch Linux and it is quite good in terms of upgrading (versionless) but I do not find it offer anything more than Ubuntu.

I tried to use Gentoo for two days and it was a pain due to dead mirrors and long compiling process. And since I have FreeBSD installed, I do not need another source based distribution. FreeBSD does offer something Linux does not offer -- a BSD licensed kernel and userland. FreeBSD is not as easy to use as Linux but it is quite usable as well. I am also trying out NetBSD but I feel it is not good for desktop usage.

PClinuxOS looks nice and in the end it does not offer anything better than Ubuntu (maybe KDE is better under PClinuxOS).

So now I have Ubuntu 6.06/7.10 and FreeBSD 7.0 Beta. I will try out other things from time to time.

I still use Windows XP SP2 at home occassionaly but mostly I am using Ubuntu.

USB Programmers for PICs

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
2. GTP USB lite (somewhat like a USB version of Wouter's WISP628A)

Class 2: Good for personal and lab use
1. PICKit 2, good and cheap, supports many PICs and double as a debugger.

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.

3. The author of WinPIC800 software has the GTP USB+ Programmer which seems to be a decent programmer as well.

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.

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.

Some PICkit 2 Links

PICKit 2 website:

PICkit 2 Faq:

PICKit 2 Wishlist:

PICkit 2 under Linux, pk2 and pk2cmd Linux port:

PICkit 2 versus ICD2:

Tuesday, November 20, 2007

Debian Template to Build GCC for dsPIC/PIC24

Microchip uses GCC as the base for its C30 compiler for PIC24/dsPIC30/dsPIC33. They have also published the source according to GPL requirement.

John Steele Scott has done some good jobs to patch the Microchip sources and provided the Debian templates to build debian packages.

Instruction for V3.01b (patches and Debian Templates)

Old version V2.05

Old version V2.00 and related information

Free PDF Touchup Utility for Linux

Often we need to do a bit of touch up for the PDF document. Normally Adobe Acrobat is the preferred tools to do it. However free tools are now catching up as well.

flpsed: touch up and edit

pdfedit: touch up and edit

pdftk: combine/split PDF files

New FC8 install hangs at the message "Creating root device"

I had the exact same problem as post #15. I have two HDDs in the system. Windows/Ubuntu (6.06 and 7.10) are in the SATA HDD. I installed Fedore 8 on the IDE HDD which has also Windows DATA partitions and Linux DATA partitions along with FreeBSD 7-Beta.

I ended up going back to Fedora 7 which is working fine. It is really a pity. The installation process from the live CD was quite smooth. It just did not boot after the "flawless" installation.

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.

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.

1. Create group "usb" and add the user name to it.
[Added on 22-Dec-2007]
[mcuee@localhost /usr/home/mcuee]$ su -
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

2. Edit /etc/devfs.rules to add the following lines.
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.
5. Activate the changes by running the following command (no reboot required):
localhost# /etc/rc.d/devfs start

6. Testing:
localhost# exit

===[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

Saturday, November 10, 2007

Good article about GPLv3

I like the four free spirits mentioned in the article.

"Nobody should be restricted by the software they use. There are four freedoms that every user should have:

  • the freedom to use the software for any purpose,
  • the freedom to share the software with your friends and neighbors,
  • the freedom to change the software to suit your needs, and
  • the freedom to share the changes you make.

When a program offers users all of these freedoms, we call it free software."

From the article, it seems GPLv3 is actually better than GPLv2. Initially I hear quite some negative review about GPLv3, but this article seems to clarify some doubts I had before.

I think both the permissive licenses (I like BSD style licenses) and GPL both have its places in the open source movement.

Still I have some doubts about using GPL in embedded software development. Maybe it needs some further clarifications.

Top 100 jobs in Singapore (2007)

It seems electronics engineers are not too bad.

Building Microchip PIC32 GCC Compiler from Source

Over the past few days, I learned how to build PIC32 (MIPS32 M4K Core based) Cross Compiler from provided GCC source under Ubuntu Linux.

This is documented in this forum thread.

libusb-win32 and OpenUSB wiki opened

Often open source projects suffer from poor documentation which scares the new users away. Now SourceForge starts to offer wiki service. Based on my suggestion, libusb-win32 and OpenUSB have opened the wiki site.

As a start, I created some initial pages.

Thursday, November 1, 2007

Bootloaders for Microchip PIC MCUs

The following is a list of bootloaders for Microchip PIC MCUs.

Comments on 14-Mar-2010: The updated list is here:

1. Non-free
2. free for no-commercial
4. Ethernet bootloader

Free from Microchip:
1. Microchip AN851: PIC16F/18F bootloader via serial
2. Microchip AN247: PIC18F CAN MCU bootloader via CAN bus
3. Microchip AN1094: PIC24/dsPIC30/dsPIC33 bootloader
4. Microchip TCP/IP Stack 4.1x: Internet bootloader for PIC18J Ethernet MCU
5. Microchip PICkit 2: USB HID Bootloader
6. Microchip USB Firmware framerwork: USB bootloader using generic USB driver

Free from third party:
1. ingenia free dsPIC bootloader:

2. Tiny Bootloader. It also lists many other bootloaders.
Some of the listed bootloaders in the Tiny Bootloader page.
3) Wouter's Wloader:
4) Wouter's ZPL:
5) Jolt:
6) Hitech PIC16F/18F bootloader
7. Colt bootloader:
8. Bloader and Screamer:
9. Free USB bootloader (with encription support)
10. Serial Wombat's boot-loader for 18F4620 (with encription) is available for free here:

11. Philip Pemberton's PIC18F bootloader
12. dsPIC30 open source bootloader

There are so many bootloaders. It seems to me AN851 and Tiny Bootloader are the most popular ones for 16F/18F.

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: .

Microchip has released the source code here:

Jeff Post has since released the Linux port of PK2CMD here:

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://
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
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):

PICkit 2 with FreeBSD (new):

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
===[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

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, October 17, 2007

PICkit 2 and PICDEM FS USB Demo Board Under FreeBSD

With the help of Hans, I am able to get the PICDEM FS USB Demo Board demo mode (interrupt transfer) work under FreeBSD using his USB stack under FreeBSD 6.2 Stable. This is a byproduct of getting the PICkit 2 work again under FreeBSD.

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.

Links to the FreeBSD USB Mailing List thread:

The bootloader (bulk transfer) is not working yet.

Monday, September 17, 2007

Olimex LPC-P2148 USB Under Linux/Windows

My LPC-P2148 was collecting dust after the first failure under Linux and change of job mid-2006. My NForce3 AMD64 motherboard is quite picky. The thread is here and I was not able to solve the problem.

Later I found out lpcusb and jcwren's example which works fine for me. So I will start again with LPC-P2148 after some learning on the PIC USB side. Maybe I will start with modifying the lpcusb stack for bare-minimum device ( interrupt transfer, bulk transfer, generic HID like the example from LakeView Ressearch). I want to try out isochronous transfer as well as it is the base for USB audio device.

Some links:

Olimex LPC-P2148


jcwren's good example




Startup Guide with Open Source Arm Development Tools

AN10583: USB Audio with libmad port and EFSL

Tuesday, August 14, 2007

Bare Minimum Isochronous Transfer USB Example for PIC18F2550

USB is not easy and isochronous transfer is the most difficult transfer type. I've done a bare minimim example with PICkit 2 (18F2550). However, it still needs quite some improvement both on the firmware side and the host side. Unfortunately I am quite weak especially on the host side.

Wednesday, July 11, 2007

PICkit 2 as a USB Learning Tool

1. Brad Minch's Lab 2 HID example using gputils

2. PICKit 2 CDC emulation ported from Microchip's PICDEM FS USB

3. Mark Rages' PICKit 2 as a SPI Protocol Analyser Hack
The code is written in SDCC.

Sunday, July 8, 2007


I have started a thread in Microchip Forum to collect the links
related to PIC MCU and USB. Many others have also contributed
to the link collections. It is here:

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 ( 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 (

Microchip has kindly published the source codes for PICkit 2 firmware and the standardalone PC application (

PICkit 2 works under Linux thanks to the efforts from several developers. The easiest to start with is pk2 from Jeff Post ( 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.

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

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: -----

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.
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 ( Take note that you should ask general questions about PICkit 2 in Microchip Forum ( 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 ( Only Step 2 is necessary.

8) How to help out?
From Jeff Post:

Note on 10-April-2009: it is now better to use pk2cmd at Microchip PICkit 2 websites.

Friday, May 18, 2007

PIC Development Tools under FreeBSD

I am mainly a Linux user and Ubuntu is my preferred distribution. However from time to time I will also try other Linux distributions and FreeBSD.

Right now I have a small installation of FreeBSD 6 Stable. It is not as easy to use as Linux but it is definitely usable. The following is a list of links for PIC MCU development tools under FreeBSD.

FreeBSD has ports for gputils/sdcc/gpsim/picp/pikdev.

It is also possible to build Piklab under FreeBSD.

PICStart+ works under FreeBSD with picp.

Wisp628 works under FreeBSD with xwisp2.

JALv2 works under FreeBSD as well.

The main problem under FreeBSD is the lack of device drivers. But they are catching up. One of the things in development is the alternative USB stack by Hans Petter Selasky ( With his help I am now able to run pk2 and piklab to support PICKit 2 under FreeBSD.

For more detail, please refer to the following mailing list thread.

You need to run the alternative USB stack (maybe you will need to use the stable or current branch) and apply the following patch to ugen.c in order to get pk2 to work. Maybe the patch is already in the latest version of the USB stack.

==== ugen.c#12 - ugen.c ====
@@ -637,9 +637,12 @@
return (EIO);
- /* setup clear stall */
- sce->xfer_out[0]->clearstall_xfer =
- sce->xfer_out[1];
+ if ((ed->bmAttributes & UE_XFERTYPE) == UE_BULK) {
+ /* setup clear stall */
+ sce->xfer_out[0]->clearstall_xfer =
+ sce->xfer_out[1];
+ }

@@ -759,10 +762,6 @@
return (EIO);

- /* setup clear stall */
- sce->xfer_in[0]->clearstall_xfer =
- sce->xfer_in[1];
PRINTFN(5, ("interrupt open done\n"));
@@ -1322,6 +1321,17 @@


+ tr_error:
+ if (xfer->error != USBD_CANCELLED) {
+ /* setup clear stall */
+ xfer->clearstall_xfer = sce->xfer_out[1];
+ /* start clear-stall */
+ usbd_start_hardware(xfer);
+ return;
+ }
+ return;

PRINTFN(5, ("xfer=%p actlen=%d\n",
@@ -1362,7 +1372,7 @@

- tr_error:
+ xfer->clearstall_xfer = NULL;

Wednesday, May 16, 2007

Microchip PIC MCU Development Tools under Linux

I've collected some links about PIC MCU Development Tools under Linux.

1. MPLAB under Linux with Wine (my mini-howto):

2. PICkit 2 under Linux
pk2 by Jeff Post:
pyk by Mark Rages: search pyk
piklab by Nicolas Hadacek:

3. MPLAB ICD 2 under Linux

4. PICStart+ under Linux
PICP by Jeff Post:

5. PICDEM FS USB related project
1) PICDEM FS USB bootloader for Linux using libusb
2)PICDEM FS USB demo appliation under Linux using libusb

6. PICkit 1 under Linux

7. Basic tools: gputils assembler/linker, gpsim simulator and sdcc C compiler

SEEVAL32 EEPROM programmer

My blog is born today: 16-May-2007!

Today I borrowed a Microchip SEEVAL 32 Serial EEProm Designer Kit from local Microchip. The kit seems quite neat. The cost is US$99.

The URL for SEEVAL is at

I am a big fan of Microchip PICKit 2 USB programmer and I am an active member of the pickit-devel Google group. Technically speaking, PICkit 2 ( should be able to support EEProm programming as well. Hopefully they can add the support soon.