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. http://www.microchipc.com/PIC18bootload/ Non-free
2. http://www.microchipc.com/PIC16bootload/ free for no-commercial
3. http://kulesh-software.com/Software/USBPicBooloader/index.html
4. Ethernet bootloader
5. http://www.auelectronics.selfip.com/Software.htm

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: http://www.voti.nl/wloader/index_1.html
4) Wouter's ZPL: http://www.circuitcellar.com/flash2002/honorable.htm
5) Jolt: http://mdubuc.freeshell.org/Jolt
6) Hitech PIC16F/18F bootloader
7. Colt bootloader: http://mdubuc.freeshell.org/Colt/
8. Bloader and Screamer: http://www.sparkfun.com/commerce/hdr.php?p=tutorials
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: http://www.microchip.com/pickit2 .

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