stm32 bootup material - HoangViet93/stm32-nano GitHub Wiki

Scope

In this page i will explain minimal material needed for stm32 project and you can understand the structure of this project.

Material

Arm embedded toolchain

Gnu arm toolchain is all tools you need to build a program from source code. Take a look at the step the install it. <br > https://launchpad.net/~team-gcc-arm-embedded/+archive/ubuntu/ppa <br > It will install a set of tool at /user/bin/ with prefix name arm-none-eabi

vietht@ubuntu:~/project/stm32-nano$ ls /usr/bin/ | grep arm-none-eabi
arm-none-eabi-addr2line
arm-none-eabi-ar
arm-none-eabi-as
arm-none-eabi-c++
arm-none-eabi-c++filt
arm-none-eabi-cpp
arm-none-eabi-elfedit
arm-none-eabi-g++
arm-none-eabi-gcc
arm-none-eabi-gcc-6.2.1
arm-none-eabi-gcc-ar
arm-none-eabi-gcc-nm
arm-none-eabi-gcc-ranlib
arm-none-eabi-gcov
arm-none-eabi-gcov-tool
arm-none-eabi-gdb
arm-none-eabi-gprof
arm-none-eabi-ld
arm-none-eabi-ld.bfd
arm-none-eabi-nm
arm-none-eabi-objcopy
arm-none-eabi-objdump
arm-none-eabi-ranlib
arm-none-eabi-readelf
arm-none-eabi-size
arm-none-eabi-strings
arm-none-eabi-strip

To understand purpose of these component in toolchain we should start built a simple program using these tool. Look at here http://www.bravegnu.org/gnu-eprog/hello-arm.html <br >

name description
arm-none-eabi-gcc arm gnu compiler
arm-none-eabi-objcopy generate binary/hex file from elf
arm-none-eabi-nm list all symbol of elf file
arm-none-eabi-objdump dump symbol table in object file
arm-none-eabi-ld gnu linker, use to link all file in project to generate elf
arm-none-eabi-size output size of program with data,code,bss... section

To illustrates purpose of these program let see the build flow. These code snippet below just a psuedo code<br >

buildflow <br >

  • C source file
int main(void)
{
	volatile int a = 5;
	volatile int b = 4;
	volatile int c = 0;

	c = a + b;
}
  • Assembly file
        .data		@ variable store in data section
a:   	.4byte 5	@ First number
b:   	.4byte 4    @ Second number
b: 		.4byte 0    @ 4 byte space for result

        .text		@ code store in text section
        .align
start:
        ldr   r0, =a         @ r0 = &a
        ldr   r1, =b         @ r1 = &b

        ldr   r2, [r0]       @ r2 = *r0
        ldr   r3, [r1]       @ r3 = *r1

        add   r4, r2, r3     @ r4 = r2 + r3

        ldr   r0, =result    @ r0 = &result
        str   r4, [r0]       @ *r0 = r4

stop:   b stop
  • object file this file store symbol (start, stop and variable) and they address, data section ... You will see 2 separate section data below. Variables take 4bytes each and increase consecutively.
vietht@ubuntu:~/project/test$ arm-none-eabi-objdump -t main.o

main.o:     file format elf32-littlearm

SYMBOL TABLE:
00000000 l    d  .text	00000000 .text
00000000 l    d  .data	00000000 .data
00000000 l    d  .bss	00000000 .bss
00000000 l       .data	00000000 a
00000004 l       .data	00000000 b
00000008 l       .data	00000000 c
00000000 l       .text	00000000 start
0000001c l       .text	00000000 stop
00000000 l    d  .ARM.attributes	00000000 .ARM.attributes
arm-none-eabi-ld -T<linker script> -o main.elf main.o
  • Now cut-off additional information (symbol info, data section info ...) in elf file to build binary file for load to stm32 flash.

A file in binary format contains consecutive bytes from a specific memory address. No other additional information is >stored in the file. This is convenient for Flash programming tools, since all that has to be done when programming is to >copy each byte in the file, to consecutive address starting from a specified base address in memory.

arm-none-eabi-objcopy -O binary main.elf main.bin

continue...

⚠️ **GitHub.com Fallback** ⚠️