-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile
143 lines (116 loc) · 4.04 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
# The driver is compiled in different ways, depending on what chip we are
# compiling for.
DEBUG_BUILD=1
STM_CHIP_SET=STM32F429_439xx
STM_DRIVER_PATH = $(HOME)/Documents/archives/STM32F4xx_DSP_StdPeriph_Lib_V1.3.0/Libraries/STM32F4xx_StdPeriph_Driver
STM_DRIVER_HDRS_STD = stm32f4xx_adc.h \
stm32f4xx_crc.h \
stm32f4xx_dbgmcu.h \
stm32f4xx_dma.h \
stm32f4xx_exti.h \
stm32f4xx_flash.h \
stm32f4xx_gpio.h \
stm32f4xx_i2c.h \
stm32f4xx_iwdg.h \
stm32f4xx_pwr.h \
stm32f4xx_rcc.h \
stm32f4xx_rtc.h \
stm32f4xx_sdio.h \
stm32f4xx_spi.h \
stm32f4xx_syscfg.h \
stm32f4xx_tim.h \
stm32f4xx_usart.h \
stm32f4xx_wwdg.h \
misc.h
STM_DRIVER_HDRS_F40_41 = stm32f4xx_cryp.h \
stm32f4xx_hash.h \
stm32f4xx_rng.h \
stm32f4xx_can.h \
stm32f4xx_dac.h \
stm32f4xx_dcmi.h \
stm32f4xx_fsmc.h
STM_DRIVER_HDRS_F427_437 = stm32f4xx_cryp.h \
stm32f4xx_hash.h \
stm32f4xx_rng.h \
stm32f4xx_can.h \
stm32f4xx_dac.h \
stm32f4xx_dcmi.h \
stm32f4xx_dma2d.h \
stm32f4xx_fmc.h \
stm32f4xx_sai.h
STM_DRIVER_HDRS_F429_439 = stm32f4xx_cryp.h \
stm32f4xx_hash.h \
stm32f4xx_rng.h \
stm32f4xx_can.h \
stm32f4xx_dac.h \
stm32f4xx_dcmi.h \
stm32f4xx_dma2d.h \
stm32f4xx_fmc.h \
stm32f4xx_ltdc.h \
stm32f4xx_sai.h
STM_DRIVER_SRCS = $(patsubst %.h, $(STM_DRIVER_PATH)/src/%.c, $(STM_DRIVER_HDRS_STD))
ifeq ($(STM_CHIP_SET), STM32F40_41xxx)
STM_DRIVER_SRCS += $(patsubst %.h, $(STM_DRIVER_PATH)/src/%.c, $(STM_DRIVER_HDRS_F40_41))
endif
ifeq ($(STM_CHIP_SET), STM32F427_437xx)
STM_DRIVER_SRCS += $(patsubst %.h, $(STM_DRIVER_PATH)/src/%.c, $(STM_DRIVER_HDRS_F427_437))
endif
ifeq ($(STM_CHIP_SET), STM32F429_439xx)
STM_DRIVER_SRCS += $(patsubst %.h, $(STM_DRIVER_PATH)/src/%.c, $(STM_DRIVER_HDRS_F429_439))
endif
STM_DRIVER_OBJS = $(STM_DRIVER_SRCS:$(STM_DRIVER_PATH)/src/%.c=objs/%.o)
STM_DRIVER_INC = $(STM_DRIVER_PATH)/inc
STM_DRIVER_DEP = inc/stm32f4xx_conf.h inc/stm32f4xx.h $(wildcard $(STM_DRIVER_INC)*.h)
CMSIS_PATH = $(HOME)/Documents/archives/CMSIS
PROJ_INC_PATH = inc
INC = $(PROJ_INC_PATH) $(CMSIS_PATH)/Include $(STM_DRIVER_INC)
PROJ_SRCS_PATH = src
PROJ_SRCS = $(wildcard $(PROJ_SRCS_PATH)/*.c)
PROJ_OBJS = $(patsubst $(PROJ_SRCS_PATH)/%, objs/%, $(addsuffix .o, $(basename $(PROJ_SRCS))))
PROJ_SRCS_ASM = $(wildcard $(PROJ_SRCS_PATH)/*.s)
PROJ_OBJS_ASM = $(patsubst $(PROJ_SRCS_PATH)/%, objs/%, $(addsuffix .o, $(basename $(PROJ_SRCS_ASM))))
PROJ_DEP = $(wildcard $(PROJ_INC_PATH)/*.h)
OBJS = $(STM_DRIVER_OBJS) $(PROJ_OBJS) $(PROJ_OBJS_ASM)
BIN = main.elf
# building for stm32f407 which is part of the family of chips with similar
# peripherals, therefore the following is defined
DEFS = USE_STDPERIPH_DRIVER $(STM_CHIP_SET)#STM32F429_439xx
CFLAGS = -ggdb3 -gdwarf-4 -Wall -ffunction-sections -fdata-sections
CFLAGS += -mlittle-endian -mthumb -mcpu=cortex-m4 -mthumb-interwork
CFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16 -O0 -dD
CFLAGS += $(foreach inc,$(INC),-I$(inc))
CFLAGS += $(foreach def,$(DEFS),-D$(def))
LDSCRIPT = STM32F429ZI_FLASH.ld
LDFLAGS = -T$(LDSCRIPT) -Xlinker
ifeq ($(DEBUG_BUILD),1)
LDFLAGS += --gc-sections
endif
CC = arm-none-eabi-gcc
OCD = sudo openocd \
-f /usr/share/openocd/scripts/board/stm32f4discovery.cfg
all: $(BIN)
driver: $(STM_DRIVER_OBJS)
proj: $(PROJ_OBJS)
# compile stm driver
$(STM_DRIVER_OBJS): objs/%.o: $(STM_DRIVER_PATH)/src/%.c $(STM_DRIVER_DEP)
$(CC) -c $(CFLAGS) $< -o $@
# compile asm
$(PROJ_OBJS_ASM): objs/%.o: $(PROJ_SRCS_PATH)/%.s $(PROJ_DEP)
$(CC) -c $(CFLAGS) $< -o $@
# compile c
$(PROJ_OBJS): objs/%.o: $(PROJ_SRCS_PATH)/%.c $(PROJ_DEP)
$(CC) -c $(CFLAGS) $< -o $@
$(BIN): $(OBJS)
$(CC) $(CFLAGS) $(LDFLAGS) $^ -o $@
flash: $(BIN)
$(OCD) -c init \
-c "reset halt" \
-c "flash write_image erase $(BIN)" \
-c "reset run" \
-c shutdown
clean:
rm objs/*
tags:
ctags -Ra . $(STM_DRIVER_PATH) $(CMSIS_PATH)
print:
$(info $(PROJ_DEP))