Home | Projects | Notes > ARM Cortex-M3/M4 Processor > Build Process & Makefile

[!] Note: The compiler does not save .i and .s file by default. You can make the compiler save them by using the compiler flags
Note that you need to specify some target-specific information when cross-compiling. These include the processor name or processor architecture, Thumb/ARM state, etc. Otherwise, the assembler may not understand some architecture-specific inline assembly code. (Check the "Machine-Dependent Options" section in the online GCC documentation.)
-c: Compile or assemble the source files, but do not link
-S: Stop after the stage of compilation proper; do not assemble.
-o: Designate output file name
-mcpu=: Specifies the name of the target ARM processor for which GCC should tune the performance of the code
-march=: Specifies the name of the target ARM architecture. GCC uses this name to determine what kind of instructions it can emit when generating assembly code. This option can be used in conjunction with or instead of the -mcpu= option. (For the ARM Cortex M4 processor, -march=armv7ve)
-mthum: Thumb state ISA
-marm: ARM state ISA (default)
For more information about compiler flags, consult GCC documentation.
xxxxxxxxxx11arm-none-eabi-gcc -c -mcpu=cortex-m4 -mthumb main.c -o main.oGenerates
main.o
xxxxxxxxxx11arm-none-eabi-gcc -S -mcpu=cortex-m4 -mthumb main.c -o main.sGenerates
main.s
Make is a tool.
xxxxxxxxxx21$ which make2/usr/bin/makexxxxxxxxxx21$ make # correct; make is an executable2$ makefile # incorrect; makefile is NOT an executable
Makefile is a file written in such a way that Make tool can understand.
Make tool needs Makefile as the input and process as per the instructions written in it.
"Makefile" or "makefile" both are valid notations.
Makefile is used for automating the build process.
Make tool is very powerful in that it can detect the modified source file(s) and process/build file them only by running make. Compiling only the modified source files and linking them into the project can save huge amount of time when only a small number of source files has been modified in a big project.
Time stamp is used to detect the modified source files.
In general, compilation is much slower process than linking. Make tool takes the advantage of this fact.
Makefile for "Task Scheduler" project:
xxxxxxxxxx431# Makefile (or makefile)2
3# Variables4CC=arm-none-eabi-gcc5MACH=cortex-m46CFLAGS= -c -mcpu=$(MACH) -mthumb -mfloat-abi=soft -std=gnu11 -Wall -o0 7LDFLAGS= -mcpu=$(MACH) -mthumb -mfloat-abi=soft --specs=nano.specs -T stm32_ls.ld -Wl,-Map=final.map8# LDFLAGS for semihosting9LDFLAGS_SH= -mcpu=$(MACH) -mthumb -mfloat-abi=soft --specs=rdimon.specs -T stm32_ls.ld -Wl,-Map=final.map10
11all: main.o led.o stm32_startup.o syscalls.o final.elf12
13# semihosting14sh: main.o led.o stm32_startup.o final_sh.elf15
16# Target (dependencies / recipie)17main.o: main.c # target is 'main.o', and 'main.c'(dependency) is necessary to create target18 $(CC) $(CFLAGS) -o $@ $^ # recipie: command to generate the target19 # $(CC) $(CFLAGS) $^ -o $@20 # $(CC) $(CFLAGS) main.c -o main.o21 # '$^' represents dependency, '$@' represents target (@ does look like a target :))22 23led.o: led.c24 $(CC) $(CFLAGS) -o $@ $^ 25
26stm32_startup.o: stm32_startup.c27 $(CC) $(CFLAGS) -o $@ $^ 28
29syscalls.o: syscalls.c30 $(CC) $(CFLAGS) -o $@ $^ 31
32final.elf: main.o led.o stm32_startup.o syscalls.o33 $(CC) $(LDFLAGS) -o $@ $^ 34
35final_sh.elf: main.o led.o stm32_startup.o # exclude 'syscalls.o'36 $(CC) $(LDFLAGS_SH) -o $@ $^ 37
38clean:39 rm -rf *.o *.elf # in Windows rm -> del40
41connect: # connect board with OpenOCD42 openocd -f /board/stm32f4discovery.cfg43 # /usr/share/openocd/scripts/board/stm32f4discovery.cfg
-std=: Specifies the language standard. (Check "Options Controlling C Dialect" section of the GCC documentation)
-On: Specifies the optimization level to n (by default 0)
Nayak, K. (2022). Embedded Systems Programming on ARM Cortex-M3/M4 Processor [Video file]. Retrieved from https://www.udemy.com/course/embedded-system-programming-on-arm-cortex-m3m4/