-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
144 lines (92 loc) · 3.56 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
# Makefile: Jihed Chaibi - 2020
#######################
# Binaries will be generated with this name (.elf, .bin, .hex, etc)
PROJ_NAME=output_fmw
#######################################################################################
CC=arm-none-eabi-gcc
GDB=gdb-multiarch
OBJCOPY=arm-none-eabi-objcopy
# Source Files
SRCS = src/*.c
SRCS += board_include/drivers/src/*.c
SRCS += board_include/startup/startup_stm32.S
# Compiler Flags
CFLAGS = -g -O0 -Wall -T board_include/LinkerScript.ld -D USE_STDPERIPH_DRIVER
CFLAGS += -mlittle-endian -mthumb -mcpu=cortex-m4 -mthumb-interwork
CFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16
CFLAGS += --specs=nosys.specs
# Header Files (-I flag)
CFLAGS += -I inc/
CFLAGS += -I board_include/
CFLAGS += -I board_include/include/
CFLAGS += -I board_include/drivers/inc/
CFLAGS += -I board_include/cmsis/include/
#######################################################################################
.PHONY: output_fmw
all: output_fmw
output_fmw: $(PROJ_NAME).elf
$(PROJ_NAME).elf: $(SRCS)
$(CC) $(CFLAGS) $^ -o output/$@
$(OBJCOPY) -O ihex output/$(PROJ_NAME).elf output/$(PROJ_NAME).hex
$(OBJCOPY) -O binary output/$(PROJ_NAME).elf output/$(PROJ_NAME).bin
clean:
rm -f *.o output/$(PROJ_NAME).elf output/$(PROJ_NAME).hex output/$(PROJ_NAME).bin
@echo "clean as a whistle!"
############################################
#### OPENOCD STUFF #####
HEXFILE = ./output/output_fmw.hex
ELFFILE = ./output/output_fmw.elf
#The path of OpenOCD will change automatically according to the OS (using the check_os)
#However, you can change it manually.
OPENOCD_PATH = /usr/share/openocd
export OPENOCD_BIN = openocd
#I'm using the nucleo STM32F401RE (F4 family)
#change this according to the family of your board
export OPENOCD_BOARD = $(OPENOCD_PATH)/scripts/board/st_nucleo_f4.cfg
############# FLASH #############
OPENOCD_FLASH_CMDS += -c 'reset halt'
OPENOCD_FLASH_CMDS += -c 'sleep 10'
OPENOCD_FLASH_CMDS += -c 'flash protect 0 0 7 off'
OPENOCD_FLASH_CMDS += -c 'halt'
OPENOCD_FLASH_CMDS += -c 'flash write_image erase $(HEXFILE) 0 ihex'
OPENOCD_FLASH_CMDS += -c shutdown
export OPENOCD_FLASH_CMDS
############# ERASE #############
OPENOCD_ERASE_CMDS += -c 'reset halt'
OPENOCD_ERASE_CMDS += -c 'sleep 10'
OPENOCD_ERASE_CMDS += -c 'sleep 10'
OPENOCD_ERASE_CMDS += -c 'flash erase_address 0x08000000 0x00080000'
OPENOCD_ERASE_CMDS += -c shutdown
export OPENOCD_ERASE_CMDS
############# DEBUG #############
OPENOCD_DEBUG_CMDS += -c 'halt'
OPENOCD_DEBUG_CMDS += -c 'sleep 10'
export OPENOCD_DEBUG_CMDS
########################################################################
flash: check_os
$(OPENOCD_BIN) -f $(OPENOCD_BOARD) -c init $(OPENOCD_FLASH_CMDS)
erase: check_os
$(OPENOCD_BIN) -f $(OPENOCD_BOARD) -c init $(OPENOCD_ERASE_CMDS)
run: check_os
$(OPENOCD_BIN) -f $(OPENOCD_BOARD) -c init $(OPENOCD_RUN_CMDS)
debug: check_os
$(OPENOCD_BIN) -f $(OPENOCD_BOARD) -c init $(OPENOCD_DEBUG_CMDS)
gdb: check_os
$(GDB) $(GDB_FLAGS) --eval-command="target remote localhost:3333" ./output/$(PROJ_NAME).elf
##################################### CHECK OS #########################
check_os:
ifeq ($(OS),Windows_NT)
OSFLAG += Windows
OPENOCD_PATH = C:/openocd
GDB=arm-none-eabi-gdb
GDB_FLAGS=
else
ifeq ($(shell uname -s),Linux)
OSFLAG += Linux
OPENOCD_PATH = /usr/share/openocd
GDB=gdb-multiarch
GDB_FLAGS=-tui
endif
endif
print_os: check_os
@echo $(OSFLAG)