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

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

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

9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# If you set USE_ARDUINO_TOOLCHAIN=1 then this makefile will attempt to use
# the toolchain that comes with Teensyduino
ifeq ($(USE_ARDUINO_TOOLCHAIN),)
USE_ARDUINO_TOOLCHAIN = 0
endif

ifeq ($(USE_ARDUINO_TOOLCHAIN),1)
ifeq ($(ARDUINO),)
$(error USE_ARDUINO_TOOLCHAIN requires that ARDUINO be set)
endif
endif

ifeq ($(USE_ARDUINO_TOOLCHAIN),1)
$(info Using ARDUINO toolchain)
CROSS_COMPILE = $(ARDUINO)/hardware/tools/arm-none-eabi/bin/arm-none-eabi-
else
$(info Using toolchain from PATH)
26
CROSS_COMPILE = arm-none-eabi-
27
endif
Dave Hylands's avatar
Dave Hylands committed
28

29
CFLAGS_TEENSY = -DF_CPU=96000000 -DUSB_SERIAL -D__MK20DX256__
30
CFLAGS_CORTEX_M4 = -mthumb -mtune=cortex-m4 -mcpu=cortex-m4 -msoft-float -mfloat-abi=soft -fsingle-precision-constant -Wdouble-promotion $(CFLAGS_TEENSY)
31
32

INC =  -I.
33
INC += -I..
34
INC += -I$(PY_SRC)
Dave Hylands's avatar
Dave Hylands committed
35
INC += -I../stmhal
36
INC += -I$(BUILD)
37
INC += -Icore
38

39
CFLAGS = $(INC) -Wall -Wpointer-arith -ansi -std=gnu99 -nostdlib $(CFLAGS_CORTEX_M4)
40
LDFLAGS = -nostdlib -T mk20dx256.ld -msoft-float -mfloat-abi=soft
41

42
43
44
45
46
47
48
49
50
51
52
53
54
ifeq ($(USE_ARDUINO_TOOLCHAIN),1)

LIBGCC_FILE_NAME = $(ARDUINO)/hardware/tools/arm-none-eabi/lib/gcc/arm-none-eabi/4.7.2/thumb2/libgcc.a
LIBM_FILE_NAME   = $(ARDUINO)/hardware/tools/arm-none-eabi/arm-none-eabi/lib/thumb2/libm.a
LIBC_FILE_NAME   = $(ARDUINO)/hardware/tools/arm-none-eabi/arm-none-eabi/lib/thumb2/libc.a

else

LIBGCC_FILE_NAME = $(shell $(CC) $(CFLAGS) -print-libgcc-file-name)
LIBM_FILE_NAME   = $(shell $(CC) $(CFLAGS) -print-file-name=libm.a)
LIBC_FILE_NAME   = $(shell $(CC) $(CFLAGS) -print-file-name=libc.a)

endif
55
56
57
58
59
60
61
62
63
64
65
66

#$(info %%%%% LIBGCC_FILE_NAME = $(LIBGCC_FILE_NAME))
#$(info %%%%% LIBM_FILE_NAME = $(LIBM_FILE_NAME))
#$(info %%%%% LIBC_FILE_NAME = $(LIBC_FILE_NAME))

#$(info %%%%% dirname LIBGCC_FILE_NAME = $(dir $(LIBGCC_FILE_NAME)))
#$(info %%%%% dirname LIBM_FILE_NAME = $(dir $(LIBM_FILE_NAME)))
#$(info %%%%% dirname LIBC_FILE_NAME = $(dir $(LIBC_FILE_NAME)))

LIBS  = -L $(dir $(LIBM_FILE_NAME)) -lm
LIBS += -L $(dir $(LIBC_FILE_NAME)) -lc
LIBS += -L $(dir $(LIBGCC_FILE_NAME)) -lgcc
Dave Hylands's avatar
Dave Hylands committed
67

68
69
70
71
72
73
#Debugging/Optimization
ifdef DEBUG
CFLAGS += -Og -ggdb
else
CFLAGS += -Os #-DNDEBUG
endif
74
75
CFLAGS += -fdata-sections -ffunction-sections
LDFLAGS += -Wl,--gc-sections
76

Dave Hylands's avatar
Dave Hylands committed
77
SRC_C = \
78
	hal_ftm.c \
Dave Hylands's avatar
Dave Hylands committed
79
80
81
	hal_gpio.c \
	help.c \
	import.c \
Dave Hylands's avatar
Dave Hylands committed
82
	main.c \
83
	lcd.c \
Dave Hylands's avatar
Dave Hylands committed
84
	led.c \
85
86
	lexermemzip.c \
	memzip.c \
Dave Hylands's avatar
Dave Hylands committed
87
	modpyb.c \
88
	pin_defs_teensy.c \
89
	reg.c \
Dave Hylands's avatar
Dave Hylands committed
90
	teensy_hal.c \
91
	timer.c \
Dave Hylands's avatar
Dave Hylands committed
92
	uart.c \
93
94
	usb.c \

Dave Hylands's avatar
Dave Hylands committed
95
96
97
STM_SRC_C = $(addprefix stmhal/,\
	gccollect.c \
	input.c \
Dave Hylands's avatar
Dave Hylands committed
98
	irq.c \
Dave Hylands's avatar
Dave Hylands committed
99
100
	pin.c \
	pin_named_pins.c \
Dave Hylands's avatar
Dave Hylands committed
101
	printf.c \
Dave Hylands's avatar
Dave Hylands committed
102
103
104
	pyexec.c \
	pybstdio.c \
	readline.c \
Dave Hylands's avatar
Dave Hylands committed
105
	string0.c \
106
	)
Dave Hylands's avatar
Dave Hylands committed
107

Dave Hylands's avatar
Dave Hylands committed
108
STM_SRC_S = $(addprefix stmhal/,\
Dave Hylands's avatar
Dave Hylands committed
109
	gchelper.s \
110
	)
Dave Hylands's avatar
Dave Hylands committed
111

112
SRC_TEENSY = $(addprefix core/,\
Dave Hylands's avatar
Dave Hylands committed
113
114
115
116
117
118
119
120
	mk20dx128.c \
	pins_teensy.c \
	analog.c \
	usb_desc.c \
	usb_dev.c \
	usb_mem.c \
	usb_serial.c \
	yield.c \
121
	)
Dave Hylands's avatar
Dave Hylands committed
122

123
OBJ = $(PY_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o) $(STM_SRC_C:.c=.o) $(STM_SRC_S:.s=.o) $(SRC_TEENSY:.c=.o))
Dave Hylands's avatar
Dave Hylands committed
124
OBJ += $(BUILD)/pins_gen.o
Dave Hylands's avatar
Dave Hylands committed
125

126
all: hex
127
hex: $(BUILD)/micropython-mz.hex
Dave Hylands's avatar
Dave Hylands committed
128

129
130
131
132
133
134
135
136
137
138
139
140
ifeq ($(ARDUINO),)
post_compile: $(BUILD)/micropython-mz.hex
	$(ECHO) "Please define ARDUINO (where TeensyDuino is installed)"
	exit 1

reboot:
	$(ECHO) "Please define ARDUINO (where TeensyDuino is installed)"
	exit 1

else
TOOLS_PATH = $(ARDUINO)/hardware/tools

141
post_compile: $(BUILD)/micropython-mz.hex
Dave Hylands's avatar
Dave Hylands committed
142
	$(ECHO) "Preparing $@ for upload"
143
	$(Q)$(TOOLS_PATH)/teensy_post_compile -file="$(basename $(<F))" -path="$(abspath $(<D))" -tools="$(TOOLS_PATH)"
Dave Hylands's avatar
Dave Hylands committed
144
145

reboot:
Dave Hylands's avatar
Dave Hylands committed
146
147
	$(ECHO) "REBOOT"
	-$(Q)$(TOOLS_PATH)/teensy_reboot
148
endif
Dave Hylands's avatar
Dave Hylands committed
149

150
151
.PHONY: deploy
deploy: post_compile reboot
Dave Hylands's avatar
Dave Hylands committed
152

153
$(BUILD)/micropython.elf: $(OBJ)
Dave Hylands's avatar
Dave Hylands committed
154
	$(ECHO) "LINK $@"
Dave Hylands's avatar
Dave Hylands committed
155
156
	$(Q)$(CC) $(LDFLAGS) -o "$@" -Wl,-Map,$(@:.elf=.map) $(OBJ) $(LIBS)
	$(Q)$(SIZE) $@
Dave Hylands's avatar
Dave Hylands committed
157

158
159
160
161
162
163
164
165
ifeq ($(MEMZIP_DIR),)
MEMZIP_DIR = memzip_files
endif

$(BUILD)/micropython-mz.hex: $(BUILD)/micropython.hex $(shell find ${MEMZIP_DIR} -type f)
	@$(ECHO) "Creating $@"
	$(Q)./add-memzip.sh $< $@ ${MEMZIP_DIR}

166
$(BUILD)/%.hex: $(BUILD)/%.elf
Dave Hylands's avatar
Dave Hylands committed
167
168
	$(ECHO) "HEX $<"
	$(Q)$(OBJCOPY) -O ihex -R .eeprom "$<" "$@"
Dave Hylands's avatar
Dave Hylands committed
169

Dave Hylands's avatar
Dave Hylands committed
170
MAKE_PINS = make-pins.py
171
172
173
BOARD_PINS = teensy_pins.csv
AF_FILE = mk20dx256_af.csv
PREFIX_FILE = mk20dx256_prefix.c
Dave Hylands's avatar
Dave Hylands committed
174
175
GEN_PINS_SRC = $(BUILD)/pins_gen.c
GEN_PINS_HDR = $(HEADER_BUILD)/pins.h
176
GEN_PINS_QSTR = $(BUILD)/pins_qstr.h
177
GEN_PINS_AF_CONST = $(HEADER_BUILD)/pins_af_const.h
178
GEN_PINS_AF_PY = $(BUILD)/pins_af.py
Dave Hylands's avatar
Dave Hylands committed
179
180
181
182
183
184
185
186
187
188

# 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): | $(HEADER_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
189
$(BUILD)/%_gen.c $(HEADER_BUILD)/%.h $(HEADER_BUILD)/%_af_const.h $(BUILD)/%_qstr.h: teensy_%.csv $(MAKE_PINS) $(AF_FILE) $(PREFIX_FILE) | $(HEADER_BUILD)
Dave Hylands's avatar
Dave Hylands committed
190
	$(ECHO) "Create $@"
191
	$(Q)$(PYTHON) $(MAKE_PINS) --board $(BOARD_PINS) --af $(AF_FILE) --prefix $(PREFIX_FILE) --hdr $(GEN_PINS_HDR) --qstr $(GEN_PINS_QSTR) --af-const $(GEN_PINS_AF_CONST) --af-py $(GEN_PINS_AF_PY) > $(GEN_PINS_SRC)
Dave Hylands's avatar
Dave Hylands committed
192
193
194
195
196
197
198
199

$(BUILD)/pins_gen.o: $(BUILD)/pins_gen.c
	$(call compile_c)

$(BUILD)/%.pp: $(BUILD)/%.c
	$(ECHO) "PreProcess $<"
	$(Q)$(CC) $(CFLAGS) -E -Wp,-C,-dD,-dI -o $@ $<

200
include ../py/mkrules.mk