Makefile 5.63 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
Dave Hylands's avatar
Dave Hylands committed
14
15
16
17
18
19
20
#CC3K_DIR=cc3k
DFU=../tools/dfu.py

CROSS_COMPILE = arm-none-eabi-

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

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)

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

#	pybwlan.c \

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

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

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

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

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

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

all: $(BUILD)/flash.dfu

$(BUILD)/flash.dfu: $(BUILD)/flash0.bin $(BUILD)/flash1.bin
	$(ECHO) "Create $@"
195
	$(Q)$(PYTHON) $(DFU) -b 0x08000000:$(BUILD)/flash0.bin -b 0x08020000:$(BUILD)/flash1.bin $@
Dave Hylands's avatar
Dave Hylands committed
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212

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

215
216
217
218
219
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
220
221
GEN_CDCINF_FILE = $(HEADER_BUILD)/pybcdc.inf
GEN_CDCINF_HEADER = $(HEADER_BUILD)/pybcdc_inf.h
222

Dave Hylands's avatar
Dave Hylands committed
223
224
225
226
227
# 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.
228
$(OBJ): | $(HEADER_BUILD)/pins.h
229

230
231
$(BUILD)/main.o: $(GEN_CDCINF_HEADER)

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

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

241
242
243
244
245
246
247
248
$(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
249
include ../py/mkrules.mk