Compilation of STM32 bare board program

Disclaimer: Due to my limited knowledge, any mistakes are welcome.

The development environment for STM32 is keil uvision5 (also known as MDK5). This software integrates a lot of functions, but it is not suitable for learning. Because it masks a lot of internal details. Such as compilation, linking details.

Next, we will introduce compiling bare board programs without using MDK5.

Under linux, the basic steps of compiling are as follows:

1)    arm-linux-gcc  -c  -nostdlib  source -o dest

2)    arm-linux-ld  -nostdlib -nostartfiles -T text=0x48000000  -e entry  sources -o dest

3)    arm-linux-objcopy -o binary source dest 

The first step: Compile into an object file, the parameter nostdlib is not to use the standard library file. Because the bare board has no library to use.

Step 2: Link multiple object files,

    The parameter nostdlib is not to use the standard library file,

    The parameter nostartfiles is not to add standard startup code to the head of the program. (Standard startup is a piece of code called by the operating system, _start),

    In the parameter -T options, write 8000000 as text=0 to define the starting position of the code segment (this address is the physical address, because the bare-board program generally does not open the MMU, in the operating system, the MMU will convert the virtual address sent by the cpu to the real physical address address).

    The parameter -e entry is the entry address of the definition program. The function name is generally used here, (the function name represents the entry address of the function).

Step 3: objcopy - copy and translate object files. Copy the transform binary.

     The parameter -O binary is to copy only the binary code in the linked file. A part of the linked file is a description of the program, which is not executable code. This part of the content will be checked in the operating system and then removed. If there is no other operation in the bare board program to remove this part of the content, an error will occur. A description of the program can be viewed using file a.out.

The resulting file is the bare board program that can be executed on the bare board.

MDK5 blocks these operational details. In the learning process, we need to know how the bare board program comes from.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325836810&siteId=291194637