forked from Yang-96Boards/Neon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
147 lines (117 loc) · 3.86 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
142
143
144
145
146
147
GNUMAKEFLAGS = --no-print-directory
CROSS_COMPILE = arm-none-eabi-
SRC_ROOT = ./Src
LIB_ROOT = ./Lib
CHIP = STM32F411xE
BOARD = USE_STM32F4XX_NUCLEO
LD_SCRIPT = $(LIB_ROOT)/Projects/STM32F411RE-Nucleo/Templates/TrueSTUDIO/STM32F4xx-Nucleo/STM32F411RE_FLASH.ld
CC = $(CROSS_COMPILE)gcc
LD = $(CROSS_COMPILE)gcc
AS = $(CROSS_COMPILE)gcc
AR = $(CROSS_COMPILE)ar
RANLIB = $(CROSS_COMPILE)ranlib
OBJCOPY = $(CROSS_COMPILE)objcopy
CFLAGS = -mcpu=cortex-m4 -mthumb
CFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16
CFLAGS += -fdata-sections -ffunction-sections
CFLAGS += -Wall -Wextra -fsigned-char
CFLAGS += -DUSE_HAL_DRIVER -D$(CHIP) -D$(BOARD)
CFLAGS += -O3
LDFLAGS = -mcpu=cortex-m4 -mthumb
LDFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16
LDFLAGS += -Wl,-static,--gc-sections,-Map=obj/output.map -nostartfiles
LIBS = -lm
ASFLAGS =
ARFLAGS = r
#
# By default reduce verbosity and don't print commands
# 'make V=1' will print the full commands
#
ifeq ("$(origin V)", "command line")
ifeq ($(V),1)
Q =
else
Q = @
endif
else
Q = @
endif
all: obj/x.bin
.PHONY: all
#
# Include dirs (absolute path)
#
INCDIRS = \
-I $(SRC_ROOT)/../Inc/ \
-I $(LIB_ROOT)/Drivers/STM32F4xx_HAL_Driver/Inc/ \
-I $(LIB_ROOT)/Drivers/CMSIS/Device/ST/STM32F4xx/Include/ \
-I $(LIB_ROOT)/Drivers/CMSIS/Include/ \
-I $(LIB_ROOT)/Drivers/BSP/STM32F4xx-Nucleo/
#
# Source files (path relative to SRC_ROOT)
#
SRC_C = main.c stm32f4xx_hal_msp.c stm32f4xx_it.c system_stm32f4xx.c
#
# Library files (path relative to LIB_ROOT)
#
xLIB_C = \
Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_adc.c \
Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_adc_ex.c \
Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.c \
Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cortex.c \
Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma.c \
Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma_ex.c \
Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash.c \
Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ex.c \
Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_gpio.c \
Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc.c \
Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc_ex.c \
Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_spi.c \
Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim.c \
Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim_ex.c \
Drivers/BSP/STM32F4xx-Nucleo/stm32f4xx_nucleo.c
LIB_C = \
Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.c \
Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cortex.c \
Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_gpio.c \
Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c.c \
Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c_ex.c \
Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc.c \
Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_uart.c \
Drivers/BSP/STM32F4xx-Nucleo/stm32f4xx_nucleo.c
LIB_S = Projects/STM32F411RE-Nucleo/Templates/TrueSTUDIO/startup_stm32f411xe.s
STUB_C = newlib_stubs.c
#
# Compile rules
#
SRC_C_O = $(patsubst %.c,obj/%.o,$(SRC_C))
LIB_S_O = $(patsubst %.s,obj/%.o,$(LIB_S))
LIB_C_O = $(patsubst %.c,obj/%.o,$(LIB_C))
STUB_C_O = $(patsubst %.c,obj/%.o,$(STUB_C))
$(SRC_C_O): obj/%.o: $(SRC_ROOT)/%.c
@echo Compile $<
$(Q)mkdir -p $(dir $@)
$(Q)$(CC) $(CFLAGS) $(INCDIRS) -MD -c -o $@ $<
$(LIB_S_O): obj/%.o: $(LIB_ROOT)/%.s
@echo Compile $<
$(Q)mkdir -p $(dir $@)
$(Q)$(AS) $(ASFLAGS) -c -o $@ $<
$(LIB_C_O): obj/%.o: $(LIB_ROOT)/%.c
@echo Compile $<
$(Q)mkdir -p $(dir $@)
$(Q)$(CC) $(CFLAGS) $(INCDIRS) -MD -c -o $@ $<
obj/x.elf: $(SRC_C_O) $(LIB_S_O) $(LIB_C_O) $(STUB_C_O)
@echo Link $@
$(Q)$(LD) $(LDFLAGS) -T $(LD_SCRIPT) \
$(SRC_C_O) $(LIB_S_O) $(LIB_C_O) $(STUB_C_O) \
$(LIBS) -o $@
$(STUB_C_O): obj/%.o: %.c
@echo Compile $<
$(Q)mkdir -p $(dir $@)
$(Q)$(CC) $(CFLAGS) $(INCDIRS) -MD -c -o $@ $<
obj/x.bin: obj/x.elf
@echo Image $@
$(Q)$(OBJCOPY) -O binary $< $@
clean:
@echo Cleanup ...
$(Q)rm -rf obj