FreeJALduino with SDCC

1. Forewords

The free and open source SDCC C compiler for PIC's have the poorer documentation in the world, in my opinion (and, if you ask me, his optimizations are a bad joke). The little pages you can find on internet contain only basics about using it. It really needs a library development team and a larger community to help in improving the compiler and in spreading it.

I've tried it a few times with and without an USB bootloader and only recently I started to have some results beyond blinking a LED. Well, actually it was still a blinking LED but using non-blocking delays and that means interrupts (in both boot and non-boot mode). This gives me some hopes regarding to this compiler :-P . Regarding to usability, of course.

The package provided include some files from Pinguino project v9.04 (all credits goes to Pinguino team) of Jean-Pierre Mandon and it tries to be an alternative of the huge vasco bootloader (~8Kb), a continuation of Pinguino project or, who knows, maybe a better base for Pinguino itself. The digitalw.c file is hacked to be usable with the FreeJALduino board (only the 18F2550 variant) but, the original one is included as original_digitalw.c file. As it is now it does not offer Arduino language compatibility - is based (but not exclusively) on the "pure" SDCC C language (where all Pinguino users will arrive sooner or later).

2. Installation

Download the archives from the end of this page. Unzip the sdcc.zip archive in your C:\ root directory (not other place or HDD). If you have already a C:\sdcc directory, please rename it to make room for our archived one. Unzip also sdcc_projects.zip in root directory so, your folders will look like on the image (I used Total Commander file manager to illustrate this). The SDCC compiler include also the required gputils tools and will not interfere with an existing gputils installation on your system. It also does not depend on system variables.

If you intend to use the bootloader, download Pdfsusb.zip and USBDrivers.zip archives and unzip them in C:\ - you will need them later.

3. Preparing your board

If you want to use your board with a bootloader, then you must download the hex file provided at attachments and burn it on your board. There are two bootloaders available:

- freejalduino_usb_bootloader_autostart.hex for FreeJALduino boards;

- pinguino_usb_bootloader_autostart.hex for Pinguino boards.

The bootloader is written in JAL language (the best free compiler in the world for PICs, seconded by Pic Micro Pascal - I advice you to try them) by Albert Faber and modified by Sebastien Lelong to have a nice feedback on the Boot LED attached on RA4 pin. The sources are included.

If you don't want to use a bootloader, then no problem, we have examples for both situations. But then, you will need a way to burn the examples on your board and is not so handy for Pinguino users - you need a breadboard and an ICSP connector, or just wires to connect the required Pinguino pins to a Pickit2 programmer (FreeJALduino have his own ICSP connector but I know also many customized Pinguino boards have it too).

4. Get ready for tests

4.1. If you use the bootloader

After burning you bootloader, connect the board to the USB (on FreeJALduino5, green jumper can be in "USB power source" position

if you don't use an external power adapter - both LED's are ON if blue jumper is set to left

) and Windows will detect it and after a while, will ask you for the drivers. You must point to this folder:

"C:\USBDrivers\MCHPUSB Custom Driver\MCHPUSB Driver\Release"

After driver installation, Pdfsusb.exe uploader should be able to detect your board.

Next, go to

"c:\sdcc_projects\boot_mode\"

folder and issue the build.bat command. Everything must compile without errors (if you downloaded my latest archives, it will). We have now the blink.hex file.

Start the Pdfsusb hex loader from:

"c:\Pdfsusb\Pdfsusb.exe"

Because our user space is empty, the bootloader will not try to give control to user application, will stay in "Boot mode" indefinitely so, we don't need to rush. Select the combo box and you should see "PICDEM FS USB 0 (boot)". Select it and board is ready to receive your program. In common conditions, when you have a previous user application, from the RESET bootloader has started counting and if you don't select the board from the combo box within 10 seconds, bootloader will give control to your previous application. But when the selection is made, bootloader stops counting and awaits your program.

Press "Load HEX file" button and choose blink.hex from the folder you compiled it. You can see that the program starts from 0x800 address (000800).

IMPORTANT! If you get a warning message about configuration bits, don't worry. Not matter what you choose as response, the bootloader inside the PIC will not override your configuration bits (which are the bootloader configuration bits).

Press "Program Device" button and application will start to upload the hex file into your board. If everything is ok, you should get this message:

Close Pdfsusb.exe application and you can execute your application. The Boot LED must start blinking as in example.

4.2. If you don't use the bootloader

Go directly to

"c:\sdcc_projects\no_boot_mode\"

folder and issue the build.bat command. Everything must compile without errors (if you downloaded my latest archives, it will). We have now the blink.hex file which you can burn it in you board using Pickit2 or compatible bootloader.

5. Where to go?

Maybe to a better C compiler? Well, a good idea can be MPLAB C18 compiler (until Microchip will release XC8 as open source) which is in free full version (professional) for Linux and Mac. But, if you want to stick with SDCC, then you can find in this page (soon, a link to the index project page) some SDCC examples -and I will add more if my time, health and knowledge permits.