This is a very simple exercise whose purpose is to get you acquitted with the process of compiling, loading and checking an embedded systems program. The task is solely setting up a led (or something similar) to blink indefinitely.
Let's begin with a pseudo code (actual coding is up to you):
1. |
int main(void) { |
The pseudo-code is self-explaining: an infinite loop alternating commands to turn on the led, cause some delay, turning off the led, and cause some delay.
The really interesting things are the functinons
led_on()
and led_off()
. If you're using the
Atmel STK500 with an AVR AT90can128 for this exercise, I suggest you
to take a look at this manual
for I/O port B. If you're using an Arduino Uno with an AVR ATMega328, check this
one.
Let's now compile our simple program:
Warning: our build of GCC is not integrating correctly with Arduino, so, for now, you'll need to copy the file avr/gcc/avr/lib/avr5/crtm328p.o into your current folder.
Try checking for the type of executable we just generated:
# file ledtells us that led is a statically linked executable stored in the Executable and Linking Format (ELF), that contains a symbol table (not stripped).
ELF is a comprehensive object format that nowadays is a de-facto standard for desktop computing. The embedded systems world, however, tends to more simple object formats such as SREC and IHEX. You have to check for the formats accepted by the loader of your embedded system platform, and, if necessary, perform the corresponding conversions.
You can convert the executable to the IHEX format with this command:
# avr-objcopy -O ihex led led.hexSince IHEX is a text format, you can directly check out the contents of led.hex:
# cat led.hexIn order the upload an executable program to your embedded system
platform, you'll need an specific tool (which is sometimes called
loader, flash programmer, or monitor). We will
upload the IHEX executable using avrdude
,
AVR Downloader/UploaDEr, and a JTAG programmer. The upload can take place either via serial or jtag.
Warning: when using jtag, make sure the cable is correctly connected to the microcontroller. THE MICROCONTROLLER MAY BE DAMAGED IF THE PINS ARE INVERTED.
After upload, the program immediately starts to execute (but you can also reset the microcontroller with the appropriate button).