Makefile 5.98 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
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
Dave Hylands's avatar
Dave Hylands committed
28
29
30
31
32

CROSS_COMPILE = arm-none-eabi-

INC =  -I.
INC += -I$(PY_SRC)
33
INC += -I$(BUILD)
Dave Hylands's avatar
Dave Hylands committed
34
35
36
INC += -I$(CMSIS_DIR)/inc
INC += -I$(CMSIS_DIR)/devinc
INC += -I$(HAL_DIR)/inc
37
INC += -I$(USBDEV_DIR)/core/inc -I$(USBDEV_DIR)/class/cdc_msc_hid/inc
38
#INC += -I$(USBHOST_DIR)
39
INC += -I$(FATFS_DIR)/src
40
INC += -I$(CC3K_DIR)
Dave Hylands's avatar
Dave Hylands committed
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62

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

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

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

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

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

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

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

all: $(BUILD)/flash.dfu

200
201
202
203
204
205
.PHONY: flashboard

flashboard: $(BUILD)/flash.dfu
	$(ECHO) "Writing $< to the board"
	$(Q)$(DFU_UTIL) -a 0 -D $<

Dave Hylands's avatar
Dave Hylands committed
206
207
$(BUILD)/flash.dfu: $(BUILD)/flash0.bin $(BUILD)/flash1.bin
	$(ECHO) "Create $@"
208
	$(Q)$(PYTHON) $(DFU) -b 0x08000000:$(BUILD)/flash0.bin -b 0x08020000:$(BUILD)/flash1.bin $@
Dave Hylands's avatar
Dave Hylands committed
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225

$(BUILD)/flash0.bin: $(BUILD)/flash.elf
	$(Q)$(OBJCOPY) -O binary -j .isr_vector $^ $@

$(BUILD)/flash1.bin: $(BUILD)/flash.elf
	$(Q)$(OBJCOPY) -O binary -j .text -j .data $^ $@

$(BUILD)/flash.elf: $(OBJ)
	$(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
226
GEN_PINS_HDR = $(HEADER_BUILD)/pins.h
Dave Hylands's avatar
Dave Hylands committed
227

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

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

243
244
$(BUILD)/main.o: $(GEN_CDCINF_HEADER)

Dave Hylands's avatar
Dave Hylands committed
245
246
# Use a pattern rule here so that make will only call make-pins.py once to make
# both pins_$(BOARD).c and pins.h
247
$(BUILD)/%_$(BOARD).c $(HEADER_BUILD)/%.h: boards/$(BOARD)/%.csv $(MAKE_PINS) $(AF_FILE) $(PREFIX_FILE)
Dave Hylands's avatar
Dave Hylands committed
248
	$(ECHO) "Create $@"
249
	$(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
250
251
252
253

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

254
255
256
257
258
259
260
261
$(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
262
include ../py/mkrules.mk