STM32 compilation

Compile

Compilation process

The STM32 compilation process is shown in the figure below
Insert picture description here

bin given elf

*.binIt is a binary file that contains the code. It needs to be burned to the designated location (eg. 0x0800 0000FLASH 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 ( TrueStudiounder the directory), and can be used after modification without rewriting.

In the last step of linking, different target files *.objand link files are *.ldcomposed *.elf.

MEMORY

/* Specify the memory areas */
MEMORY
	{
		RAM (xrw)      : ORIGIN = 0x20000000, LENGTH = 64K
		FLASH (rx)      : ORIGIN = 0x8000000, LENGTH = 512K
	}

MEMORYSpecifies the memory segment available in the chip. ORIGIN: Starting length;: Length of LENGTHsegment. r:readable; wwritable; xexecutable.

SECTION

SECTIONSSpecifies 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 scriptThere 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 .textsegment and then place all the files contained in all .textsegments of the word. (Such as different file-defined functions and the like. Feeling is .textsub-segment, but it should be just a simple naming convention.)

Entry function

There are four options for entry function:

  1. the `-e’ entry command-line option;
  2. the ENTRY(symbol) command in a linker control script;
  3. the value of the symbol __start, if present;
  4. the address of the first byte of the .text section, if present;
  5. The address 0.

The default entry function in __startSTM32 is , but STM32 official routines will use Reset_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 */
}

KEEPIt 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. >FLASHThese are placed in the section of MEMORYthe statement of FLASHthe. This is the meaning of one of .isr_vectorthe segments on FLASHthe starting address, aligned on four-byte skip optimization.

It can be known from the startup file that it .isr_vectoris 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 newlibthat it is more complete and more optimized. The other is newlib-nanothat it has been reduced in size. Compile time, use -specs=nano.specsusenewlib-nano

Guess you like

Origin blog.csdn.net/lib0000/article/details/112356870