|ARM Technical Support Knowledge Articles|
To port an existing program to use microlib, some changes to your source code and build scripts are usually required. This FAQ gives a step by step guide on how to achieve this task.
Microlib is not a standards-compliant ISO C library. Before porting microlib into your existing program or writing a new program using microlib, it is recommended that you check the section “Differences from the default C library” and “ISO C features missing from microlib” of the ARM Compiler Tools libraries documentation to ensure it meets your application requirements.
Step 1: Configure Stack and Heap
Specify the initial stack pointer by defining a symbol
to be equal to the top of the stack. The initial stack pointer must be aligned to a multiple of eight bytes. Specify the start and end of the heap by defining symbols
respectively, if your program uses ARM-supplied heap functions. This can be done in an assembly file or using the embedded assembler in C, for example:
__asm void dummy_function(void)
__initial_sp EQU STACK_BASE
__heap_base EQU HEAP_BASE
__heap_limit EQU (HEAP_BASE + HEAP_SIZE)
The above constants
can be defined in a header file (
, for example) and included in the C source file defining the stack and heap symbols.
#define HEAP_BASE 0x20100000
#define STACK_BASE 0x20200000
#define HEAP_SIZE ((STACK_BASE-HEAP_BASE)/2)
#define STACK_SIZE ((STACK_BASE-HEAP_BASE)/2)
Step 2: Prevent
You need to make sure your
main() function does not return by putting an endless loop at the end of
function. This is because microlib does not contain any library code to handle exit from
while (1) ; //endless loop to prevent main() returning
Step 3: Configure RVCT to use microlib
In the build script, add the
to the linker command line. This switch will cause the linker to link in the microlib instead of the default standard C library.
Step 4: Build your code
You may see error messages and need to change your code if you are using any unsupported features, for example, using OS functions such as
Article last edited on: 2011-11-01 09:07:19
Did you find this article helpful? Yes No
How can we improve this article?