-
Notifications
You must be signed in to change notification settings - Fork 9
/
Makefile
100 lines (72 loc) · 2.7 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
#
# GNU Makefile for a template STM32F3 project
#
#
# Your *.c source files here:
SRCS = \
main.c errno.c hw_config.c stm32f30x_it.c stm32f3_discovery.c system_stm32f30x.c \
usb_desc.c usb_endp.c usb_istr.c usb_prop.c usb_pwr.c
# all the files will be generated with this name (main.elf, main.bin, main.hex, etc)
PROJ_NAME=main
# Location of the Libraries folder from the STM32F0xx Standard Peripheral Library
STD_PERIPH_LIB = ../STM32F3-Discovery_FW_V1.1.0/inst
# Location of the linker scripts
LDSCRIPT_INC=Device/ldscripts
# location of OpenOCD Board .cfg files (only used with 'make program')
OPENOCD_BOARD_DIR=/usr/local/arm/share/openocd/scripts/board
# Configuration (cfg) file containing programming directives for OpenOCD
OPENOCD_PROC_FILE=extra/stm32f3-openocd.cfg
# that's it, no need to change anything below this line!
###################################################
PREFIX = arm-none-eabi-
CC=$(PREFIX)gcc
AR=$(PREFIX)ar
GDB=$(PREFIX)gdb
OBJCOPY=$(PREFIX)objcopy
OBJDUMP=$(PREFIX)objdump
SIZE=$(PREFIX)size
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
LDFLAGS += -Wl,--gc-sections -Wl,-Map=$(PROJ_NAME).map
###################################################
vpath %.a $(STD_PERIPH_LIB)
CFLAGS += -include $(STD_PERIPH_LIB)/stm32f30x_conf.h -I $(STD_PERIPH_LIB)
STARTUP = Device/startup_stm32f30x.s # add startup file to build
# need if you want to build with -DUSE_CMSIS
#SRCS += stm32f0_discovery.c
#SRCS += stm32f0_discovery.c stm32f0xx_it.c
OBJS = $(addprefix objs/,$(SRCS:.c=.o))
DEPS = $(addprefix deps/,$(SRCS:.c=.d))
###################################################
.PHONY: all proj program debug clean reallyclean
all: proj
-include $(DEPS)
proj: $(PROJ_NAME).elf
dirs: deps objs
deps objs:
@mkdir -p $@
objs/%.o : src/%.c dirs
$(CC) $(CFLAGS) -c -o $@ $< -MMD -MF deps/$(*F).d
$(PROJ_NAME).elf: $(OBJS)
$(CC) $(CFLAGS) $(LDFLAGS) $^ -o $@ $(STARTUP) -L$(STD_PERIPH_LIB) -lstm32f3-util -lstm32f3 -L$(LDSCRIPT_INC) -Tstm32f3.ld
$(OBJCOPY) -O ihex $(PROJ_NAME).elf $(PROJ_NAME).hex
$(OBJCOPY) -O binary $(PROJ_NAME).elf $(PROJ_NAME).bin
$(OBJDUMP) -St $(PROJ_NAME).elf >$(PROJ_NAME).lst
$(SIZE) $(PROJ_NAME).elf
program: all
openocd -f $(OPENOCD_BOARD_DIR)/stm32f3discovery.cfg -f $(OPENOCD_PROC_FILE) -c "stm_flash `pwd`/$(PROJ_NAME).bin" -c shutdown
debug: program
$(GDB) --tui -x extra/gdb_cmds $(PROJ_NAME).elf
clean:
find ./ -name '*~' | xargs rm -f
rm -f objs/*.o
rm -f deps/*.d
rm -f $(PROJ_NAME).elf
rm -f $(PROJ_NAME).hex
rm -f $(PROJ_NAME).bin
rm -f $(PROJ_NAME).map
rm -f $(PROJ_NAME).lst
rm -f openocd.log
-rmdir deps objs