User guide

6.8 An embeddable application with interrupt handling
This section describes how to convert the application in A semihosted application with interrupt handling into an
embeddable application. Converting the application requires additional files:
vectors.s
This file contains exception vectors and exception handlers. For this example ROM is fixed at
0x0.
init.s
This file performs ROM/RAM remapping (if required), initializes stack pointers and interrupts for
each mode, and branches to __main in the C library. The C library code at __main eventually
calls main().
ROM/RAM remapping is not used in this example. A sample scatter-load description for
remapping is available in install_directory\Examples\embedded\rps_irq.
retarget.c
This file implements a retarget layer for low-level I/O. Typically, this would contain your own
target-dependent implementations. This example provides implementations of fputc(),
ferror(), _sys_exit(), _ttywrch() and __user_initial_stackheap().
The #define USE_SERIAL_PORT selects code to output characters from the serial port of an
ARM Development (PID) Board.
serial.c
This file implements a simple polled RS232 serial driver for the ARM Integrator board. It outputs
single characters on Serial Port A at 9600 Baud, 8 bit, no parity, 1 stop bit.
The file uart.c instantiates the uart0 structure. The scatter-loading files place this structure
over the peripheral registers. See Using scatter loading with memory-mapped I/O for details on
defining I/O structures.
heap.s
This file exports the symbol bottom_of_heap.
stack.s
This file exports the symbol top_of_stacks.
To ensure that no semihosting SWI-using function is linked in from the C library, #pragma
import(__use_no_semihosting_swi) is referenced from main().
6.8.1 Memory map
The scatter-load descriptor file defines one load region, FLASH, and five execution regions:
FLASH
The entire program is placed in ROM. The RO code executes from FLASH. The execution
address of FLASH is the same as its load address (0x24000000), so it does not have to be
moved.
32bitRAM
The exception vector table vectors.s must appear in RAM at 0x0, so the +First command
is used to place it first in the image. The RW data is relocated from FLASH to 32bitRAM above
the vector code at 0x0. The ZI data is initialized in RAM above the RW data.
ROM/RAM remapping is not used in this example. A sample scatter-load description for
remapping is available in install_directory\Examples\Embedded\rps_irq.
HEAP
The heap is located at the end of memory used by the variables. The object heap.o contains a
symbol that is used to setup the heap base.
STACKS
The top of stack at 0x40000. The object stack.o contains a symbol that is used to set up the
stack top.
UART0
Memory-mapped I/O at 0x16000000. The object uart.o contains symbols that are used to
reserve the memory-mapped I/O. This memory is not zero-initialized.
6.8.2 Building the example
To build the example, use the build_c.bat batch file, the CodeWarrior IDE project file rps_irq.mcp with a target
of EmbedScatter, or a makefile containing the following (the indented lines are a continuation of the single line
above):
armasm -g vectors.s
armasm -g -PD "ROM_RAM_REMAP SETL {TRUE}" init.s
armasm -g stack.s
armasm -g heap.s
REM Use the following lines to build without using the serial port.
armcc -c -g -O1 main.c -I..\include -DEMBEDDED -DROM_RAM_REMAP
armcc -c -g -O1 retarget.c
REM Use the following lines to build using the serial port.
REM armcc -c -g -O1 main.c -I..\include -DEMBEDDED -DROM_RAM_REMAP
Writing Code for ROM
Copyright ?1999 2001 ARM Limited 6-22