-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
175 lines (146 loc) · 4.53 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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
########################################
# Makefile for an STM32F4xx project that
# builds the project for installation
# on the STM32F401RE target.
########################################
########################################
# Define toolchain
########################################
CC=arm-none-eabi-gcc
LD=arm-none-eabi-gcc
SZ=arm-none-eabi-size
CP=arm-none-eabi-objcopy
SF=st-flash
CC_TEST=gcc
########################################
# Define project specific details
########################################
TARGET=gvent
LIB=lib/stm32
SRC_DIR=src
TEST_DIR=test
INC_DIR=include
DEV_DIR=device
HAL_SRC=$(LIB)/STM32F4xx_HAL/Src
HAL_INC=$(LIB)/STM32F4xx_HAL/Inc
########################################
# Define source files for the project
#
# All new files added to the project must
# be listed here
# ########################################
# include all C source files
SRCS = $(shell find $(SRC_DIR) -name '*.c')
# the startup file is an assembler file
# could extend this later if needed to have
# other assembler files
ASM_SRCS = $(DEV_DIR)/startup_stm32f401retx.s
OBJ = $(SRCS:.c=.o)
OBJ += $(ASM_SRCS:.s=.o)
########################################
# Define where to look for .h files
########################################
# we have to include all of our gVent include/*
# directories separately...
INC_DIRS += $(INC_DIR)/
INC_DIRS += $(INC_DIR)/hardware
INC_DIRS += $(INC_DIR)/platform
INC_DIRS += $(INC_DIR)/application
INC_DIRS += $(INC_DIR)/application/tasks
INCLUDE_BASE = $(addprefix -I,$(INC_DIRS))
# includes for the HAL and ARM Cortex hardware
INC_DIRS_HAL = $(HAL_INC)/ \
$(LIB)/CMSIS/Device/ST/STM32F4xx/Include/ \
$(LIB)/CMSIS/Include/ \
INCLUDE_PLATFORM = $(INCLUDE_BASE) $(addprefix -I,$(INC_DIRS_HAL))
INCLUDE_TEST = $(INCLUDE_BASE)
########################################
# Define HAL source dependencies
########################################
EXT_SRCS = $(HAL_SRC)/stm32f4xx_hal.c \
$(HAL_SRC)/stm32f4xx_hal_cortex.c \
$(HAL_SRC)/stm32f4xx_hal_dma.c \
$(HAL_SRC)/stm32f4xx_hal_dma_ex.c \
$(HAL_SRC)/stm32f4xx_hal_exti.c \
$(HAL_SRC)/stm32f4xx_hal_flash.c \
$(HAL_SRC)/stm32f4xx_hal_flash_ex.c \
$(HAL_SRC)/stm32f4xx_hal_flash_ramfunc.c \
$(HAL_SRC)/stm32f4xx_hal_gpio.c \
$(HAL_SRC)/stm32f4xx_hal_i2c.c \
$(HAL_SRC)/stm32f4xx_hal_pwr.c \
$(HAL_SRC)/stm32f4xx_hal_pwr_ex.c \
$(HAL_SRC)/stm32f4xx_hal_rcc.c \
$(HAL_SRC)/stm32f4xx_hal_rcc_ex.c \
$(HAL_SRC)/stm32f4xx_hal_tim.c \
$(HAL_SRC)/stm32f4xx_hal_tim_ex.c \
$(HAL_SRC)/stm32f4xx_hal_uart.c
# get the .o files for the HAL sources
OBJ += $(EXT_SRCS:.c=.o)
########################################
# Compiler and Linker Flags
########################################
CFLAGS = -std=gnu11
CFLAGS += -mcpu=cortex-m4
CFLAGS += -g3
CFLAGS += -O0
CFLAGS += -Wall
CFLAGS += -DUSE_HAL_DRIVER -DSTM32F401xE -DDEBUG
CFLAGS += -ffunction-sections
CFLAGS += -fdata-sections
CFLAGS += --specs=nano.specs
CFLAGS += -mfpu=fpv4-sp-d16
CFLAGS += -mfloat-abi=hard
CFLAGS += -mthumb
CFLAGS_TEST = -std=gnu11
CFLAGS_TEST += -O0
CFLAGS_TEST += -Wall
CFLAGS_TEST += -g3
LSCRIPT = device/STM32F401RETX_FLASH.ld
LFLAGS = -mcpu=cortex-m4
LFLAGS += -T$(LSCRIPT)
LFLAGS += --specs=nosys.specs
LFLAGS += -Wl,-Map="$(TARGET).map"
LFLAGS += -Wl,--gc-sections
LFLAGS += -static --specs=nano.specs
LFLAGS += -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb
LFLAGS += -Wl,--start-group -lc -lm -Wl,--end-group
########################################
# make recipes
########################################
all: $(TARGET).bin
$(TARGET): $(TARGET).elf
$(TARGET).elf: INCLUDE=$(INCLUDE_PLATFORM)
$(TARGET).elf: $(OBJ)
echo "building $(TARGET).elf"
$(CC) $(LFLAGS) -o $(TARGET).elf $^
$(SZ) $(TARGET).elf
$(TARGET).bin: $(TARGET).elf
$(CP) -O binary $(TARGET).elf $(TARGET).bin
%.o: %.c
$(CC) -c $(CFLAGS) $(INCLUDE) $^ -o $@
%.o: %.s
$(CC) -c -x assembler-with-cpp \
-mcpu=cortex-m4 -g3 -c -x assembler-with-cpp \
--specs=nano.specs -mfpu=fpv4-sp-d16 \
-mfloat-abi=hard -mthumb $^ -o $@
flash:
$(SF) write $(TARGET).bin 0x8000000
ventilation_test: test/test_runner.c src/application/tasks/ventilation.o \
test/ventilation_test.o \
test/stubs/system_info_stub.o \
test/stubs/valve_stub.o \
test/stubs/clinician_input_stub.o \
test/stubs/sensor_stub.o \
test/stubs/dss_stub.o \
test/test_util.o
$(CC) -o $@ $^
test: CC=$(CC_TEST)
test: CFLAGS=$(CFLAGS_TEST)
test: INCLUDE=$(INCLUDE_TEST)
test: ventilation_test
clean:
rm -f *.elf *.bin *.o *.su *.map
rm -f test/*.o test/*/*.o
rm -f $(OBJ)
rm -f $(OBJ:.o=.su)
rm -f ventilation_test