Cross Compiler Introduction
The compiler tool chain used for the unit Embedded Systems 220 is version
2.7.2 of GCC, built for DOS using an outdated version of DJGPP, and
configured as a cross compiler for the Motorola 68332 microcontroller.
The EyeBot Prompt icon starts a command prompt configured with the
necessary environment variables to run the cross compiler. Trying to
run the tools from a normal Command Prompt or MS-DOS Prompt window will
not work.
There is no integrated development environment like Visual Studio.
Instead, you write C or assembly language source files using a text
editor, such as Notepad. You then run the appropriate commands to build
your program. The output file is an S-record, which is a file with the
HEX extension.
References
You will need a Motorola 68332 command reference, and a RoBIOS library
reference. These are available on the Mobile
Robot Lab web page. Choose EyeBot => Controller => Hardware
=> Data Sheets for the 68332 reference, and EyeBot => Controller
=> Libraries for the RoBIOS reference. The 68332 reference is on
pages 47-50 of the PDF file.
Programming in Assembly Language
Assembly-language programs should have the S file extension. The assembler
is the GNU assembler, which uses different notation to the Microsoft
Macro Assembler that some of you may be familiar with.
An assembly-language program should consist of text and data sections,
containing the executable code and the static data. You need to include
the labmacs.i include file in order to define the addresses of the RoBIOS
user functions.
The RoBIOS user functions follow the C calling convention. To call
them, you must push the parameters onto the stack in the right-to-left
order, and then JSR to them.
The following Hello World program illustrates these points. Use this
as a skeleton for your own assembly-language programs.
.include "labmac.i"
.section .data
msg: .asciz "Hello, world!\n"
.section .text
.globl main
main: pea msg
jsr LCDPrintf
add.l #4, %sp
move.l #0, %d0
rts
"labmac.i" Routines:
A number of routines, such as OSGetCount to get the system clock, and
KEYGet to wait for a button press, are pre-written and can be accessed
in a program by including the .include "labmac.i" line in
your code.
· Input parameters for the routines are passed through the stack
· Output of routines is put into D0
To execute routine XXX the following convention is used:
1. Push parameters (if necessary) onto the stack
2. JSR XXX
3. Reset stack (if parameters were pushed onto it)
4. Result of XXX is stored in D0
Building Assembly Language Programs
To build a single-file assembly-language program called program.s,
use the gas68 command. You should supply the file name without the file
extension. For example, if the previous program was called hello.s,
then the command gas68 hello would be used; not gas68 hello.s
Building C Programs
The following C program performs exactly the same steps as the assembly-language
program given above.
#include <eyebot.h>
int main(void)
{
LCDPrintf("Hello, world!\n");
return 0;
}
To compile this program, use the gcc68 command. Once again, do not
include the file extension on the command line. Type gcc68 hello, not
gcc68 hello.c.
Building Multiple File Programs
If your program is large enough, you might split it into multiple files.
Also, if part of your program is written in C, and part of it is written
in assembly language, then you will need to use more than one file.
To build programs consisting of more than one file, you first build
each file separately, producing a corresponding file called an object
file, which has the O extension. You then combine your object files
into a single S-record using a tool called a linker.
To assemble an assembly-language program into an object file, use the
gas68o command. You should not supply the file extension. To compile
a C program into an object file, use the gcc68o command. You should
not supply the file extension for this command, either.
To link object files together, use the gld68o command. The first parameter
should be the desired S-record file name. The second and remaining parameters
should be the object file names, in any order. This command is different
to all the other commands, in that you should provide the file extension.
For example, the commands gas68o hello and gld68o hello.hex hello.o
will build the assembly-language Hello World program shown above.
If you know how, you might also consider writing a make file.
Downloading and Running Programs
Once the program is built, you have an S-record file, with a HEX extension.
To run the program, you first need to download it to the EyeBot. The
EyeBot should be connected to your computer using a standard RS232 serial
cable. The transhex command is used to download the program over the
serial cable. You might need to set the serial port or baud rate parameters
using the /C or /B options.