-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
154 lines (125 loc) · 4.33 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
145
146
147
148
149
150
151
152
153
154
#
# Makefile for simple monitor on STM32F3 Discovery Board
#
# openocd -f board/stm32f3discovery.cfg -c "init" -c "halt" -c "flash write_image erase simple_monitor.elf" -c "reset run" -c shutdown
# C source files for the project
PROJ_NAME = simple_monitor
SRCS = main.c
# Simple Monitor sources
SRCS += monitor.c uart.c parser.c dump.c syscall.c terminal.c \
decoder/decoder.c decoder/STM32F30x_decoder.c \
printf_stdarg.c mytest.c mycode.s
###################################################
# Location of the linker scripts
LDSCRIPT_INC=ld
# Location of CMSIS files for our device
CMSIS = Drivers/CMSIS
CMSIS_INC = $(CMSIS)/Include
CMSIS_DEV = $(CMSIS)/Device/ST/STM32F3xx
CMSIS_DEV_INC = $(CMSIS_DEV)/Include
CMSIS_DEV_SRC = $(CMSIS_DEV)/Source/Templates
SRCS += $(CMSIS_DEV_SRC)/system_stm32f3xx.c
# Location of HAL drivers
HAL = Drivers/STM32F3xx_HAL_Driver
HAL_INC = $(HAL)/Inc
HAL_SRC = $(HAL)/Src
SRCS += $(HAL_SRC)/stm32f3xx_hal_rcc.c \
$(HAL_SRC)/stm32f3xx_hal.c \
$(HAL_SRC)/stm32f3xx_hal_cortex.c \
$(HAL_SRC)/stm32f3xx_hal_uart.c \
$(HAL_SRC)/stm32f3xx_hal_gpio.c \
$(HAL_SRC)/stm32f3xx_hal_pcd.c \
$(HAL_SRC)/stm32f3xx_hal_pcd_ex.c \
$(HAL_SRC)/stm32f3xx_hal_i2c.c \
$(HAL_SRC)/stm32f3xx_hal_spi.c
# USB Sources
USB_CORE = Drivers/STM32_USB_Device_Library/Core
USB_CORE_INC = $(USB_CORE)/Inc
USB_CORE_SRC = $(USB_CORE)/Src
SRCS += $(USB_CORE_SRC)/usbd_core.c \
$(USB_CORE_SRC)/usbd_ctlreq.c \
$(USB_CORE_SRC)/usbd_ioreq.c
USB_CLASS = Drivers/STM32_USB_Device_Library/Class/CDC
USB_CLASS_INC = $(USB_CLASS)/Inc
USB_CLASS_SRC = $(USB_CLASS)/Src
SRCS += $(USB_CLASS_SRC)/usbd_cdc.c \
usbd_conf.c usbd_desc.c usbd_cdc_interface.c
# Location of BSP Files
BSP = Drivers/BSP/STM32F3-Discovery
BSP_INC = $(BSP)
BSP_SRC = $(BSP)
SRCS += $(BSP)/stm32f3_discovery.c \
$(BSP)/stm32f3_discovery_accelerometer.c \
$(BSP)/stm32f3_discovery_gyroscope.c
# Location of Component Files
CMP = Drivers/BSP/Components
CMP_INC = $(CMP)
CMP_SRC = $(CMP)
SRCS += $(CMP)/lsm303dlhc/lsm303dlhc.c \
$(CMP)/l3gd20/l3gd20.c
PREFIX = arm-none-eabi-
CC=$(PREFIX)gcc
AR=$(PREFIX)ar
AS=$(PREFIX)as
GDB=$(PREFIX)gdb
OBJCOPY=$(PREFIX)objcopy
OBJDUMP=$(PREFIX)objdump
SIZE=$(PREFIX)size
#CFLAGS = -Wall -g -std=c99 -Os
CFLAGS = -Wall -g -std=gnu99
CFLAGS += -Os
CFLAGS += -Werror
CFLAGS += -mlittle-endian -mcpu=cortex-m4 -march=armv7e-m
CFLAGS += -mthumb
CFLAGS += -mfpu=fpv4-sp-d16 -mfloat-abi=softfp
CFLAGS += -ffunction-sections -fdata-sections
CFLAGS += -I .
CFLAGS += -I $(CMSIS_INC)
CFLAGS += -I $(CMSIS_DEV_INC)
CFLAGS += -DSTM32F303xC
CFLAGS += -I $(HAL_INC)
CFLAGS += -I $(BSP_INC)
CFLAGS += -I $(USB_CORE_INC)
CFLAGS += -I $(USB_CLASS_INC)
LDFLAGS = -Wall -g -std=c99 -Os
LDFLAGS += -mlittle-endian -mcpu=cortex-m4 -march=armv7e-m
LDFLAGS += -Wl,--gc-sections -Wl,-Map=$(PROJ_NAME).map
LDFLAGS += -mthumb
LDFLAGS += -mfpu=fpv4-sp-d16 -mfloat-abi=softfp
LDFLAGS += -ffunction-sections -fdata-sections
ASFLAGS = -Wall -g -mlittle-endian -mcpu=cortex-m4 -march=armv7e-m
ASFLAGS += -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=softfp
###################################################
STARTUP = $(CMSIS_DEV_SRC)/gcc/startup_stm32f303xc.o # add startup file to build
OBJS = $(addsuffix .o,$(basename $(SRCS)))
DEPS = $(addprefix deps/,$(SRCS:.c=.d))
###################################################
.PHONY: all proj program debug clean reallyclean
all: proj
-include $(DEPS)
proj: $(PROJ_NAME).elf
deps:
@mkdir -p $@
%.o : %.c deps
$(CC) $(CFLAGS) -c -o $@ $< -MMD -MF deps/$(*F).d
$(PROJ_NAME).elf: $(OBJS) $(STARTUP)
$(CC) $(LDFLAGS) $^ -o $@ -L$(STD_PERIPH_LIB) -lstm32f3 -L$(LDSCRIPT_INC) -Tsimple_monitor.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 board/stm32f3discovery.cfg -c "init" -c "reset init" -c "halt" -c "flash write_image erase $(PROJ_NAME).elf" -c "reset run" -c shutdown
debug: program
$(GDB) --tui -x gdb/gdb_cmds $(PROJ_NAME).elf
clean:
find ./ -name '*~' | xargs rm -f
find ./ -name '*.o' | xargs rm -f
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