I'm trying to figure out how to use sdcc to program a Vex robot, which is based on the PIC 18f8520. The Vex has traditionally been programmed with MPLAB and mcc18, and more recently with EasyC and RobotC.
The first hurdle I need to overcome is the base address of the hex file. The Vex requires programs to reside between 0x0800 and 0x3fff.
I found the --code-loc linker flag, but it doesn't seem to have any effect. Is this flag supposed to work the the PIC16 port? Am I missing something obvious? I realize that PIC support may not be finished. If that's why I'm having trouble here, I'll just shut up and be patient...
As a stop-gap, I thought of hacking the addresses in the hex file after-the-fact, but that would only be simple if the code uses purely relative addressing, which I can't assume. I haven't had time to explore the machine code format yet.
Below is a simple test program compiled with what seem to me to be the right flags. Below that is a segment of the Vex default firmware, to show an example with the correct 0x0800 base address.
I'm using the Mar 1, 2008 snapshot of sdcc.
FreeBSD sculpin bacon ~/Prog/VEX/Squares 441: more squares.c
for (c=0; c<100; ++c)
d = c * c;
FreeBSD sculpin bacon ~/Prog/VEX/Squares 442: sdcc -mpic16 -p18f8520 -c squares.c
FreeBSD sculpin bacon ~/Prog/VEX/Squares 443: sdcc -mpic16 -p18f8520 --code-loc 0x0800 -oSquares.hex squares.o
message: using default linker script "/usr/local/share/gputils/lkr/18f8520.lkr"
FreeBSD sculpin bacon ~/Prog/VEX/Squares 444: more Squares.hex :020000040000FA
FreeBSD sculpin bacon ~/Prog/VEX/Firmware 449: more Vex_default_firmware.hex
OK, I'm still wondering about the --code-loc flag, but I managed to get the addressing scheme I need by editing the linker script 18f8520.lkr to the following, using the EasyC/mcc linker script as a model. ( They're not quite compatible, but very similar. )
// $Id: 18f8520.lkr,v 1.7 2006/08/19 02:50:52 craigfranklin Exp $
// File: 18f8520.lkr
// Sample linker script for the PIC18F8520 processor
// Not intended for use with MPLAB C18. For C18 projects,
// use the linker scripts provided with that product.
CODEPAGE NAME=vectors START=0x0 END=0x7FF PROTECTED
CODEPAGE NAME=page START=0x800 END=0x7FFF
CODEPAGE NAME=idlocs START=0x200000 END=0x200007 PROTECTED
CODEPAGE NAME=config START=0x300000 END=0x30000D PROTECTED
CODEPAGE NAME=devid START=0x3FFFFE END=0x3FFFFF PROTECTED
CODEPAGE NAME=eedata START=0xF00000 END=0xF003FF PROTECTED
ACCESSBANK NAME=accessram START=0x0 END=0x5F
DATABANK NAME=gpr0 START=0x80 END=0xFF PROTECTED
DATABANK NAME=gpr1 START=0x100 END=0x1FF
DATABANK NAME=gpr2 START=0x200 END=0x2FF
DATABANK NAME=gpr3 START=0x300 END=0x3FF
DATABANK NAME=gpr4 START=0x400 END=0x4FF
DATABANK NAME=gpr5 START=0x500 END=0x5FF
DATABANK NAME=gpr6 START=0x600 END=0x6FF
DATABANK NAME=gpr7 START=0x700 END=0x7F3
DATABANK NAME=dbgspr START=0x7F4 END=0x7FF PROTECTED
ACCESSBANK NAME=accesssfr START=0xF60 END=0xFFF PROTECTED
The resulting hex file is acceptable to the loader (programmer), although it has an extra line in it before the code when compared with the mcc generated code:
If someone can point me to a some good docs on the hex file format, I'd appreciate it.
> If someone can point me to a some good docs on the hex file format, I'd appreciate it.
The original Intel specification is also available but you'll find it
in the documentation for the highly recommended toolset "srecord" as well:
http://srecord.sourceforge.net/srecord-1.39.pdf (page 75)
Btw. both your intel hex snippets do not seem complete, the end of file record
srec_info (part of the above mentioned toolset) complains:)
Thanks for the pointers.
I know the snippets were incompete: I only posted enough to show the extra line I was referring to.
Log in to post a comment.
Sign up for the SourceForge newsletter:
You seem to have CSS turned off.
Please don't fill out this field.