Yesterday, i were working with 18f4550 pic device, flashed with microchip’s bootloader (picdem). I’ve discovered that in linux there are few documentation about programming in 18f pic series. Well, I’ve finally programmed my pic without a pic programmer (using the bootloader), all the process from debian gnu/linux (using sid).
The programs I’ve needed (and the versions used by me) are:
- piklab (0.15.4-1)
- gputils (0.13.7-1) and gputils-common (0.13.7-1)
- sdcc (2.9.0-3)
- and the picdemfs microchip bootloader (download from here, hex to restore pic to the original state)
The process is (commands from deban-based distributions, others may vary):
Install gputils, gputils-common, sdcc and piklab [aptitude install gputils gputils-common sdcc piklab](others say that sdcc must be compiled by our own, but I couldn compile it ¬¬, but debian’s sdcc binary worked very well).
The problem with SDCC and the bootloader is that the hex generated by SDCC starts at position 0 of the pic. This is a problem because the booloader is there, so we need to begin our program after 0X800 position, where the bootloader ends. So we must edit the linker file corresponding to our pic (in my case, 18f4550.lkr , located in /usr/share/gputils/lkr/ .
Change this line:
CODEPAGE NAME=page START=0x0 END=0x7FFF
CODEPAGE NAME=boot START=0x0 END=0x7FF PROTECTED
CODEPAGE NAME=vectors START=0x800 END=0x829 PROTECTED
CODEPAGE NAME=page START=0x800 END=0x7FFF
The interesting line is the page CODEPAGE, it must start at 0x800 because the bootloader is located before that position.
I don’t know how this exactly works, but crt0i.o writes a few code in the position 0, so we must to edit the source code and compile it again to avoid errors.
crt0i.c is under /usr/share/sdcc/lib/src/pic16/startup/ . Just edit it adding this line to the beginning of file (before anything else):
#pragma code _entry 0x800
Compile crt0i.c and replace the original crt0i.o (under /usr/share/sdcc/lib/pic16/) with the custom crt0i.o.
sdcc -c -mpic16 -p18f4550 /usr/share/sdcc/lib/src/pic16/startup/crt0i.c
mv /usr/share/sdcc/lib/pic16/crt0i.o /usr/share/sdcc/lib/pic16/crt0i_ORIG.o
cp crt0i.o /usr/share/sdcc/lib/pic16/crtoi.o
With this changes, you’ve almost done. Now you can connect the pic to the computer (using usb and the bootloader), and in the lower section of the window, choose picdem Bootloader (USB Port) and Small Device C Compiler. On the left side of the window, choose your device (18f4550). To finish, compile the “hello world!” program in tis page (very useful page) http://www.freenet.org.nz/sdcc/ , and you will see in the hex file that begins at position 0x800 instead 0x000.
Connect your pic to the usb port nd program it, an all is done!
Comments, suggestions, questions… I may help you if I can =).