Makefile 4.63 KB
Newer Older
1
include ../py/mkenv.mk
2

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

6
7
8
# include py core make definitions
include ../py/py.mk

9
10
11
12
13
14
15
CMSIS_DIR=cmsis
STMPERIPH_DIR=stmperiph
STMUSB_DIR=stmusb
STMUSBD_DIR=stmusbd
STMUSBH_DIR=stmusbh
FATFS_DIR=fatfs
CC3K_DIR=cc3k
16
DFU=../tools/dfu.py
Damien's avatar
Damien committed
17

18
CROSS_COMPILE = arm-none-eabi-
19

20
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
21
CFLAGS = -I. -I$(PY_SRC) -I$(CMSIS_DIR) -I$(STMPERIPH_DIR) -I$(STMUSB_DIR) -Wall -Werror -ansi -std=gnu99 $(CFLAGS_CORTEX_M4) $(COPT)
22
23
24
25
CFLAGS += -I$(STMUSBD_DIR)
CFLAGS += -I$(STMUSBH_DIR)
CFLAGS += -I$(FATFS_DIR)
#CFLAGS += -I$(CC3K_DIR)
mux's avatar
mux committed
26

Dave Hylands's avatar
Dave Hylands committed
27
BOARD ?= PYBOARD4
28
29
30
ifeq ($(wildcard boards/$(BOARD)/.),)
$(error Invalid BOARD specified)
endif
Dave Hylands's avatar
Dave Hylands committed
31
32
CFLAGS += -Iboards/$(BOARD)

mux's avatar
mux committed
33
34
#Debugging/Optimization
ifeq ($(DEBUG), 1)
35
CFLAGS += -g -DPENDSV_DEBUG
36
COPT = -O0
mux's avatar
mux committed
37
else
38
COPT += -Os -DNDEBUG
mux's avatar
mux committed
39
40
endif

41
LDFLAGS = --nostdlib -T stm32f405.ld -Map=$(@:.elf=.map) --cref
42
43
44
45
LIBS =

# uncomment this if you want libgcc
#LIBS += $(shell $(CC) -print-libgcc-file-name)
Damien's avatar
Damien committed
46
47
48
49

SRC_C = \
	main.c \
	printf.c \
50
	math.c \
Damien's avatar
Damien committed
51
	system_stm32f4xx.c \
Damien's avatar
Damien committed
52
53
54
55
	stm32fxxx_it.c \
	string0.c \
	malloc0.c \
	systick.c  \
56
	pendsv.c \
57
	gccollect.c \
58
	lexerfatfs.c \
Damien George's avatar
Damien George committed
59
	import.c \
60
	pyexec.c \
61
	led.c \
62
	gpio.c \
63
	lcd.c \
64
	servo.c \
Damien's avatar
Damien committed
65
	flash.c \
66
	storage.c \
Damien George's avatar
Damien George committed
67
	accel.c \
68
	usart.c \
Damien's avatar
Damien committed
69
	usb.c \
70
	timer.c \
71
	audio.c \
72
	sdcard.c \
73
	i2c.c \
mux's avatar
mux committed
74
	adc.c \
mux's avatar
mux committed
75
	rtc.c \
mux's avatar
mux committed
76
	file.c \
Dave Hylands's avatar
Dave Hylands committed
77
78
79
	pin.c \
	pin_named_pins.c \
	pin_map.c \
Dave Hylands's avatar
Dave Hylands committed
80
81
	exti.c \
	usrsw.c \
82
#	pybwlan.c \
Damien's avatar
Damien committed
83
84
85

SRC_S = \
	startup_stm32f40xx.s \
86
	gchelper.s \
Damien's avatar
Damien committed
87

88
89
SRC_STMPERIPH = $(addprefix $(STMPERIPH_DIR)/,\
	stm_misc.c \
Damien's avatar
Damien committed
90
	stm32f4xx_rcc.c \
91
	stm32f4xx_syscfg.c \
Damien's avatar
Damien committed
92
93
94
	stm32f4xx_flash.c \
	stm32f4xx_dma.c \
	stm32f4xx_gpio.c \
95
	stm32f4xx_exti.c \
96
	stm32f4xx_tim.c \
97
	stm32f4xx_sdio.c \
98
99
	stm32f4xx_pwr.c \
	stm32f4xx_rtc.c \
100
	stm32f4xx_usart.c \
101
	stm32f4xx_spi.c \
102
	stm32f4xx_dac.c \
Damien's avatar
Damien committed
103
	stm32f4xx_rng.c \
104
	stm32f4xx_i2c.c \
105
106
107
	stm32f4xx_adc.c \
	stm324x7i_eval.c \
	stm324x7i_eval_sdio_sd.c \
108
109
110
	)

SRC_STMUSB = $(addprefix $(STMUSB_DIR)/,\
Damien's avatar
Damien committed
111
	usb_core.c \
112
	usb_bsp.c \
Damien's avatar
Damien committed
113
114
	usb_dcd.c \
	usb_dcd_int.c \
115
116
117
118
119
120
	usb_hcd.c \
	usb_hcd_int.c \
	)
#	usb_otg.c \

SRC_STMUSBD = $(addprefix $(STMUSBD_DIR)/,\
Damien's avatar
Damien committed
121
122
123
124
125
	usbd_core.c \
	usbd_ioreq.c \
	usbd_req.c \
	usbd_usr.c \
	usbd_desc.c \
126
	usbd_pyb_core.c \
127
	usbd_pyb_core2.c \
Damien's avatar
Damien committed
128
129
130
131
132
	usbd_cdc_vcp.c \
	usbd_msc_bot.c  \
	usbd_msc_data.c \
	usbd_msc_scsi.c \
	usbd_storage_msd.c \
133
	)
Damien's avatar
Damien committed
134

135
SRC_STMUSBH = $(addprefix $(STMUSBH_DIR)/,\
136
137
138
139
140
141
142
143
	usbh_core.c \
	usbh_hcs.c \
	usbh_stdreq.c \
	usbh_ioreq.c \
	usbh_usr.c \
	usbh_hid_core.c \
	usbh_hid_mouse.c \
	usbh_hid_keybd.c \
144
	)
145

146
147
148
SRC_FATFS = $(addprefix $(FATFS_DIR)/,\
	ff.c \
	diskio.c \
mux's avatar
mux committed
149
	ccsbcs.c \
150
151
152
	)

SRC_CC3K = $(addprefix $(CC3K_DIR)/,\
153
154
155
156
157
158
159
160
161
162
	cc3000_common.c \
	evnt_handler.c \
	hci.c \
	netapp.c \
	nvmem.c \
	security.c \
	socket.c \
	wlan.c \
	ccspi.c \
	pybcc3k.c \
163
	)
164

165
166
167
168
169
OBJ = $(PY_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o) $(SRC_S:.s=.o) $(SRC_STMPERIPH:.c=.o) $(SRC_STMUSB:.c=.o))
OBJ += $(addprefix $(BUILD)/, $(SRC_STMUSBD:.c=.o))
#OBJ += $(addprefix $(BUILD)/, $(SRC_STMUSBH:.c=.o))
OBJ += $(addprefix $(BUILD)/, $(SRC_FATFS:.c=.o))
#OBJ += $(addprefix $(BUILD)/, $(SRC_CC3K:.c=.o))
Dave Hylands's avatar
Dave Hylands committed
170
OBJ += $(BUILD)/pins_$(BOARD).o
Damien's avatar
Damien committed
171

172
all: $(BUILD)/flash.dfu
Damien's avatar
Damien committed
173

174
$(BUILD)/flash.dfu: $(BUILD)/flash0.bin $(BUILD)/flash1.bin
Dave Hylands's avatar
Dave Hylands committed
175
176
	$(ECHO) "Create $@"
	$(Q)python $(DFU) -b 0x08000000:$(BUILD)/flash0.bin -b 0x08020000:$(BUILD)/flash1.bin $@
Damien's avatar
Damien committed
177

178
$(BUILD)/flash0.bin: $(BUILD)/flash.elf
Dave Hylands's avatar
Dave Hylands committed
179
	$(Q)$(OBJCOPY) -O binary -j .isr_vector $^ $@
180
181

$(BUILD)/flash1.bin: $(BUILD)/flash.elf
Dave Hylands's avatar
Dave Hylands committed
182
	$(Q)$(OBJCOPY) -O binary -j .text -j .data $^ $@
Damien's avatar
Damien committed
183
184

$(BUILD)/flash.elf: $(OBJ)
Dave Hylands's avatar
Dave Hylands committed
185
	$(ECHO) "LINK $@"
186
	$(Q)$(LD) $(LDFLAGS) -o $@ $(OBJ) $(LIBS)
Dave Hylands's avatar
Dave Hylands committed
187
	$(Q)$(SIZE) $@
Damien's avatar
Damien committed
188

Dave Hylands's avatar
Dave Hylands committed
189
190
191
192
MAKE_PINS = boards/make-pins.py
BOARD_PINS = boards/$(BOARD)/pins.csv
AF_FILE = boards/stm32f4xx-af.csv
PREFIX_FILE = boards/stm32f4xx-prefix.c
Dave Hylands's avatar
Dave Hylands committed
193
194
195
196
197
198
199
200
201
202
203
204
205
GEN_PINS_SRC = $(BUILD)/pins_$(BOARD).c
GEN_PINS_HDR = $(BUILD)/pins.h

# 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.
$(OBJ): | $(BUILD)/pins.h

# Use a pattern rule here so that make will only call make-pins.py once to make
# both pins_$(BOARD).c and pins.h
$(BUILD)/%_$(BOARD).c $(BUILD)/%.h: boards/$(BOARD)/%.csv $(MAKE_PINS) $(AF_FILE) $(PREFIX_FILE)
Dave Hylands's avatar
Dave Hylands committed
206
	$(ECHO) "Create $@"
Dave Hylands's avatar
Dave Hylands committed
207
	$(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
208
209
210
211

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

212
include ../py/mkrules.mk