Makefile 5.96 KB
Newer Older
1
# Select the board to build for: if not given on the command line,
2
3
# then default to PYBV10.
BOARD ?= PYBV10
4
5
6
7
8
9
10
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
14
15
16
17
18
19
20
include ../py/mkenv.mk

# qstr definitions (must come before including py.mk)
QSTR_DEFS = qstrdefsport.h

# 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
27
# may need to prefix dfu-util with sudo
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63

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
CFLAGS = $(INC) -Wall -Werror -ansi -std=gnu99 $(CFLAGS_CORTEX_M4) $(COPT)

CFLAGS += -Iboards/$(BOARD)

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

LDFLAGS = --nostdlib -T stm32f405.ld -Map=$(@:.elf=.map) --cref
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_named_pins.c \
Damien George's avatar
Damien George committed
78
79
80
81
	bufhelper.c \
	i2c.c \
	spi.c \
	uart.c \
82
	usb.c \
83
84
	printf.c \
	math.c \
85
	mathsincos.c \
86
	gccollect.c \
87
88
	pybstdio.c \
	readline.c \
89
	pyexec.c \
Damien George's avatar
Damien George committed
90
	help.c \
91
	input.c \
92
	modos.c \
93
94
	modpyb.c \
	modstm.c \
95
	modtime.c \
96
97
	import.c \
	lexerfatfs.c \
98
	extint.c \
99
	usrsw.c \
100
	rng.c \
Damien George's avatar
Damien George committed
101
	rtc.c \
102
103
	flash.c \
	storage.c \
104
	file.c \
Damien George's avatar
Damien George committed
105
	sdcard.c \
106
	diskio.c \
107
	lcd.c \
108
	accel.c \
Damien George's avatar
Damien George committed
109
	servo.c \
Damien George's avatar
Damien George committed
110
	dac.c \
Dave Hylands's avatar
Dave Hylands committed
111
	adc.c \
112
	pybwlan.c \
Dave Hylands's avatar
Dave Hylands committed
113
114
115

SRC_S = \
	startup_stm32f40xx.s \
116
	gchelper.s \
Dave Hylands's avatar
Dave Hylands committed
117
118
119

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

145
146
147
148
SRC_USBDEV = $(addprefix $(USBDEV_DIR)/,\
	core/src/usbd_core.c \
	core/src/usbd_ctlreq.c \
	core/src/usbd_ioreq.c \
149
150
151
152
	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 \
153
154
	)

155
156
#	class/cdc/src/usbd_cdc.c \
	class/msc/src/usbd_msc.c \
157
#	usbd_core.c \
Dave Hylands's avatar
Dave Hylands committed
158
159
160
161
162
163
164
165
166
167
168
169
170
	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 \
	)

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

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 =
190
OBJ += $(PY_O)
Dave Hylands's avatar
Dave Hylands committed
191
192
193
OBJ += $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
OBJ += $(addprefix $(BUILD)/, $(SRC_S:.s=.o))
OBJ += $(addprefix $(BUILD)/, $(SRC_HAL:.c=.o))
194
OBJ += $(addprefix $(BUILD)/, $(SRC_USBDEV:.c=.o))
195
OBJ += $(addprefix $(BUILD)/, $(SRC_FATFS:.c=.o))
196
OBJ += $(addprefix $(BUILD)/, $(SRC_CC3K:.c=.o))
197
OBJ += $(BUILD)/pins_$(BOARD).o
Dave Hylands's avatar
Dave Hylands committed
198

199
all: $(BUILD)/firmware.dfu
Dave Hylands's avatar
Dave Hylands committed
200

201
.PHONY: deploy
202

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

207
$(BUILD)/firmware.dfu: $(BUILD)/firmware.elf
Dave Hylands's avatar
Dave Hylands committed
208
	$(ECHO) "Create $@"
209
210
211
	$(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
212

213
$(BUILD)/firmware.elf: $(OBJ)
Dave Hylands's avatar
Dave Hylands committed
214
215
216
217
218
219
220
221
222
	$(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
223
GEN_PINS_HDR = $(HEADER_BUILD)/pins.h
Dave Hylands's avatar
Dave Hylands committed
224

225
226
227
228
229
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
230
231
GEN_CDCINF_FILE = $(HEADER_BUILD)/pybcdc.inf
GEN_CDCINF_HEADER = $(HEADER_BUILD)/pybcdc_inf.h
232

Dave Hylands's avatar
Dave Hylands committed
233
234
235
236
237
# 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.
238
$(OBJ): | $(HEADER_BUILD)/pins.h
239

240
241
$(BUILD)/main.o: $(GEN_CDCINF_HEADER)

Dave Hylands's avatar
Dave Hylands committed
242
243
# Use a pattern rule here so that make will only call make-pins.py once to make
# both pins_$(BOARD).c and pins.h
244
$(BUILD)/%_$(BOARD).c $(HEADER_BUILD)/%.h: boards/$(BOARD)/%.csv $(MAKE_PINS) $(AF_FILE) $(PREFIX_FILE)
Dave Hylands's avatar
Dave Hylands committed
245
	$(ECHO) "Create $@"
246
	$(Q)$(PYTHON) $(MAKE_PINS) --board $(BOARD_PINS) --af $(AF_FILE) --prefix $(PREFIX_FILE) --hdr $(GEN_PINS_HDR) > $(GEN_PINS_SRC)
Dave Hylands's avatar
Dave Hylands committed
247
248
249
250

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

251
252
253
254
255
256
257
258
$(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
259
include ../py/mkrules.mk