-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathMakefile
executable file
·115 lines (88 loc) · 3.73 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
# Name of the binaries.
PROJ_NAME=blinky
######################################################################
# SETUP SOURCES #
######################################################################
# This is the directory containing the firmware package,
# the unzipped folder downloaded from here:
# http://www.st.com/web/en/catalog/tools/PF257904
STM_DIR=../STM32F4-Discovery_FW_V1.1.0
# This is where the source files are located,
# which are not in the current directory
# (the sources of the standard peripheral library, which we use)
# see also "info:/make/Selective Search" in Konqueror
STM_SRC = $(STM_DIR)/Libraries/STM32F4xx_StdPeriph_Driver/src
# Tell make to look in that folder if it cannot find a source
# in the current directory
vpath %.c $(STM_SRC)
# My source file
SRCS = main.c
# Contains initialisation code and must be compiled into
# our project. This file is in the current directory and
# was writen by ST.
SRCS += system_stm32f4xx.c
# These source files implement the functions we use.
# make finds them by searching the vpath defined above.
SRCS += stm32f4xx_rcc.c
SRCS += stm32f4xx_gpio.c
# Startup file written by ST
# The assembly code in this file is the first one to be
# executed. Normally you do not change this file.
SRCS += $(STM_DIR)/Libraries/CMSIS/ST/STM32F4xx/Source/Templates/TrueSTUDIO/startup_stm32f4xx.s
# The header files we use are located here
INC_DIRS = $(STM_DIR)/Utilities/STM32F4-Discovery
INC_DIRS += $(STM_DIR)/Libraries/CMSIS/Include
INC_DIRS += $(STM_DIR)/Libraries/CMSIS/ST/STM32F4xx/Include
INC_DIRS += $(STM_DIR)/Libraries/STM32F4xx_StdPeriph_Driver/inc
INC_DIRS += .
# in case we have to many sources and don't want
# to compile all sources every time
# OBJS = $(SRCS:.c=.o)
######################################################################
# SETUP TOOLS #
######################################################################
# This is the path to the toolchain
# (we don't put our toolchain on $PATH to keep the system clean)
TOOLS_DIR = /opt/gcc-arm-embedded/gcc-arm-none-eabi-4_7-2013q1/bin
# The tool we use
CC = $(TOOLS_DIR)/arm-none-eabi-gcc
OBJCOPY = $(TOOLS_DIR)/arm-none-eabi-objcopy
GDB = $(TOOLS_DIR)/arm-none-eabi-gdb
## Preprocessor options
# directories to be searched for header files
INCLUDE = $(addprefix -I,$(INC_DIRS))
# #defines needed when working with the STM library
DEFS = -DUSE_STDPERIPH_DRIVER
# if you use the following option, you must implement the function
# assert_failed(uint8_t* file, uint32_t line)
# because it is conditionally used in the library
# DEFS += -DUSE_FULL_ASSERT
## Compiler options
CFLAGS = -ggdb
# please do not optimize anything because we are debugging
CFLAGS += -O0
CFLAGS += -Wall -Wextra -Warray-bounds
CFLAGS += -mlittle-endian -mthumb -mcpu=cortex-m4 -mthumb-interwork
CFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16
## Linker options
# tell ld which linker file to use
# (this file is in the current directory)
LFLAGS = -Tstm32_flash.ld
######################################################################
# SETUP TARGETS #
######################################################################
.PHONY: $(PROJ_NAME)
$(PROJ_NAME): $(PROJ_NAME).elf
$(PROJ_NAME).elf: $(SRCS)
$(CC) $(INCLUDE) $(DEFS) $(CFLAGS) $(LFLAGS) $^ -o $@
$(OBJCOPY) -O ihex $(PROJ_NAME).elf $(PROJ_NAME).hex
$(OBJCOPY) -O binary $(PROJ_NAME).elf $(PROJ_NAME).bin
clean:
rm -f *.o $(PROJ_NAME).elf $(PROJ_NAME).hex $(PROJ_NAME).bin
# Flash the STM32F4
flash:
st-flash write $(PROJ_NAME).bin 0x8000000
.PHONY: debug
debug:
# before you start gdb, you must start st-util
$(GDB) $(PROJ_NAME).elf