Makefile 6.37 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
# Select the board to build for: if not given on the command line,
# then default to PYBV10.
BOARD ?= PYBV10
ifeq ($(wildcard boards/$(BOARD)/.),)
$(error Invalid BOARD specified)
endif

# If the build directory is not given, make it reflect the board name.
BUILD ?= build-$(BOARD)

Dave Hylands's avatar
Dave Hylands committed
11
12
13
include ../py/mkenv.mk

# qstr definitions (must come before including py.mk)
14
QSTR_DEFS = qstrdefsport.h $(BUILD)/pins_qstr.h
Dave Hylands's avatar
Dave Hylands committed
15
16
17
18
19
20

# include py core make definitions
include ../py/py.mk

CMSIS_DIR=cmsis
HAL_DIR=hal
21
22
USBDEV_DIR=usbdev
#USBHOST_DIR=usbhost
23
FATFS_DIR=fatfs
24
CC3K_DIR=cc3k
Dave Hylands's avatar
Dave Hylands committed
25
DFU=../tools/dfu.py
26
# may need to prefix dfu-util with sudo
27
DFU_UTIL ?= dfu-util
28
DEVICE=0483:df11
Dave Hylands's avatar
Dave Hylands committed
29
30
31
32
33

CROSS_COMPILE = arm-none-eabi-

INC =  -I.
INC += -I$(PY_SRC)
34
INC += -I$(BUILD)
Dave Hylands's avatar
Dave Hylands committed
35
36
37
INC += -I$(CMSIS_DIR)/inc
INC += -I$(CMSIS_DIR)/devinc
INC += -I$(HAL_DIR)/inc
38
INC += -I$(USBDEV_DIR)/core/inc -I$(USBDEV_DIR)/class/cdc_msc_hid/inc
39
#INC += -I$(USBHOST_DIR)
40
INC += -I$(FATFS_DIR)/src
41
INC += -I$(CC3K_DIR)
Dave Hylands's avatar
Dave Hylands committed
42
43

CFLAGS_CORTEX_M4 = -mthumb -mtune=cortex-m4 -mabi=aapcs-linux -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -fsingle-precision-constant -Wdouble-promotion
44
CFLAGS = $(INC) -Wall -Werror -ansi -std=gnu99 -nostdlib $(CFLAGS_CORTEX_M4) $(COPT)
Dave Hylands's avatar
Dave Hylands committed
45
46
47
48
49
50
51
52
53
54
55

CFLAGS += -Iboards/$(BOARD)

#Debugging/Optimization
ifeq ($(DEBUG), 1)
CFLAGS += -g -DPENDSV_DEBUG
COPT = -O0
else
COPT += -Os -DNDEBUG
endif

56
LDFLAGS = -nostdlib -T stm32f405.ld -Map=$(@:.elf=.map) --cref
Dave Hylands's avatar
Dave Hylands committed
57
58
59
60
61
62
63
LIBS =

# uncomment this if you want libgcc
#LIBS += $(shell $(CC) -print-libgcc-file-name)

SRC_C = \
	main.c \
64
	string0.c \
Dave Hylands's avatar
Dave Hylands committed
65
	system_stm32f4xx.c \
66
67
	stm32f4xx_it.c \
	stm32f4xx_hal_msp.c \
68
	usbd_conf.c \
69
	usbd_desc_cdc_msc.c \
70
	usbd_cdc_interface.c \
71
	usbd_msc_storage.c \
72
	pendsv.c \
73
	systick.c  \
74
	timer.c \
75
76
	led.c \
	pin.c \
77
	pin_defs_stmhal.c \
78
	pin_named_pins.c \
Damien George's avatar
Damien George committed
79
80
81
82
	bufhelper.c \
	i2c.c \
	spi.c \
	uart.c \
83
	usb.c \
84
85
	printf.c \
	math.c \
86
	mathsincos.c \
87
	gccollect.c \
88
89
	pybstdio.c \
	readline.c \
90
	pyexec.c \
Damien George's avatar
Damien George committed
91
	help.c \
92
	input.c \
93
	modos.c \
94
95
	modpyb.c \
	modstm.c \
96
	modtime.c \
97
98
	import.c \
	lexerfatfs.c \
99
	extint.c \
100
	usrsw.c \
101
	rng.c \
Damien George's avatar
Damien George committed
102
	rtc.c \
103
104
	flash.c \
	storage.c \
105
	file.c \
Damien George's avatar
Damien George committed
106
	sdcard.c \
107
	diskio.c \
108
	ffconf.c \
109
	lcd.c \
110
	accel.c \
Damien George's avatar
Damien George committed
111
	servo.c \
Damien George's avatar
Damien George committed
112
	dac.c \
Dave Hylands's avatar
Dave Hylands committed
113
	adc.c \
114
	pybwlan.c \
Dave Hylands's avatar
Dave Hylands committed
115
116
117

SRC_S = \
	startup_stm32f40xx.s \
118
	gchelper.s \
Dave Hylands's avatar
Dave Hylands committed
119
120
121

SRC_HAL = $(addprefix $(HAL_DIR)/src/,\
	stm32f4xx_hal.c \
Dave Hylands's avatar
Dave Hylands committed
122
123
	stm32f4xx_hal_adc.c \
	stm32f4xx_hal_adc_ex.c \
Dave Hylands's avatar
Dave Hylands committed
124
	stm32f4xx_hal_cortex.c \
Damien George's avatar
Damien George committed
125
126
	stm32f4xx_hal_dac.c \
	stm32f4xx_hal_dac_ex.c \
127
	stm32f4xx_hal_dma.c \
128
129
	stm32f4xx_hal_flash.c \
	stm32f4xx_hal_flash_ex.c \
130
	stm32f4xx_hal_gpio.c \
131
	stm32f4xx_hal_i2c.c \
132
	stm32f4xx_hal_pcd.c \
133
	stm32f4xx_hal_pcd_ex.c \
134
	stm32f4xx_hal_rcc.c \
Damien George's avatar
Damien George committed
135
	stm32f4xx_hal_rcc_ex.c \
136
	stm32f4xx_hal_rng.c \
Damien George's avatar
Damien George committed
137
138
	stm32f4xx_hal_rtc.c \
	stm32f4xx_hal_rtc_ex.c \
Damien George's avatar
Damien George committed
139
	stm32f4xx_hal_sd.c \
Damien George's avatar
Damien George committed
140
	stm32f4xx_hal_spi.c \
141
142
	stm32f4xx_hal_tim.c \
	stm32f4xx_hal_tim_ex.c \
143
	stm32f4xx_hal_uart.c \
Damien George's avatar
Damien George committed
144
	stm32f4xx_ll_sdmmc.c \
145
	stm32f4xx_ll_usb.c \
Dave Hylands's avatar
Dave Hylands committed
146
147
	)

148
149
150
151
SRC_USBDEV = $(addprefix $(USBDEV_DIR)/,\
	core/src/usbd_core.c \
	core/src/usbd_ctlreq.c \
	core/src/usbd_ioreq.c \
152
153
154
155
	class/cdc_msc_hid/src/usbd_cdc_msc_hid.c \
	class/cdc_msc_hid/src/usbd_msc_bot.c \
	class/cdc_msc_hid/src/usbd_msc_scsi.c \
	class/cdc_msc_hid/src/usbd_msc_data.c \
156
157
	)

158
159
#	class/cdc/src/usbd_cdc.c \
	class/msc/src/usbd_msc.c \
160
#	usbd_core.c \
Dave Hylands's avatar
Dave Hylands committed
161
162
163
164
165
166
167
168
169
170
171
172
173
	usbd_ioreq.c \
	usbd_req.c \
	usbd_usr.c \
	usbd_desc.c \
	usbd_pyb_core.c \
	usbd_pyb_core2.c \
	usbd_cdc_vcp.c \
	usbd_msc_bot.c  \
	usbd_msc_data.c \
	usbd_msc_scsi.c \
	usbd_storage_msd.c \
	)

174
SRC_FATFS = $(addprefix $(FATFS_DIR)/src/,\
Dave Hylands's avatar
Dave Hylands committed
175
	ff.c \
176
	option/ccsbcs.c \
Dave Hylands's avatar
Dave Hylands committed
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
	)

SRC_CC3K = $(addprefix $(CC3K_DIR)/,\
	cc3000_common.c \
	evnt_handler.c \
	hci.c \
	netapp.c \
	nvmem.c \
	security.c \
	socket.c \
	wlan.c \
	ccspi.c \
	pybcc3k.c \
	)

OBJ =
193
OBJ += $(PY_O)
Dave Hylands's avatar
Dave Hylands committed
194
195
196
OBJ += $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
OBJ += $(addprefix $(BUILD)/, $(SRC_S:.s=.o))
OBJ += $(addprefix $(BUILD)/, $(SRC_HAL:.c=.o))
197
OBJ += $(addprefix $(BUILD)/, $(SRC_USBDEV:.c=.o))
198
OBJ += $(addprefix $(BUILD)/, $(SRC_FATFS:.c=.o))
199
OBJ += $(addprefix $(BUILD)/, $(SRC_CC3K:.c=.o))
200
OBJ += $(BUILD)/pins_$(BOARD).o
Dave Hylands's avatar
Dave Hylands committed
201

Windel Bouwman's avatar
Windel Bouwman committed
202
all: $(BUILD)/firmware.dfu $(BUILD)/firmware.hex
Dave Hylands's avatar
Dave Hylands committed
203

204
.PHONY: deploy
205

206
deploy: $(BUILD)/firmware.dfu
207
	$(ECHO) "Writing $< to the board"
208
	$(Q)$(DFU_UTIL) -a 0 -d $(DEVICE) -D $<
209

210
$(BUILD)/firmware.dfu: $(BUILD)/firmware.elf
Dave Hylands's avatar
Dave Hylands committed
211
	$(ECHO) "Create $@"
212
213
214
	$(Q)$(OBJCOPY) -O binary -j .isr_vector $^ $(BUILD)/firmware0.bin
	$(Q)$(OBJCOPY) -O binary -j .text -j .data $^ $(BUILD)/firmware1.bin
	$(Q)$(PYTHON) $(DFU) -b 0x08000000:$(BUILD)/firmware0.bin -b 0x08020000:$(BUILD)/firmware1.bin $@
Dave Hylands's avatar
Dave Hylands committed
215

Windel Bouwman's avatar
Windel Bouwman committed
216
217
218
219
$(BUILD)/firmware.hex: $(BUILD)/firmware.elf
	$(ECHO) "Create $@"
	$(Q)$(OBJCOPY) -O ihex $< $@

220
$(BUILD)/firmware.elf: $(OBJ)
Dave Hylands's avatar
Dave Hylands committed
221
222
223
224
225
226
227
228
229
	$(ECHO) "LINK $@"
	$(Q)$(LD) $(LDFLAGS) -o $@ $(OBJ) $(LIBS)
	$(Q)$(SIZE) $@

MAKE_PINS = boards/make-pins.py
BOARD_PINS = boards/$(BOARD)/pins.csv
AF_FILE = boards/stm32f4xx-af.csv
PREFIX_FILE = boards/stm32f4xx-prefix.c
GEN_PINS_SRC = $(BUILD)/pins_$(BOARD).c
230
GEN_PINS_HDR = $(HEADER_BUILD)/pins.h
231
232
GEN_PINS_QSTR = $(BUILD)/pins_qstr.h
GEN_PINS_AF_CONST = $(HEADER_BUILD)/pins-af-const.h
Dave Hylands's avatar
Dave Hylands committed
233

234
235
236
237
238
INSERT_USB_IDS = ../tools/insert-usb-ids.py
FILE2H = ../tools/file2h.py

USB_IDS_FILE = usbd_desc_cdc_msc.c
CDCINF_TEMPLATE = pybcdc.inf_template
239
240
GEN_CDCINF_FILE = $(HEADER_BUILD)/pybcdc.inf
GEN_CDCINF_HEADER = $(HEADER_BUILD)/pybcdc_inf.h
241

Dave Hylands's avatar
Dave Hylands committed
242
243
244
245
246
# Making OBJ use an order-only depenedency on the generated pins.h file
# has the side effect of making the pins.h file before we actually compile
# any of the objects. The normal dependency generation will deal with the
# case when pins.h is modified. But when it doesn't exist, we don't know
# which source files might need it.
247
$(OBJ): | $(HEADER_BUILD)/pins.h
248

249
250
$(BUILD)/main.o: $(GEN_CDCINF_HEADER)

Dave Hylands's avatar
Dave Hylands committed
251
252
# Use a pattern rule here so that make will only call make-pins.py once to make
# both pins_$(BOARD).c and pins.h
253
$(BUILD)/%_$(BOARD).c $(HEADER_BUILD)/%.h $(HEADER_BUILD)/%-af-const.h $(BUILD)/%_qstr.h: boards/$(BOARD)/%.csv $(MAKE_PINS) $(AF_FILE) $(PREFIX_FILE) | $(HEADER_BUILD)
Dave Hylands's avatar
Dave Hylands committed
254
	$(ECHO) "Create $@"
255
	$(Q)$(PYTHON) $(MAKE_PINS) --board $(BOARD_PINS) --af $(AF_FILE) --prefix $(PREFIX_FILE) --hdr $(GEN_PINS_HDR) --qstr $(GEN_PINS_QSTR) --af-const $(GEN_PINS_AF_CONST) > $(GEN_PINS_SRC)
Dave Hylands's avatar
Dave Hylands committed
256
257
258
259

$(BUILD)/pins_$(BOARD).o: $(BUILD)/pins_$(BOARD).c
	$(call compile_c)

260
261
262
263
264
265
266
267
$(GEN_CDCINF_HEADER): $(GEN_CDCINF_FILE) $(FILE2H)
	$(ECHO) "Create $@"
	$(Q)$(PYTHON) $(FILE2H) $< > $@

$(GEN_CDCINF_FILE): $(CDCINF_TEMPLATE) $(INSERT_USB_IDS) $(USB_IDS_FILE)
	$(ECHO) "Create $@"
	$(Q)$(PYTHON) $(INSERT_USB_IDS) $(USB_IDS_FILE) $< > $@

Dave Hylands's avatar
Dave Hylands committed
268
include ../py/mkrules.mk