-
Notifications
You must be signed in to change notification settings - Fork 4
/
Makefile
141 lines (115 loc) · 3.58 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
PROJECT = FUJIscope
######################################
# building variables
######################################
HIDE_WARNING = 1
# debug build?
DEBUG = 1
# optimization
OPT = -O3
#######################################
# pathes
#######################################
# Build path
OUTDIR = build
TOOL_DIR = tool
BIN_IMAGE = $(OUTDIR)/$(PROJECT).bin
EXECUTABLE = $(OUTDIR)/$(PROJECT).elf
MAP_FILE = $(OUTDIR)/$(PROJECT).map
SRC_DIR = Drivers/STM32F4xx_HAL_Driver/Src \
Src
INC_DIR = Drivers/CMSIS/Device/ST/STM32F4xx/Include \
Drivers/CMSIS/Include \
Drivers/STM32F4xx_HAL_Driver/Inc \
Drivers/STM32F4xx_HAL_Driver/Inc/Legacy \
Inc
######################################
# source
######################################
C_SOURCES += $(wildcard $(addsuffix /*.c,$(SRC_DIR)))
ASM_SOURCES = startup/startup_stm32f407xx.s
#######################################
# binaries
#######################################
CC = arm-none-eabi-gcc
AS = arm-none-eabi-gcc -x assembler-with-cpp
CP = arm-none-eabi-objcopy
AR = arm-none-eabi-ar
SZ = arm-none-eabi-size
HEX = $(CP) -O ihex
BIN = $(CP) -O binary -S
#######################################
# CFLAGS
#######################################
# macros for gcc
C_DEFS = -D__weak="__attribute__((weak))" -D__packed="__attribute__((__packed__))" -DUSE_HAL_DRIVER -DSTM32F407xx
# includes for gcc
INCLUDES += $(addprefix -I,$(INC_DIR))
# compile gcc flags
CFLAGS = -mthumb -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard $(C_DEFS) $(INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections
ifeq ($(DEBUG), 1)
CFLAGS += -g -gdwarf-2
endif
ifeq ($(HIDE_WARNING), 1)
CFLAGS += -w
endif
# Generate dependency information
CFLAGS += -std=c99 -MD -MP -MF .dep/$(@F).d
#Floating point
CFLAGS +=-DARM_MATH_CM4 -D__FPU_PRESENT -ffast-math
#######################################
# LDFLAGS
#######################################
# link script
LDSCRIPT = STM32F407VGTx_FLASH.ld
# libraries
#LIBS is optional , you can remove it
LIBS = -lc -lm -lnosys
LDFLAGS = -mthumb -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -specs=nano.specs
LDFLAGS+= -T$(TOOL_DIR)/STM32F407VGTx_FLASH.ld $(LIBS)
LDFLAGS +=-Wl,-Map=$(MAP_FILE),--cref -Wl,--gc-sections
MAKDIR = mk
MAK = $(wildcard $(MAKDIR)/*.mk)
# default action: build all
all: $(OUTDIR)/$(PROJECT).elf $(OUTDIR)/$(PROJECT).hex $(BIN_IMAGE)
include $(MAK)
#######################################
# build the application
#######################################
# list of ObjectS
OBJS = $(addprefix $(OUTDIR)/,$(notdir $(C_SOURCES:.c=.o)))
vpath %.c $(sort $(dir $(C_SOURCES)))
# list of ASM program OBJS
OBJS += $(addprefix $(OUTDIR)/,$(notdir $(ASM_SOURCES:.s=.o)))
OBJS += $(RTOSOBJS)
vpath %.s $(sort $(dir $(ASM_SOURCES)))
$(OUTDIR)/%.o: %.c Makefile | $(OUTDIR)
@echo " MAIN | CC "$@
@$(CC) -c $(CFLAGS) -Wa,-a,-ad,-alms=$(OUTDIR)/$(notdir $(<:.c=.lst)) $< -o $@
$(OUTDIR)/%.o: %.s Makefile | $(OUTDIR)
@echo " MAIN | AS "$@
@$(AS) -c $(CFLAGS) $< -o $@
$(OUTDIR)/$(PROJECT).elf: $(OBJS) Makefile
@echo " ALL | LD "$@
@$(CC) $(OBJS) $(LDFLAGS) -o $@
@$(SZ) $@
$(OUTDIR)/%.hex: $(OUTDIR)/%.elf | $(OUTDIR)
$(HEX) $< $@
$(OUTDIR)/%.bin: $(OUTDIR)/%.elf | $(OUTDIR)
$(BIN) $< $@
$(OUTDIR):
mkdir -p $@
#######################################
# clean up
#######################################
clean:
-rm -fR .dep $(OUTDIR)
# Flash the STM32F4
flash: $(EXECUTABLE)
st-flash write $(BIN_IMAGE) 0x8000000
#######################################
# dependencies
#######################################
-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
.PHONY: clean all
# *** EOF ***