Makefile 5.8 KB
Newer Older
Dave Hylands's avatar
Dave Hylands committed
1
2
3
4
5
6
7
8
9
10
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
11
12
USBDEV_DIR=usbdev
#USBHOST_DIR=usbhost
13
FATFS_DIR=fatfs
14
CC3K_DIR=cc3k
Dave Hylands's avatar
Dave Hylands committed
15
DFU=../tools/dfu.py
16
17
# may need to prefix dfu-util with sudo
DFU_UTIL=dfu-util
Dave Hylands's avatar
Dave Hylands committed
18
19
20
21
22

CROSS_COMPILE = arm-none-eabi-

INC =  -I.
INC += -I$(PY_SRC)
23
INC += -I$(BUILD)
Dave Hylands's avatar
Dave Hylands committed
24
25
26
INC += -I$(CMSIS_DIR)/inc
INC += -I$(CMSIS_DIR)/devinc
INC += -I$(HAL_DIR)/inc
27
INC += -I$(USBDEV_DIR)/core/inc -I$(USBDEV_DIR)/class/cdc_msc_hid/inc
28
#INC += -I$(USBHOST_DIR)
29
INC += -I$(FATFS_DIR)/src
30
INC += -I$(CC3K_DIR)
Dave Hylands's avatar
Dave Hylands committed
31
32
33
34

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)

35
BOARD ?= PYBV10
Dave Hylands's avatar
Dave Hylands committed
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
ifeq ($(wildcard boards/$(BOARD)/.),)
$(error Invalid BOARD specified)
endif
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 \
57
	string0.c \
Dave Hylands's avatar
Dave Hylands committed
58
	system_stm32f4xx.c \
59
60
	stm32f4xx_it.c \
	stm32f4xx_hal_msp.c \
61
	usbd_conf.c \
62
	usbd_desc_cdc_msc.c \
63
	usbd_cdc_interface.c \
64
	usbd_msc_storage.c \
65
	pendsv.c \
66
	systick.c  \
67
	timer.c \
68
69
	led.c \
	pin.c \
70
	pin_named_pins.c \
Damien George's avatar
Damien George committed
71
72
73
74
	bufhelper.c \
	i2c.c \
	spi.c \
	uart.c \
75
	usb.c \
76
77
	printf.c \
	math.c \
78
	mathsincos.c \
79
	gccollect.c \
80
81
	pybstdio.c \
	readline.c \
82
	pyexec.c \
Damien George's avatar
Damien George committed
83
	help.c \
84
	input.c \
85
	modos.c \
86
87
	modpyb.c \
	modstm.c \
88
	modtime.c \
89
90
	import.c \
	lexerfatfs.c \
91
	extint.c \
92
	usrsw.c \
93
	rng.c \
Damien George's avatar
Damien George committed
94
	rtc.c \
95
96
	flash.c \
	storage.c \
97
	file.c \
Damien George's avatar
Damien George committed
98
	sdcard.c \
99
	diskio.c \
100
	lcd.c \
101
	accel.c \
Damien George's avatar
Damien George committed
102
	servo.c \
Damien George's avatar
Damien George committed
103
	dac.c \
Dave Hylands's avatar
Dave Hylands committed
104
	adc.c \
105
	pybwlan.c \
Dave Hylands's avatar
Dave Hylands committed
106
107
108

SRC_S = \
	startup_stm32f40xx.s \
109
	gchelper.s \
Dave Hylands's avatar
Dave Hylands committed
110
111
112

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

138
139
140
141
SRC_USBDEV = $(addprefix $(USBDEV_DIR)/,\
	core/src/usbd_core.c \
	core/src/usbd_ctlreq.c \
	core/src/usbd_ioreq.c \
142
143
144
145
	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 \
146
147
	)

148
149
#	class/cdc/src/usbd_cdc.c \
	class/msc/src/usbd_msc.c \
150
#	usbd_core.c \
Dave Hylands's avatar
Dave Hylands committed
151
152
153
154
155
156
157
158
159
160
161
162
163
	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 \
	)

164
SRC_FATFS = $(addprefix $(FATFS_DIR)/src/,\
Dave Hylands's avatar
Dave Hylands committed
165
	ff.c \
166
	option/ccsbcs.c \
Dave Hylands's avatar
Dave Hylands committed
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
	)

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 =
183
OBJ += $(PY_O)
Dave Hylands's avatar
Dave Hylands committed
184
185
186
OBJ += $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
OBJ += $(addprefix $(BUILD)/, $(SRC_S:.s=.o))
OBJ += $(addprefix $(BUILD)/, $(SRC_HAL:.c=.o))
187
OBJ += $(addprefix $(BUILD)/, $(SRC_USBDEV:.c=.o))
188
OBJ += $(addprefix $(BUILD)/, $(SRC_FATFS:.c=.o))
189
OBJ += $(addprefix $(BUILD)/, $(SRC_CC3K:.c=.o))
190
OBJ += $(BUILD)/pins_$(BOARD).o
Dave Hylands's avatar
Dave Hylands committed
191
192
193

all: $(BUILD)/flash.dfu

194
195
196
197
198
199
.PHONY: flashboard

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

Dave Hylands's avatar
Dave Hylands committed
200
201
$(BUILD)/flash.dfu: $(BUILD)/flash0.bin $(BUILD)/flash1.bin
	$(ECHO) "Create $@"
202
	$(Q)$(PYTHON) $(DFU) -b 0x08000000:$(BUILD)/flash0.bin -b 0x08020000:$(BUILD)/flash1.bin $@
Dave Hylands's avatar
Dave Hylands committed
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219

$(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
220
GEN_PINS_HDR = $(HEADER_BUILD)/pins.h
Dave Hylands's avatar
Dave Hylands committed
221

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

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

237
238
$(BUILD)/main.o: $(GEN_CDCINF_HEADER)

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

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

248
249
250
251
252
253
254
255
$(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
256
include ../py/mkrules.mk