2014-01-24 09:05:30 +00:00
|
|
|
include ../py/mkenv.mk
|
2014-01-08 17:09:47 +00:00
|
|
|
|
2014-01-15 06:23:56 +00:00
|
|
|
# qstr definitions (must come before including py.mk)
|
2014-07-22 15:57:36 +01:00
|
|
|
QSTR_DEFS = qstrdefsport.h $(BUILD)/pins_qstr.h
|
2014-01-15 06:23:56 +00:00
|
|
|
|
2014-01-08 17:09:47 +00:00
|
|
|
# include py core make definitions
|
|
|
|
include ../py/py.mk
|
|
|
|
|
2014-09-22 06:40:42 +01:00
|
|
|
# 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)
|
2014-06-16 17:38:24 +01:00
|
|
|
CROSS_COMPILE = arm-none-eabi-
|
2014-09-22 06:40:42 +01:00
|
|
|
endif
|
2014-01-06 08:20:11 +00:00
|
|
|
|
2014-01-08 17:09:47 +00:00
|
|
|
CFLAGS_TEENSY = -DF_CPU=96000000 -DUSB_SERIAL -D__MK20DX256__
|
2014-09-22 06:40:42 +01:00
|
|
|
CFLAGS_CORTEX_M4 = -mthumb -mtune=cortex-m4 -mcpu=cortex-m4 -msoft-float -mfloat-abi=soft -fsingle-precision-constant -Wdouble-promotion $(CFLAGS_TEENSY)
|
2014-04-16 22:10:33 +01:00
|
|
|
|
|
|
|
INC = -I.
|
2014-12-27 14:11:49 +00:00
|
|
|
INC += -I..
|
2014-06-16 06:33:14 +01:00
|
|
|
INC += -I../stmhal
|
2015-01-12 02:26:15 +00:00
|
|
|
INC += -I../lib/mp-readline
|
2014-04-17 18:03:27 +01:00
|
|
|
INC += -I$(BUILD)
|
2014-06-16 17:38:24 +01:00
|
|
|
INC += -Icore
|
2014-04-16 22:10:33 +01:00
|
|
|
|
2014-10-29 09:05:55 +00:00
|
|
|
CFLAGS = $(INC) -Wall -Wpointer-arith -ansi -std=gnu99 -nostdlib $(CFLAGS_CORTEX_M4)
|
2014-09-22 06:40:42 +01:00
|
|
|
LDFLAGS = -nostdlib -T mk20dx256.ld -msoft-float -mfloat-abi=soft
|
2014-06-16 17:38:24 +01:00
|
|
|
|
2014-09-22 06:40:42 +01:00
|
|
|
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
|
2014-06-16 17:38:24 +01:00
|
|
|
|
|
|
|
#$(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
|
2014-01-06 08:20:11 +00:00
|
|
|
|
2014-01-13 13:25:10 +00:00
|
|
|
#Debugging/Optimization
|
|
|
|
ifdef DEBUG
|
|
|
|
CFLAGS += -Og -ggdb
|
|
|
|
else
|
|
|
|
CFLAGS += -Os #-DNDEBUG
|
|
|
|
endif
|
2014-08-20 21:21:11 +01:00
|
|
|
CFLAGS += -fdata-sections -ffunction-sections
|
|
|
|
LDFLAGS += -Wl,--gc-sections
|
2014-01-13 13:25:10 +00:00
|
|
|
|
2014-01-06 08:20:11 +00:00
|
|
|
SRC_C = \
|
2014-08-20 21:21:11 +01:00
|
|
|
hal_ftm.c \
|
2014-06-16 06:33:14 +01:00
|
|
|
hal_gpio.c \
|
|
|
|
help.c \
|
|
|
|
import.c \
|
2014-01-06 08:20:11 +00:00
|
|
|
main.c \
|
2014-01-07 17:49:42 +00:00
|
|
|
lcd.c \
|
2014-01-06 08:20:11 +00:00
|
|
|
led.c \
|
2014-01-08 09:00:22 +00:00
|
|
|
lexermemzip.c \
|
|
|
|
memzip.c \
|
2014-06-16 06:33:14 +01:00
|
|
|
modpyb.c \
|
2014-07-22 15:57:36 +01:00
|
|
|
pin_defs_teensy.c \
|
2014-08-20 21:21:11 +01:00
|
|
|
reg.c \
|
2014-06-16 06:33:14 +01:00
|
|
|
teensy_hal.c \
|
2014-08-20 21:21:11 +01:00
|
|
|
timer.c \
|
2014-06-16 06:33:14 +01:00
|
|
|
uart.c \
|
2014-01-07 17:49:42 +00:00
|
|
|
usb.c \
|
|
|
|
|
2014-06-16 06:33:14 +01:00
|
|
|
STM_SRC_C = $(addprefix stmhal/,\
|
|
|
|
gccollect.c \
|
|
|
|
input.c \
|
2014-08-24 20:21:12 +01:00
|
|
|
irq.c \
|
2014-06-16 06:33:14 +01:00
|
|
|
pin.c \
|
|
|
|
pin_named_pins.c \
|
2014-01-06 08:20:11 +00:00
|
|
|
printf.c \
|
2014-06-16 06:33:14 +01:00
|
|
|
pyexec.c \
|
|
|
|
pybstdio.c \
|
2014-01-06 08:20:11 +00:00
|
|
|
string0.c \
|
2014-01-24 09:05:30 +00:00
|
|
|
)
|
2014-01-06 08:20:11 +00:00
|
|
|
|
2014-06-16 06:33:14 +01:00
|
|
|
STM_SRC_S = $(addprefix stmhal/,\
|
2014-01-06 08:20:11 +00:00
|
|
|
gchelper.s \
|
2014-01-24 09:05:30 +00:00
|
|
|
)
|
2014-01-06 08:20:11 +00:00
|
|
|
|
2015-01-12 02:26:15 +00:00
|
|
|
LIB_SRC_C = $(addprefix lib/,\
|
|
|
|
mp-readline/readline.c \
|
|
|
|
)
|
|
|
|
|
2014-06-16 17:38:24 +01:00
|
|
|
SRC_TEENSY = $(addprefix core/,\
|
2014-01-06 08:20:11 +00:00
|
|
|
mk20dx128.c \
|
|
|
|
pins_teensy.c \
|
|
|
|
analog.c \
|
|
|
|
usb_desc.c \
|
|
|
|
usb_dev.c \
|
|
|
|
usb_mem.c \
|
|
|
|
usb_serial.c \
|
|
|
|
yield.c \
|
2014-06-16 17:38:24 +01:00
|
|
|
)
|
2014-01-06 08:20:11 +00:00
|
|
|
|
2014-01-15 06:23:56 +00:00
|
|
|
OBJ = $(PY_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o) $(STM_SRC_C:.c=.o) $(STM_SRC_S:.s=.o) $(SRC_TEENSY:.c=.o))
|
2015-01-12 02:26:15 +00:00
|
|
|
OBJ += $(addprefix $(BUILD)/, $(LIB_SRC_C:.c=.o))
|
2014-06-16 06:33:14 +01:00
|
|
|
OBJ += $(BUILD)/pins_gen.o
|
2014-01-06 08:20:11 +00:00
|
|
|
|
2014-01-24 09:05:30 +00:00
|
|
|
all: hex
|
2014-01-08 09:00:22 +00:00
|
|
|
hex: $(BUILD)/micropython-mz.hex
|
2014-01-06 08:20:11 +00:00
|
|
|
|
2014-06-16 17:38:24 +01:00
|
|
|
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
|
|
|
|
|
2014-01-08 09:00:22 +00:00
|
|
|
post_compile: $(BUILD)/micropython-mz.hex
|
2014-01-08 18:15:39 +00:00
|
|
|
$(ECHO) "Preparing $@ for upload"
|
2014-08-03 17:55:24 +01:00
|
|
|
$(Q)$(TOOLS_PATH)/teensy_post_compile -file="$(basename $(<F))" -path="$(abspath $(<D))" -tools="$(TOOLS_PATH)"
|
2014-01-06 08:20:11 +00:00
|
|
|
|
|
|
|
reboot:
|
2014-01-08 18:15:39 +00:00
|
|
|
$(ECHO) "REBOOT"
|
|
|
|
-$(Q)$(TOOLS_PATH)/teensy_reboot
|
2014-06-16 17:38:24 +01:00
|
|
|
endif
|
2014-01-06 08:20:11 +00:00
|
|
|
|
2014-06-16 17:38:24 +01:00
|
|
|
.PHONY: deploy
|
|
|
|
deploy: post_compile reboot
|
2014-01-06 08:20:11 +00:00
|
|
|
|
2014-01-08 09:00:22 +00:00
|
|
|
$(BUILD)/micropython.elf: $(OBJ)
|
2014-06-16 06:33:14 +01:00
|
|
|
$(ECHO) "LINK $@"
|
2014-01-08 18:15:39 +00:00
|
|
|
$(Q)$(CC) $(LDFLAGS) -o "$@" -Wl,-Map,$(@:.elf=.map) $(OBJ) $(LIBS)
|
|
|
|
$(Q)$(SIZE) $@
|
2014-01-06 08:20:11 +00:00
|
|
|
|
2014-01-08 09:00:22 +00:00
|
|
|
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}
|
|
|
|
|
2014-01-08 17:09:47 +00:00
|
|
|
$(BUILD)/%.hex: $(BUILD)/%.elf
|
2014-01-08 18:15:39 +00:00
|
|
|
$(ECHO) "HEX $<"
|
|
|
|
$(Q)$(OBJCOPY) -O ihex -R .eeprom "$<" "$@"
|
2014-01-06 08:20:11 +00:00
|
|
|
|
2014-06-16 06:33:14 +01:00
|
|
|
MAKE_PINS = make-pins.py
|
2014-08-08 22:34:06 +01:00
|
|
|
BOARD_PINS = teensy_pins.csv
|
|
|
|
AF_FILE = mk20dx256_af.csv
|
|
|
|
PREFIX_FILE = mk20dx256_prefix.c
|
2014-06-16 06:33:14 +01:00
|
|
|
GEN_PINS_SRC = $(BUILD)/pins_gen.c
|
|
|
|
GEN_PINS_HDR = $(HEADER_BUILD)/pins.h
|
2014-07-22 15:57:36 +01:00
|
|
|
GEN_PINS_QSTR = $(BUILD)/pins_qstr.h
|
2014-08-08 22:34:06 +01:00
|
|
|
GEN_PINS_AF_CONST = $(HEADER_BUILD)/pins_af_const.h
|
2014-08-20 21:21:11 +01:00
|
|
|
GEN_PINS_AF_PY = $(BUILD)/pins_af.py
|
2014-06-16 06:33:14 +01:00
|
|
|
|
|
|
|
# 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
|
2014-08-08 22:34:06 +01:00
|
|
|
$(BUILD)/%_gen.c $(HEADER_BUILD)/%.h $(HEADER_BUILD)/%_af_const.h $(BUILD)/%_qstr.h: teensy_%.csv $(MAKE_PINS) $(AF_FILE) $(PREFIX_FILE) | $(HEADER_BUILD)
|
2014-06-16 06:33:14 +01:00
|
|
|
$(ECHO) "Create $@"
|
2014-08-20 21:21:11 +01:00
|
|
|
$(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)
|
2014-06-16 06:33:14 +01:00
|
|
|
|
|
|
|
$(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 $@ $<
|
|
|
|
|
2014-01-24 09:05:30 +00:00
|
|
|
include ../py/mkrules.mk
|