-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
126 lines (92 loc) · 2.98 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
#######################################################################
# Makefile for STM32F4 Discovery board projects
OUTPATH = build
PROJECT = $(OUTPATH)/robotflesh
OPENOCD_SCRIPT_DIR ?= /usr/share/openocd/scripts
HEAP_SIZE = 0x500
################
# Sources
SOURCES_S = core/startup_stm32f407xx.s
SOURCES_RTOS = $(wildcard freertos/*.c freertos/portable/GCC/ARM_CM4F/*.c)
SOURCES_RTOS += $(wildcard freertos/portable/MemMang/*.c)
SOURCES_CORE = $(wildcard core/*.c)
SOURCES_PERIPH = $(wildcard plib/*.c)
SOURCES_ARM_MATH = $(wildcard math/*.c)
SOURCES_C = $(wildcard *.c old/*.c lib/*.c)
SOURCES_C += $(SOURCES_RTOS)
SOURCES_C += $(SOURCES_CORE)
SOURCES_C += $(SOURCES_PERIPH)
SOURCES_C += $(SOURCES_ARM_MATH)
SOURCES = $(SOURCES_S) $(SOURCES_C)
OBJS = $(SOURCES_S:.s=.o) $(SOURCES_C:.c=.o)
# Includes and Defines
INC_RTOS = -Ifreertos -Ifreertos/include -Ifreertos/portable/GCC/ARM_CM4F
INC_CORE = -Icore
INC_PERIPH = -Iplib
INC_ARM_MATH = -Imath
INCLUDES = -Iold -Ilib
INCLUDES += $(INC_RTOS)
INCLUDES += $(INC_CORE)
INCLUDES += $(INC_PERIPH)
INCLUDES += $(INC_ARM_MATH)
DEFINES = -DSTM32 -DSTM32F4 -DSTM32F407xx -DHEAP_SIZE=$(HEAP_SIZE)
DEFINES += -DARM_MATH_CM4
# Compiler/Assembler/Linker/etc
PREFIX = arm-none-eabi
CC = $(PREFIX)-gcc
AS = $(PREFIX)-as
AR = $(PREFIX)-ar
LD = $(PREFIX)-gcc
NM = $(PREFIX)-nm
OBJCOPY = $(PREFIX)-objcopy
OBJDUMP = $(PREFIX)-objdump
READELF = $(PREFIX)-readelf
SIZE = $(PREFIX)-size
GDB = $(PREFIX)-gdb
RM = rm -f
OPENOCD=openocd
# Compiler options
MCUFLAGS = -mcpu=cortex-m4 -mlittle-endian -mfloat-abi=hard -mfpu=fpv4-sp-d16 \
-mthumb -fsingle-precision-constant -mno-unaligned-access
DEBUG_OPTIMIZE_FLAGS = -O0 -ggdb -gdwarf-2
CFLAGS = -Wall -Wextra
CFLAGS_EXTRA = -nostartfiles -nodefaultlibs -nostdlib\
-fdata-sections -ffunction-sections
CFLAGS += $(DEFINES) $(MCUFLAGS) $(DEBUG_OPTIMIZE_FLAGS) $(CFLAGS_EXTRA) $(INCLUDES)
LDFLAGS = -static $(MCUFLAGS) -Wl,--start-group -lgcc -lc -lg -Wl,--end-group \
-Wl,--gc-sections -T STM32F407VGTx_FLASH.ld -specs=nosys.specs \
-u _printf_float
#-u _scanf_float
.PHONY: dirs all clean flash erase
all: dirs $(PROJECT).bin $(PROJECT).asm
dirs: ${OUTPATH}
${OUTPATH}:
mkdir -p ${OUTPATH}
clean:
$(RM) $(OBJS) $(PROJECT).elf $(PROJECT).bin $(PROJECT).asm
# Hardware specific
flash: $(PROJECT).bin
st-flash write $(PROJECT).bin 0x08000000
erase:
st-flash erase
gdb-server-ocd:
$(OPENOCD) -f $(OPENOCD_SCRIPT_DIR)/interface/stlink-v2.cfg \
-f $(OPENOCD_SCRIPT_DIR)/board/stm32f4discovery.cfg
gdb-server-st:
st-util
OPENOCD_P=3333
gdb-openocd: $(PROJECT).elf
$(GDB) --eval-command="target extended-remote localhost:$(OPENOCD_P)"\
--eval-command="monitor halt" $(PROJECT).elf
GDB_P=4242
gdb-st-util: $(PROJECT).elf
$(GDB) --eval-command="target extended-remote localhost:$(GDB_P)"\
--eval-command="monitor halt" $(PROJECT).elf
$(PROJECT).elf: $(OBJS)
%.elf:
$(LD) $(OBJS) $(LDFLAGS) -o $@
$(SIZE) -A $@
%.bin: %.elf
$(OBJCOPY) -O binary $< $@
%.asm: %.elf
$(OBJDUMP) -dwh $< > $@