-
Notifications
You must be signed in to change notification settings - Fork 13
/
Makefile
101 lines (71 loc) · 2.18 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# toolchain
TOOLCHAIN = arm-none-eabi-
CC = $(TOOLCHAIN)gcc
CP = $(TOOLCHAIN)objcopy
AS = $(TOOLCHAIN)gcc -x assembler-with-cpp
HEX = $(CP) -O ihex
BIN = $(CP) -O binary -S
# define mcu, specify the target processor
MCU = cortex-m3
# all the files will be generated with this name (main.elf, main.bin, main.hex, etc)
PROJECT_NAME=stm32f10x_makefile_template
# specify define
DDEFS =
# define root dir
ROOT_DIR = .
# define include dir
INCLUDE_DIRS = .
# define stm32f10x lib dir
STM32F10x_LIB_DIR = $(ROOT_DIR)/stm32f10x_lib
# define user dir
USER_DIR = $(ROOT_DIR)/user
# link file
LINK_SCRIPT = $(ROOT_DIR)/stm32_flash.ld
# stm32f10x lib src
STM32F10X_LIB_SRC =
# user specific
SRC =
SRC += $(USER_DIR)/main.c
SRC += $(USER_DIR)/uart_log.c
ASM_SRC =
# user include
INCLUDE_DIRS += $(USER_DIR)
# include sub makefiles
include makefile_std_lib.mk # STM32 Standard Peripheral Library
INC_DIR = $(patsubst %, -I%, $(INCLUDE_DIRS))
# run from Flash
DEFS = $(DDEFS) -DRUN_FROM_FLASH=1
OBJECTS = $(ASM_SRC:.s=.o) $(SRC:.c=.o) $(STM32F10X_LIB_SRC:.c=.o)
# Define optimisation level here
OPT = -Os
MC_FLAGS = -mcpu=$(MCU)
AS_FLAGS = $(MC_FLAGS) -g -gdwarf-2 -mthumb -Wa,-amhls=$(<:.s=.lst)
CP_FLAGS = $(MC_FLAGS) $(OPT) -g -gdwarf-2 -mthumb -fomit-frame-pointer -Wall -fverbose-asm -Wa,-ahlms=$(<:.c=.lst) $(DEFS)
LD_FLAGS = $(MC_FLAGS) -g -gdwarf-2 -mthumb -nostartfiles -Xlinker --gc-sections -T$(LINK_SCRIPT) -Wl,-Map=$(PROJECT_NAME).map,--cref,--no-warn-mismatch
#
# makefile rules
#
all: $(OBJECTS) $(PROJECT_NAME).elf $(PROJECT_NAME).hex $(PROJECT_NAME).bin
$(TOOLCHAIN)size $(PROJECT_NAME).elf
%o: %c
$(CC) -c $(CP_FLAGS) -I . $(INC_DIR) $< -o $@
%o: %s
$(AS) -c $(AS_FLAGS) $< -o $@
%elf: $(OBJECTS)
$(CC) $(OBJECTS) $(LD_FLAGS) -o $@
%hex: %elf
$(HEX) $< $@
%bin: %elf
$(BIN) $< $@
flash: $(PROJECT_NAME).bin
st-flash write $(PROJECT_NAME).bin 0x8000000
erase:
st-flash erase
clean:
-rm -rf $(OBJECTS)
-rm -rf $(PROJECT_NAME).elf
-rm -rf $(PROJECT_NAME).map
-rm -rf $(PROJECT_NAME).hex
-rm -rf $(PROJECT_NAME).bin
-rm -rf $(SRC:.c=.lst)
-rm -rf $(ASM_SRC:.s=.lst)