forked from RoboMaster/RoboRTS-Firmware
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
206 lines (164 loc) · 5.85 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
203
204
205
# STM32 Makefile for GNU toolchain and openocd
#
# This Makefile fetches the Cube firmware package from ST's' website.
# This includes: CMSIS, STM32 HAL, BSPs, USB drivers and examples.
#
# Usage:
# make cube Download and unzip Cube firmware
# make program Flash the board with OpenOCD
# make openocd Start OpenOCD
# make debug Start GDB and attach to OpenOCD
# make dirs Create subdirs like obj, dep, ..
# make template Prepare a simple example project in this dir
#
# Copyright 2015 Steffen Vogel
# License http://www.gnu.org/licenses/gpl.txt GNU Public License
# Author Steffen Vogel <[email protected]>
# Link http://www.steffenvogel.de
#
# edited for the STM32F4-Discovery
# A name common to all output files (elf, map, hex, bin, lst)
TARGET = demo
# Take a look into $(CUBE_DIR)/Drivers/BSP for available BSPs
# name needed in upper case and lower case
BOARD = STM32F446ZE-Nucleo
BOARD_UC = STM32F4xx_Nucleo_144
BOARD_LC = stm32f4xx_nucleo_144
BSP_BASE = $(BOARD_LC)
OCDFLAGS = -f board/stm32f4discovery.cfg
GDBFLAGS =
#EXAMPLE = Templates
#EXAMPLE = Examples/GPIO/GPIO_IOToggle
# MCU family and type in various capitalizations o_O
MCU_FAMILY = stm32f4xx
MCU_LC = stm32f427xx
MCU_MC = STM32F427xx
MCU_UC = STM32F427HL
# path of the ld-file inside the example directories
LDFILE = $(EXAMPLE)/SW4STM32/$(BOARD_UC)/$(MCU_UC)Tx_FLASH.ld
#LDFILE = $(EXAMPLE)/TrueSTUDIO/$(BOARD_UC)/$(MCU_UC)_FLASH.ld
# Your C files from the /src directory
SRCS = Src/main.c
SRCS += Src/system_$(MCU_FAMILY).c
SRCS += Src/stm32f4xx_it.c
SRCS += Middlewares/Third_Party/FreeRTOS/Source
SRCS += Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS
SRCS += Middlewares/Third_Party/FreeRTOS/Source/portable/RVDS/ARM_CM4F
# Basic HAL libraries
SRCS += stm32f4xx_hal_rcc.c stm32f4xx_hal_rcc_ex.c stm32f4xx_hal.c stm32f4xx_hal_cortex.c stm32f4xx_hal_gpio.c stm32f4xx_hal_pwr_ex.c $(BSP_BASE).c
# Directories
OCD_DIR = /usr/share/openocd/scripts
#CUBE_DIR = cube
#BSP_DIR = $(CUBE_DIR)/Drivers/BSP/$(BOARD_UC)
BSP_DIR = MDK-ARM/bsp
HAL_DIR = Drivers/STM32F4xx_HAL_Driver
CMSIS_DIR = Drivers/CMSIS
DEV_DIR = $(CMSIS_DIR)/Device/ST/STM32F4xx
CUBE_URL = http://www.st.com/st-web-ui/static/active/en/st_prod_software_internet/resource/technical/software/firmware/stm32cubef4.zip
# that's it, no need to change anything below this line!
###############################################################################
# Toolchain
PREFIX = arm-none-eabi
CC = $(PREFIX)-gcc
AR = $(PREFIX)-ar
OBJCOPY = $(PREFIX)-objcopy
OBJDUMP = $(PREFIX)-objdump
SIZE = $(PREFIX)-size
GDB = $(PREFIX)-gdb
OCD = openocd
###############################################################################
# Options
# Defines
DEFS = -D$(MCU_MC) -DUSE_HAL_DRIVER
# Debug specific definitions for semihosting
DEFS += -DUSE_DBPRINTF
# Include search paths (-I)
INCS = -IInc
INCS += -I$(BSP_DIR)
INCS += -I$(CMSIS_DIR)/Include
INCS += -I$(DEV_DIR)/Include
INCS += -I$(HAL_DIR)/Inc
INCS += -IMiddlewares/Third_Party/FreeRTOS/Source/include
INCS += -IMiddlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS
INCS += -IMiddlewares/Third_Party/FreeRTOS/Source/portable/RVDS/ARM_CM4F
# Library search paths
LIBS = -L$(CMSIS_DIR)/Lib
# Compiler flags
CFLAGS = -Wall -g -std=c99 -Os
CFLAGS += -mlittle-endian -mcpu=cortex-m4 -march=armv7e-m -mthumb
CFLAGS += -mfpu=fpv4-sp-d16 -mfloat-abi=hard
CFLAGS += -ffunction-sections -fdata-sections
CFLAGS += $(INCS) $(DEFS)
# Linker flags
LDFLAGS = -Wl,--gc-sections -Wl,-Map=$(TARGET).map $(LIBS) -T$(MCU_LC).ld
# Enable Semihosting
LDFLAGS += --specs=rdimon.specs -lc -lrdimon
# Source search paths
VPATH = ./src
VPATH += $(BSP_DIR)
VPATH += $(HAL_DIR)/Src
VPATH += $(DEV_DIR)/Source/
OBJS = $(addprefix obj/,$(SRCS:.c=.o))
DEPS = $(addprefix dep/,$(SRCS:.c=.d))
# Prettify output
V = 0
ifeq ($V, 0)
Q = @
P = > /dev/null
endif
###################################################
.PHONY: all dirs program debug template clean
all: $(TARGET).bin
-include $(DEPS)
dirs: dep obj cube
dep obj src:
@echo "[MKDIR] $@"
$Qmkdir -p $@
obj/%.o : %.c | dirs
@echo "[CC] $(notdir $<)"
$Q$(CC) $(CFLAGS) -c -o $@ $< -MMD -MF dep/$(*F).d
$(TARGET).elf: $(OBJS)
@echo "[LD] $(TARGET).elf"
$Q$(CC) $(CFLAGS) $(LDFLAGS) src/startup_$(MCU_LC).s $^ -o $@
@echo "[OBJDUMP] $(TARGET).lst"
$Q$(OBJDUMP) -St $(TARGET).elf >$(TARGET).lst
@echo "[SIZE] $(TARGET).elf"
$(SIZE) $(TARGET).elf
$(TARGET).bin: $(TARGET).elf
@echo "[OBJCOPY] $(TARGET).bin"
$Q$(OBJCOPY) -O binary $< $@
openocd:
$(OCD) -s $(OCD_DIR) $(OCDFLAGS)
program: all
$(OCD) -s $(OCD_DIR) $(OCDFLAGS) -c "program $(TARGET).elf verify reset"
debug:
@if ! nc -z localhost 3333; then \
echo "\n\t[Error] OpenOCD is not running! Start it with: 'make openocd'\n"; exit 1; \
else \
$(GDB) -ex "target extended localhost:3333" \
-ex "monitor arm semihosting enable" \
-ex "monitor reset halt" \
-ex "load" \
-ex "monitor reset init" \
$(GDBFLAGS) $(TARGET).elf; \
fi
cube:
#rm -fr $(CUBE_DIR)
#wget -O /tmp/cube.zip $(CUBE_URL)
#unzip /tmp/cube.zip
#mv STM32Cube* $(CUBE_DIR)
#chmod -R u+w $(CUBE_DIR)
#rm -f /tmp/cube.zip
echo " update cube"
template: cube src
cp -ri $(CUBE_DIR)/Projects/$(BOARD)/$(EXAMPLE)/Src/* src
cp -ri $(CUBE_DIR)/Projects/$(BOARD)/$(EXAMPLE)/Inc/* src
cp -i $(DEV_DIR)/Source/Templates/gcc/startup_$(MCU_LC).s src
cp -i $(CUBE_DIR)/Projects/$(BOARD)/$(LDFILE) $(MCU_LC).ld
clean:
@echo "[RM] $(TARGET).bin"; rm -f $(TARGET).bin
@echo "[RM] $(TARGET).elf"; rm -f $(TARGET).elf
@echo "[RM] $(TARGET).map"; rm -f $(TARGET).map
@echo "[RM] $(TARGET).lst"; rm -f $(TARGET).lst
@echo "[RMDIR] dep" ; rm -fr dep
@echo "[RMDIR] obj" ; rm -fr obj