-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile
204 lines (155 loc) · 6.34 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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# extra defined parameters users want to specify
EXTRA_C_DEFS ?=
######################################
# source
######################################
# C sources
C_SOURCES = \
src/station.c \
src/util.c \
src/daylight_track.c \
src/aircond_track.c \
src/netconn.c \
src/app_msg.c \
src/IO/sensor_reader.c \
src/IO/outdev.c \
src/IO/display.c \
src/IO/display/textfonts.c \
src/IO/relay/SRD-0xVDC-SL-C.c \
src/IO/display/SSD1315_OLED.c \
src/IO/YL69.c \
src/IO/LDR.c \
src/IO/DHT11.c
C_SOURCES += \
src/network/mqtt_client.c \
src/system/middleware/ESP_AT_parser/middleware.c \
src/system/platform/stm32/stm32f446/platform.c \
third_party/MQTT_Client/generate/src/mqtt_generate.c \
third_party/MQTT_Client/third_party/ESP8266_AT_parser/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_adc.c \
third_party/MQTT_Client/third_party/ESP8266_AT_parser/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_spi.c
C_ENTRY_FILE = src/station.c
# ASM sources
ASM_SOURCES =
# C defines
C_DEFS = $(foreach def, $(EXTRA_C_DEFS), $(addprefix -D, $(def)) )
# C includes
C_INCLUDES = -Iinclude \
-Iinclude/system/middleware/ESP_AT_parser \
-Iinclude/system/platform/stm32/stm32f446
# ------ middleware / platform specific configuration (TODO: refactor) ------
C_INCLUDES += \
-Ithird_party/MQTT_Client/third_party/libtomcrypt/src/headers \
-Ithird_party/MQTT_Client/third_party/libtommath \
-Ithird_party/MQTT_Client/include \
-Ithird_party/MQTT_Client/generate/include \
-Ithird_party/MQTT_Client/third_party/ESP8266_AT_parser/Src/ESP_AT_parser/inc \
-Ithird_party/MQTT_Client/include/system/middleware/ESP_AT_parser \
-Ithird_party/MQTT_Client/third_party/ESP8266_AT_parser/Src/FreeRTOS/Source/include \
-Ithird_party/MQTT_Client/third_party/ESP8266_AT_parser/Src/FreeRTOS/Source/portable/GCC/ARM_CM4_MPU \
-Ithird_party/MQTT_Client/third_party/ESP8266_AT_parser/Drivers/STM32F4xx_HAL_Driver/Inc \
-Ithird_party/MQTT_Client/third_party/ESP8266_AT_parser/Drivers/STM32F4xx_HAL_Driver/Inc/Legacy \
-Ithird_party/MQTT_Client/third_party/ESP8266_AT_parser/Drivers/CMSIS/Device/ST/STM32F4xx/Include \
-Ithird_party/MQTT_Client/third_party/ESP8266_AT_parser/Drivers/CMSIS/Include \
-Ithird_party/MQTT_Client/include/system/platform/arm/armv7m/stm \
-Ithird_party/jsmn
# C defines
C_DEFS += -DUSE_HAL_DRIVER -DSTM32F446xx -DHAL_ADC_MODULE_ENABLED -DHAL_SPI_MODULE_ENABLED
# ASM sources
ASM_SOURCES += third_party/MQTT_Client/src/system/platform/arm/armv7m/stm/bootcode_stm32f446.s
# link script
LDSCRIPT = -T./third_party/MQTT_Client/src/system/platform/arm/armv7m/stm/stm32f446_flash.ld
LD_SPECS_FILE = -specs=nano.specs
EXTRA_LIBS = -lnosys
C_TOOLCHAIN_PREFIX = arm-none-eabi-
CPU = -mcpu=cortex-m4
FPU = -mfpu=fpv4-sp-d16
FLOAT-ABI = -mfloat-abi=hard
CPU_ARCH_FLAGS = $(CPU) -mthumb $(FPU) $(FLOAT-ABI)
# Debug
OPENOCD_CFG_FILES = -f $(OPENOCD_HOME)/tcl/board/st_nucleo_f4.cfg -f $(OPENOCD_HOME)/tcl/interface/stlink-v2-1.cfg
REMOTE_DEBUGGER_CMD = openocd
DBG_SERVER_CMD = $(REMOTE_DEBUGGER_CMD) $(OPENOCD_CFG_FILES) -c init -c "reset init"
GDB_CMD = gdb-multiarch
GDB_SCRIPT_PATH = ./third_party/MQTT_Client/auto/platform/utility.gdb
DBG_CLIENT_CMD = $(GDB_CMD) -x $(GDB_SCRIPT_PATH)
# ------------------------------------------------------------------------- #
BUILD_DIR_TOP=build
BUILD_DIR=$(BUILD_DIR_TOP)
#--------------------------------------------------------------------------------------
# The gcc compiler bin path can be either defined in make command via GCC_PATH variable
# (> make GCC_PATH=xxx) either it can be added to the PATH environment variable.
ifdef GCC_PATH
CC = $(GCC_PATH)/$(C_TOOLCHAIN_PREFIX)gcc
AS = $(GCC_PATH)/$(C_TOOLCHAIN_PREFIX)gcc -x assembler-with-cpp
CP = $(GCC_PATH)/$(C_TOOLCHAIN_PREFIX)objcopy
SZ = $(GCC_PATH)/$(C_TOOLCHAIN_PREFIX)size
AR = $(GCC_PATH)/$(C_TOOLCHAIN_PREFIX)ar
CCOV = $(GCC_PATH)/$(C_TOOLCHAIN_PREFIX)gcov
DUMP = $(GCC_PATH)/$(C_TOOLCHAIN_PREFIX)objdump
else
CC = $(C_TOOLCHAIN_PREFIX)gcc
AS = $(C_TOOLCHAIN_PREFIX)gcc -x assembler-with-cpp
CP = $(C_TOOLCHAIN_PREFIX)objcopy
SZ = $(C_TOOLCHAIN_PREFIX)size
AR = $(C_TOOLCHAIN_PREFIX)ar
CCOV = $(C_TOOLCHAIN_PREFIX)gcov
DUMP = $(C_TOOLCHAIN_PREFIX)objdump
endif
HEX = $(CP) -O ihex
BIN = $(CP) -O binary -S
# optimization
OPT = -Og
CFLAGS += $(CPU_ARCH_FLAGS) $(C_DEFS) $(C_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections -Wint-to-pointer-cast
ifeq ($(DEBUG), yes)
CFLAGS += -g -gdwarf-2
endif
# Generate dependency information
CFLAGS += -MMD -MP -MF"$(@:%.o=%.d)"
#######################################
# LDFLAGS
#######################################
# libraries
LIBS += -lc -lm $(EXTRA_LIBS)
LIBDIR =
# TODO: xxx.map should be platform-specific
LDFLAGS = $(CPU_ARCH_FLAGS) $(LD_SPECS_FILE) $(LDSCRIPT) $(LIBDIR) $(LIBS) -Wl,-Map=$<.map,--cref -Wl,--gc-sections
ifeq ($(MAKECMDGOALS), utest_helper) # if unit test is enabled
CFLAGS += -coverage
LDFLAGS += -coverage
endif
#######################################
# build the application
#######################################
# collect C/assembly objects compiled for library (may be built by cross-compile toolchain)
C_ASM_OBJECTS = $(addprefix $(BUILD_DIR)/,$(notdir $(C_SOURCES:.c=.o)))
vpath %.c $(sort $(dir $(C_SOURCES)))
C_ASM_OBJECTS += $(addprefix $(BUILD_DIR)/,$(notdir $(ASM_SOURCES:.s=.o)))
vpath %.s $(sort $(dir $(ASM_SOURCES)))
THIRD_PARTY_LIBS_PATH = \
third_party/MQTT_Client/build/libmqttclient.a \
third_party/MQTT_Client/third_party/libtomcrypt/libtomcrypt.a \
third_party/MQTT_Client/third_party/libtommath/libtommath.a
build_exe: $(BUILD_DIR)/station.elf $(BUILD_DIR)/station.text $(BUILD_DIR)/station.bin
$(BUILD_DIR)/%.o: %.c makefile | $(BUILD_DIR)
$(CC) -c $(CFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/$(notdir $(<:.c=.lst)) $< -o $@
$(BUILD_DIR)/%.o: %.s makefile | $(BUILD_DIR)
$(AS) -c $(CFLAGS) $< -o $@
%.elf: $(C_ASM_OBJECTS) $(THIRD_PARTY_LIBS_PATH)
$(CC) $^ $(LDFLAGS) -o $@
$(SZ) $@
%.bin: %.elf | $(BUILD_DIR)
$(BIN) $< $@
%.text: %.elf | $(BUILD_DIR)
$(DUMP) -Dh $< > $@
$(BUILD_DIR):
@mkdir -p $@
clean:
-rm -fR $(BUILD_DIR_TOP)
# optional function for those who use code navigation tools e.g. ctags
update_navigator:
@rm -rf ./tags; ctags -R ./include ./src ./third_party/MQTT_Client/third_party/ESP8266_AT_parser \
./third_party/MQTT_Client/src ./third_party/MQTT_Client/include ./third_party/jsmn
dbg_server:
@$(DBG_SERVER_CMD)
dbg_client:
@$(DBG_CLIENT_CMD)