pic18F4550 with Debian GNU/Linux and SDCC

Hello.

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:

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

For this:

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

15 comentarios to “pic18F4550 with Debian GNU/Linux and SDCC”

  1. MGA Says:

    Thank you for the info…

  2. Leandro Says:

    Hi, when I compile crt0i.c (after changes) I have this message:

    leandro@leandro-laptop:/usr/share/sdcc/lib/src/pic16$ sudo sdcc -c -mpic16 -p18f4550 /usr/share/sdcc/lib/src/pic16/startup/crt0i.c

    /usr/share/sdcc/lib/src/pic16/startup/crt0i.c:1: warning 115: unknown or unsupported #pragma directive ‘code_entry 0x800’

    Did you solve it?

    Thanks!

  3. otamay Says:

    Ahh!! It is a wordpress issue… jeje

    Just change the “×” for an “x” (the key left to the “c” in a qwerty keyboard) and it will compile sucessfully.

    WordPress change all the x for an × char =/.

  4. Geday Says:

    Hi there.

    Did you use a PICDEM USB board or another home brew one?

    Thanks

  5. Otamay Says:

    A homebrew one, this is the circuit I’ve built.

  6. Andy Says:

    Hi, this could be a dumb question, but I am trying to use linux in conjungtion with this microcontroller as well, however it would seem that there is no hot-plug support for the PIC microcontrollers… Or at least the device is not recognized and nothing is created in /dev when it is plugged in. Did you write your own drivers or how did you go about getting Linux to recognize the device?

  7. Otamay Says:

    When you flash the bootloader onto the pic, you can program it with Piklab choosing picdem bootloader as the programmer.

    On the other side, a month ago I’ve seen another project using this microcontroller, Pinguino project ( http://sites.google.com:80/site/pinguinotutorial/home ). It is based on Vasco bootloader and programming is very easy, because it comes with its own programming interface (arduino like) and easy and useful C functions. It uses SDCC.

    You can program with both methods and it is almost the same, but with pinguino, there are some usb functions that you could use to communicate with the PC (I’ve used lua).

    =) See you!.

  8. funlw65 Says:

    Hi,

    You succeeded in using interrupts with this setup? Or only simple programs which don’t need interrupts?

    Vasi

  9. Lejan Says:

    Hi, Thanks for your help, when I compiler it says:

    leandro@leandro-PC:/usr/share/sdcc/lib/src/pic16/startup$ sdcc -c -mpic16 -p18f4550 /usr/share/sdcc/lib/src/pic16/startup/crt0i.c

    /usr/share/sdcc/lib/src/pic16/startup/crt0i.c:255: error 4: ‘fopen’ failed on file ‘crt0i.asm’

    Solution??
    Thanks!!

  10. Lejan Says:

    Just solved, I had to change the folder where I was executing the order.

  11. Nafeesa Mangat Says:

    Hey there! I could have sworn I’ve been to this site before but after browsing through some of the post I realized it’s new to me.

    Anyways, I’m definitely delighted I found it and I’ll be book-marking and checking back frequently!

  12. pic18F4550 with Debian GNU/Linux and SDCC | Mundo da Robótica Says:

    […] Fonte e mais detalhes aqui. […]

  13. s4 mini prix Says:

    Au niveau de la qualité des clichés en eux même, le capteur de eight mégapixels
    avec flash LED fait bien son travail. Sans atteindre la qualité de
    prise de vue de son grand frère le Galaxy S4, ce modèle prend de bonnes images assez détaillées dans différentes conditions de luminosité.

    Les factors faibles du capteur sont comme toujours le zoom qui dégrade rapidement la qualité
    et les pictures en condition de faible luminosité.
    Sur ce dernier level, Samsung suggest un « Mode Nuit » assez convainquant qui rehausse la luminosité des pictures et fait gagner en netteté.

  14. codes promo Says:

    Conseil valable rare unique fois sur Pimkie.com du 22/01/2010 au 24/01/2010 inclus)
    sur toute la drugstore (à partir avec 49 euros d’achat) valable 1 fois contre un achat minimum en compagnie de 50€) Ouverture valable jusqu’au 1er avril ensuite ce n’est marche un blague.
    Dernières tendances de cette mode puis bonnes sociabilités sont présentées régulièrement par
    tangibles catalogues adroitement fournis.
    manifestes accessoires pendant parfait race Médor
    puis Cie , Zooplus , Zubial Automobile Motocyclette Adam Alors Eve ,
    Sexy Voie , Orcanta Ambulant & Internet Conrad Conradpro Cette pénates du canevas Lacoshop Manutan Provence
    outillage Fée game Ce espiègle grenat Les jouets parmi fourré Micromania myToys.fr
    Walz-kidzz Valable en contrepartie terminé commande en même
    temps que produits en même temps que la catégorie Accomplir-Ration jusqu’au 31/12/2014 Domicile verso du circonstances keliquide Adam ensuite Eve , Orcanta
    lingerie , Sexy Voie

  15. Darcy Says:

    Hola he disdrutado con tu blog no te conocía te empiezo a
    seguir hoy. Felicidades tienes una web fantástica Gracias por compartir con todos.

Responder

Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Cerrar sesión / Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión / Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión / Cambiar )

Google+ photo

Estás comentando usando tu cuenta de Google+. Cerrar sesión / Cambiar )

Conectando a %s


A %d blogueros les gusta esto: