Compile
Compilation process
The STM32 compilation process is shown in the figure below
bin given elf
*.bin
It is a binary file that contains the code. It needs to be burned to the designated location (eg. 0x0800 0000
FLASH address).
*.elf
: Executable Linkable Format. File contains symbol look-ups
, relocated table
. The write address is specified.
link
The following code can be found under the project template in each firmware library of STM32 (
TrueStudio
under the directory), and can be used after modification without rewriting.
In the last step of linking, different target files *.obj
and link files are *.ld
composed *.elf
.
MEMORY
/* Specify the memory areas */
MEMORY
{
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 64K
FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 512K
}
MEMORY
Specifies the memory segment available in the chip. ORIGIN
: Starting length;: Length of LENGTH
segment. r
:readable; w
writable; x
executable.
SECTION
SECTIONS
Specifies the layout of the segment in memory. These segments are the segments declared in the startup file and other source files. The linker places them in different areas of memory here . link script
There is only one and only one inside SECTIONS
, which can arrange different segments.
.
Symbols & *
Symbols
.
The current output location (or the address of the placement section) is always saved. Whenever the .
after completion of a period of the assignment .
will increment the appropriate address offset. eg.
SECTIONS
{
output :
{
file1(.text)
. = . + 1000;
file2(.text)
. += 1000;
file3(.text)
} = 0x1234;
}
This code puts the .text section in file1 at the beginning. Then place the .text section in file2 at an interval of 1000. Another interval of 1000, place the .text section in file3.
*
Representatives are selected.
.text :
{
. = ALIGN(4);
*(.text) /* .text sections (code) */
*(.text*) /* .text* sections (code) */
} >FLASH
All files placed first in the .text
segment and then place all the files contained in all .text
segments of the word. (Such as different file-defined functions and the like. Feeling is .text
sub-segment, but it should be just a simple naming convention.)
Entry function
There are four options for entry function:
- the `-e’ entry command-line option;
- the
ENTRY(symbol)
command in a linker control script; - the value of the symbol
__start
, if present; - the address of the first byte of the
.text
section, if present; - The address 0.
The default entry function in
__start
STM32 is , but STM32 official routines will useReset_Handler
(reset interrupt function) as the entry function.
Example
/* Define output sections */
SECTIONS
{
/* The startup code goes first into FLASH */
.isr_vector :
{
. = ALIGN(4);
KEEP(*(.isr_vector)) /* Startup code */
. = ALIGN(4);
} >FLASH
/* other segements here */
}
KEEP
It means that in this part, code optimization can be omitted. ALIGHN(4)
It is a function, which means that this section is aligned on a 4-byte boundary. >FLASH
These are placed in the section of MEMORY
the statement of FLASH
the. This is the meaning of one of .isr_vector
the segments on FLASH
the starting address, aligned on four-byte skip optimization.
It can be known from the startup file that it
.isr_vector
is the interrupt vector table of STM32, which contains the interrupt processing function of the system.
You can find other function definitions in the official GNU documentation .
Compilation parameters
- Nano libs and Standard C lib
The GNU ARM compiler provides two sets of C function libraries. One is newlib
that it is more complete and more optimized. The other is newlib-nano
that it has been reduced in size. Compile time, use -specs=nano.specs
usenewlib-nano