Saturday, November 10, 2007

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.
http://forum.microchip.com/tm.aspx?m=292995

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.
http://libusb-win32.wiki.sourceforge.net/Porting+libusb+based+program+to+libusb-win32
http://openusb.wiki.sourceforge.net/libusb+related+projects

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:
http://www.microchip.com/forums/tm.aspx?m=424874

Commercial/Non-Free.
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
http://www.brushelectronics.com/index.php?page=software#EBL
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:

http://www.ingenia-cat.com/

2. Tiny Bootloader. It also lists many other bootloaders.
http://www.etc.ugal.ro/cchiculita/software/picbootloader.htm
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
http://www.htsoft.com/forum/all/showflat.php/Cat/0/Number/26726/an/0/page/0#Post26726
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)
http://www.diolan.com/pic/bootloader.html
10. Serial Wombat's boot-loader for 18F4620 (with encription) is available for free here:

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

11. Philip Pemberton's PIC18F bootloader
http://www.philpem.me.uk/elec/pic/
12. dsPIC30 open source bootloader
http://mrmackey.no-ip.org/elektronik/ds30loader/

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