Manual programming

From Pinguino-Wiki
Jump to: navigation, search
  • Bootloader: Version 4
  • Board: Pinguino 26J50

A toolchain is the set of programming tools that are used to create a product (typically another computer program or system of programs). The tools may be used in a chain, so that the output of each tool becomes the input for the next, but the term is used widely to refer to any set of linked development tools.

Pinguino IDE, when targeting the Pinguino 26J50, comprises sdcc —a C compiler— and sdcpp —a preprocessor— from the SDCC suite, gpasm and gplink from the GPUTILS suite.

Contents

SDCC

General options
Option Explanation
-I Add to the include (*.h) path.
-L Add the next field to the library search path.
-D Define macro.
-W Pass through options to the pre-processor (p), assembler (a) or linker (l).
--compile-only Compile and assemble, but do not link.
-o Place the output into the given path/file.


Code generation options
Option Explanation
-m Set the port to use.
-p Select port specific processor.


Special options for the pic16 port
Option Explanation
--obanksel= Set banksel optimization level (default=0 no).
--denable-peeps Explicit enable of peepholes.
--optimize-cmp Try to optimize some compares.
--optimize-df Thoroughly analyze data flow (memory and time intensive!).
--ivt-loc= Set address of interrupt vector table.
--no-crt Do not link any default run-time initialization module.


Using SDCC under Windows

Compiling

sdcc -mpic16 -p18f26j50 -I<ide_path>/p8/include -I<ide_path>/p8/include/non-free -I<ide_path>/p8/include/pinguino/core -I<ide_path>/p8/include/pinguino/libraries -I<ide_path>/<working_folder> -Dboot4 -DPINGUINO26J50 --obanksel=9 --optimize-cmp --optimize-df --denable-peeps --ivt-loc=3072 --compile-only <ide_path>/source/main.c -o<ide_path>/source/main.o

Linking

sdcc -mpic16 -p18f26j50 -I<ide_path>/p8/include -I<ide_path>/p8/include/non-free -I<ide_path>/p8/include/pinguino/core -I<ide_path>/p8/include/pinguino/libraries -L<ide_path>/p8/lib -L<ide_path>/p8/lib/non-free -Dboot4 -DPINGUINO26J50 --obanksel=9 --optimize-cmp --optimize-df --denable-peeps --ivt-loc=3072 --no-crt <ide_path>/source/main.o libc18f.lib libm18f.lib libio18f26j50.lib -Wl-s<ide_path>/p8/lkr/boot4.18f26j50.lkr,-m -o<ide_path>/source/main.hex

Windows Batch File Example

You need to keep only p8 and source directories.

Your program must be in source/user.c.

Simple blinking LED should look like:

#include <digitalw.c>
#include <delay.c>
 
void setup()
{                
    pinmode(USERLED, OUTPUT);     
}
 
void loop()
{
    toggle(USERLED);			
    Delayms(1000);	// delay 1 second	        
}

SDCC binaries are available from SDCC web page.

@echo OFF
SET PATH=%PATH%;.\win32\p8\bin
ECHO  **********************************************************************
ECHO  *                                                                    *
ECHO  *                 PINGUINO PLATFORM BUILDER BATCH                    *
ECHO  *                                                                    *
ECHO  **********************************************************************
ECHO  * Script Rev 20130316-2300                                           *
ECHO  * @author Ludovic VAGINAY                                            *
ECHO  **********************************************************************
ECHO  .
ECHO  .
ECHO  **********************************************************************
ECHO  *   PERFORM A SOURCE FOLDER CLEANING (Delete older executables)...   *
IF EXIST .\source\main.cod DEL .\source\main.cod
IF EXIST .\source\main.lst DEL .\source\main.lst
IF EXIST .\source\main.map DEL .\source\main.map
IF EXIST .\source\main.asm DEL .\source\main.asm
IF EXIST .\source\main.hex DEL .\source\main.hex
IF EXIST .\source\main.o DEL .\source\main.o
ECHO  *                                                      ...Done !     *
ECHO  **********************************************************************
ECHO .             
ECHO .
ECHO  **********************************************************************
ECHO  *         Now, compiling...                                          *
sdcc -mpic16 -p18f26j50 -I.\p8\include -I.\p8\include\non-free -I.\p8\include\pinguino\core -I.\p8\include\pinguino\libraries -I.\source -Dboot4 -DPINGUINO26J50 --obanksel=9 --optimize-cmp --optimize-df --denable-peeps --ivt-loc=3072 --compile-only .\source\main.c -o.\source\main.o 2> compilation.txt
ECHO  *              ... Done !                                            *
REM ECHO Compilation Log content :
REM TYPE compilation.txt
ECHO  *                                                                    *
IF NOT EXIST ".\source\main.o" GOTO ERROR_LABEL
ECHO  *  > 0 Error. So, good news, Now were going to link your program !   *
sdcc -mpic16 -p18f26j50 -I.\p8\include -I.\p8\include\non-free -I.\p8\include\pinguino\core -I.\p8\include\pinguino\libraries -L.\p8\lib -L.\p8\lib\non-free -Dboot4 -DPINGUINO26J50 --obanksel=9 --optimize-cmp --optimize-df --denable-peeps --ivt-loc=3072 --no-crt .\source\main.o libc18f.lib libm18f.lib libio18f26j50.lib -Wl-s.\p8\lkr\boot4.18f26j50.lkr,-m -o.\source\main.hex
ECHO  *                                                   ...Done !        *
ECHO  **********************************************************************
GOTO END_LABEL
:ERROR_LABEL
ECHO  *        Error on compilation forbids linking (main.o is missing).   *
ECHO  *   ===> Look in compilation.txt log where are found errors. <===    *
ECHO  **********************************************************************
:END_LABEL
ECHO .
ECHO .
PAUSE

Using SDCC under Linux

ToDo

Using SDCC under OS X

If you have installed the OS X version of the Pinguino IDE, then you need to keep only the macosx, p8 and source directories and their contents.

Note: Before revision 762 of the Pinguino X.4 IDE, the gpasm and gplink binaries in macosx/bin need to be upgraded from v0.13.4 beta to v0.13.7 beta (later versions may work, not tested) to be able to compile and link programs for the Pinguino 26J50 board. You can download gputils-0.13.7 from http://sourceforge.net/projects/gputils/files/gputils/0.13.7/ and compile (compiles cleanly under OS X 10.6.8), then copy to the macosx/p8/bin directory.

Program Skeleton

Your program defines should be in source/define.h and your program code should be in source/user.c.

The define.h file for a simple blinking LED program for the Pinguino 26J50 board should look like:


/* hardware definition for Pinguino 26J50 board */
#define myLED 12    // pin 12 = RC2
 
#include <delay.c>
#include <digitalw.c>
 
/************************************************
 * Configuration words for Pinguino 26J50 Board *
 ************************************************/
 
static __code char __at __CONFIG1L _conf0 = 0x86;  // 20 MHz (external crystal)
static __code char __at __CONFIG1H _conf1 = 0xF7;  // 48 MHz (no clock divider)
static __code char __at __CONFIG2L _conf2 = 0x1D;  // HSPLL
static __code char __at __CONFIG2H _conf3 = 0xFF;
static __code char __at __CONFIG3L _conf4 = 0x61;  // DSWDT and RTCC uses INTRC
static __code char __at __CONFIG3H _conf5 = 0xF8;
static __code char __at __CONFIG4L _conf6 = 0x81;  // 0xFF
static __code char __at __CONFIG4H _conf7 = 0xF1;


... and the user.c code file should look like:


/* setup() is run once only */
void setup() 
        {
        pinmode(myLED, OUTPUT);
        }
 
/* loop() loops forever */
void loop()
        {
        toggle(myLED);
        Delayms(2000);   // delay 2 seconds between blinks
        }

OS X Bourne shell scripts

Compiling

#!/bin/sh

# Set the IDE path to find the necessary files
# -- CHANGE the next line to suit YOUR file system
ide_path="/Users/trev/pinguino/rev459"

# Compile command
${ide_path}/macosx/p8/bin/sdcc -mpic16 --obanksel=9 --optimize-cmp --optimize-df --denable-peeps --ivt-loc=3072 -p18f26j50 -DPIC18F26J50 -DPinguino26J50 -Dboot4 -I${ide_path}/p8/include -I${ide_path}/p8/include/non-free/pic16 -I${ide_path}/p8/include/pinguino/core -I${ide_path}/p8/include/pinguino/libraries -I${ide_path}/source --compile-only -o${ide_path}/source/main.o ${ide_path}/source/main.c

Linking

#!/bin/sh

# Set the IDE path to find the necessary files
# -- CHANGE the next line to suit YOUR file system
ide_path="/Users/trev/pinguino/rev459"

# Link command
${ide_path}/macosx/p8/bin/sdcc -mpic16 --obanksel=9 --optimize-cmp --optimize-df --denable-peeps --use-crt=${ide_path}/p8/obj/crt0i18f26j50.o --ivt-loc=3072 -Wl-s${ide_path}/p8/lkr/boot4.18f26j50.lkr -m -p18f26j50 -DPIC18F26J50 -DPinguino26J50 -I${ide_path}/p8/include -I${ide_path}/p8/include/non-free/pic16 -I${ide_path}/p8/include/pinguino/core -I${ide_path}/p8/include/pinguino/libraries -L${ide_path}/p8/lib/pic16 -llibc18f.lib -llibm18f.lib -llibio18f26j50.lib -llibsdcc.lib ${ide_path}/source/main.o -o${ide_path}/source/main.hex

Programming

You can now program the Pinguino 26J50 board using a Microchip PICkit2 or other hardware PIC programmer. Simply import the main.hex file and program the board using the ICSP pins!

Personal tools