2016-08-23 02:48:09 -04:00
|
|
|
# Select the board to build for: if not given on the command line,
|
|
|
|
# then default to PYBV10.
|
2016-08-23 19:47:53 -04:00
|
|
|
BOARD ?= arduino_zero
|
2016-08-23 02:48:09 -04:00
|
|
|
ifeq ($(wildcard boards/$(BOARD)/.),)
|
|
|
|
$(error Invalid BOARD specified)
|
|
|
|
endif
|
2016-08-19 23:24:04 -04:00
|
|
|
|
2016-08-23 02:48:09 -04:00
|
|
|
|
|
|
|
# If the build directory is not given, make it reflect the board name.
|
|
|
|
BUILD ?= build-$(BOARD)
|
|
|
|
|
|
|
|
include ../py/mkenv.mk
|
|
|
|
-include mpconfigport.mk
|
|
|
|
include boards/$(BOARD)/mpconfigboard.mk
|
2016-08-19 23:24:04 -04:00
|
|
|
|
|
|
|
# qstr definitions (must come before including py.mk)
|
2016-08-23 02:48:09 -04:00
|
|
|
# TODO(tannewt): Support friendly pin names like the stmhal implementations do.
|
|
|
|
# Add $(BUILD)/pins_qstr.h $(BUILD)/modstm_qstr.h
|
2016-08-19 23:24:04 -04:00
|
|
|
QSTR_DEFS = qstrdefsport.h
|
|
|
|
|
2016-08-23 02:48:09 -04:00
|
|
|
CROSS = 0
|
|
|
|
|
2016-08-19 23:24:04 -04:00
|
|
|
# include py core make definitions
|
|
|
|
include ../py/py.mk
|
|
|
|
|
|
|
|
ifeq ($(CROSS), 1)
|
|
|
|
CROSS_COMPILE = arm-none-eabi-
|
|
|
|
endif
|
|
|
|
|
|
|
|
BOSSAC := /Users/tannewt/ArduinoCore-samd/tools/bossac_osx
|
|
|
|
|
2016-08-23 02:48:09 -04:00
|
|
|
|
|
|
|
HAL_DIR=hal/$(MCU_SERIES)
|
|
|
|
|
2016-08-19 23:24:04 -04:00
|
|
|
INC += -I.
|
|
|
|
INC += -I..
|
|
|
|
INC += -I../lib/mp-readline
|
2016-08-23 02:48:09 -04:00
|
|
|
INC += -Iasf/common/boards/
|
|
|
|
INC += -Iasf/common/services/sleepmgr/
|
|
|
|
INC += -Iasf/common/services/usb/
|
|
|
|
INC += -Iasf/common/services/usb/class/cdc/
|
|
|
|
INC += -Iasf/common/services/usb/class/cdc/device/
|
|
|
|
INC += -Iasf/common/services/usb/udc/
|
|
|
|
INC += -Iasf/common/utils
|
|
|
|
INC += -Iasf/common2/services/delay/
|
|
|
|
INC += $(addprefix -Iasf/sam0/,\
|
|
|
|
drivers/extint/ \
|
|
|
|
drivers/port \
|
|
|
|
drivers/system \
|
2016-08-26 19:56:03 -04:00
|
|
|
drivers/adc/adc_sam_d_r \
|
2016-08-27 18:04:34 -04:00
|
|
|
drivers/dac \
|
|
|
|
drivers/dac/dac_sam_d_c \
|
2016-08-23 02:48:09 -04:00
|
|
|
drivers/system/clock \
|
|
|
|
drivers/system/clock/clock_samd21_r21_da \
|
|
|
|
drivers/system/interrupt \
|
|
|
|
drivers/system/interrupt/system_interrupt_samd21 \
|
|
|
|
drivers/system/pinmux \
|
|
|
|
drivers/system/power/power_sam_d_r \
|
|
|
|
drivers/system/reset/reset_sam_d_r \
|
2016-08-23 19:47:53 -04:00
|
|
|
drivers/sercom/ \
|
2016-08-23 02:48:09 -04:00
|
|
|
drivers/usb/ \
|
|
|
|
utils \
|
|
|
|
utils/cmsis/samd21/include \
|
|
|
|
utils/cmsis/samd21/source \
|
|
|
|
utils/header_files \
|
|
|
|
utils/preprocessor \
|
|
|
|
)
|
|
|
|
INC += -Iasf/thirdparty/CMSIS/Include
|
|
|
|
INC += -Iboards/$(BOARD)/
|
2016-08-19 23:24:04 -04:00
|
|
|
INC += -I$(BUILD)
|
|
|
|
|
|
|
|
ifeq ($(CROSS), 1)
|
2016-08-23 02:48:09 -04:00
|
|
|
CFLAGS_CORTEX_M0 = -mthumb -mabi=aapcs-linux -mcpu=cortex-m0plus -fsingle-precision-constant -Wdouble-promotion -D__SAMD21G18A__ -DUSB_DEVICE_PRODUCT_ID=0x024D -DUSB_DEVICE_VENDOR_ID=0x4123 -DBOARD=USER_BOARD -ffunction-sections -fdata-sections -fshort-enums -D ARM_MATH_CM0PLUS=true -DSYSTICK_MODE -DEXTINT_CALLBACK_MODE=true -DUDD_ENABLE -DUSART_CALLBACK_MODE=true -DUSB_DEVICE_LPM_SUPPORT
|
2016-08-19 23:24:04 -04:00
|
|
|
CFLAGS = $(INC) -Wall -Werror -ansi -std=gnu99 -nostdlib $(CFLAGS_CORTEX_M0) $(COPT)
|
|
|
|
else
|
|
|
|
CFLAGS = -m32 $(INC) -Wall -Werror -ansi -std=gnu99 $(COPT)
|
|
|
|
endif
|
|
|
|
|
|
|
|
#Debugging/Optimization
|
|
|
|
ifeq ($(DEBUG), 1)
|
|
|
|
CFLAGS += -O0 -ggdb
|
|
|
|
else
|
|
|
|
CFLAGS += -Os -DNDEBUG
|
|
|
|
endif
|
|
|
|
|
|
|
|
LIBS =
|
|
|
|
ifeq ($(CROSS), 1)
|
|
|
|
LIBGCC_FILE_NAME = $(shell $(CC) $(CFLAGS) -print-libgcc-file-name)
|
2016-08-23 02:48:09 -04:00
|
|
|
LDFLAGS = -Lasf/thirdparty/CMSIS/Lib/GCC/ -L $(dir $(LIBGCC_FILE_NAME)) -nostdlib -T $(LD_FILE) -Map=$@.map --cref --gc-sections
|
2016-08-19 23:24:04 -04:00
|
|
|
LIBS += -larm_cortexM0l_math -lgcc
|
|
|
|
else
|
|
|
|
LD = gcc
|
|
|
|
LDFLAGS = -m32 -Wl,-Map=$@.map,--cref
|
|
|
|
endif
|
|
|
|
|
2016-08-23 02:48:09 -04:00
|
|
|
|
|
|
|
SRC_ASF = $(addprefix asf/sam0/,\
|
2016-08-27 18:04:34 -04:00
|
|
|
drivers/adc/adc_sam_d_r/adc.c \
|
|
|
|
drivers/dac/dac_sam_d_c/dac.c \
|
2016-08-23 02:48:09 -04:00
|
|
|
drivers/port/port.c \
|
2016-08-23 19:47:53 -04:00
|
|
|
drivers/sercom/sercom.c \
|
|
|
|
drivers/sercom/sercom_interrupt.c \
|
|
|
|
drivers/sercom/usart/usart.c \
|
|
|
|
drivers/sercom/usart/usart_interrupt.c \
|
2016-08-23 02:48:09 -04:00
|
|
|
drivers/system/clock/clock_samd21_r21_da/clock.c \
|
|
|
|
drivers/system/clock/clock_samd21_r21_da/gclk.c \
|
2016-08-23 19:47:53 -04:00
|
|
|
drivers/system/interrupt/system_interrupt.c \
|
2016-08-23 02:48:09 -04:00
|
|
|
drivers/system/pinmux/pinmux.c \
|
|
|
|
drivers/system/system.c \
|
|
|
|
drivers/usb/stack_interface/usb_device_udd.c \
|
|
|
|
drivers/usb/stack_interface/usb_dual.c \
|
|
|
|
drivers/usb/usb_sam_d_r/usb.c \
|
|
|
|
)
|
|
|
|
|
2016-08-19 23:24:04 -04:00
|
|
|
SRC_C = \
|
|
|
|
main.c \
|
2016-08-24 20:38:08 -04:00
|
|
|
modmachine.c \
|
2016-08-28 03:02:05 -04:00
|
|
|
modmachine_adc.c \
|
|
|
|
modmachine_dac.c \
|
|
|
|
modmachine_pin.c \
|
2016-08-24 16:17:55 -04:00
|
|
|
modutime.c \
|
2016-08-23 02:48:09 -04:00
|
|
|
mphalport.c \
|
2016-08-24 20:38:08 -04:00
|
|
|
pin_named_pins.c \
|
2016-08-23 19:47:53 -04:00
|
|
|
uart.c \
|
2016-08-23 02:48:09 -04:00
|
|
|
asf/common/services/sleepmgr/samd/sleepmgr.c \
|
|
|
|
asf/common/services/usb/class/cdc/device/udi_cdc.c \
|
|
|
|
asf/common/services/usb/class/cdc/device/udi_cdc_desc.c \
|
|
|
|
asf/common/services/usb/udc/udc.c \
|
|
|
|
asf/common/utils/interrupt/interrupt_sam_nvic.c \
|
|
|
|
asf/common2/services/delay/sam0/systick_counter.c \
|
2016-08-23 19:47:53 -04:00
|
|
|
asf/sam0/utils/cmsis/samd21/source/gcc/startup_samd21.c \
|
|
|
|
asf/sam0/utils/cmsis/samd21/source/system_samd21.c \
|
|
|
|
asf/sam0/utils/syscalls/gcc/syscalls.c \
|
2016-08-24 20:38:08 -04:00
|
|
|
boards/$(BOARD)/pins.c \
|
2016-08-19 23:24:04 -04:00
|
|
|
lib/utils/stdout_helpers.c \
|
|
|
|
lib/utils/printf.c \
|
|
|
|
lib/utils/pyexec.c \
|
|
|
|
lib/libc/string0.c \
|
2016-08-24 16:17:55 -04:00
|
|
|
lib/mp-readline/readline.c
|
|
|
|
|
|
|
|
SRC_AUTOGEN = \
|
|
|
|
$(BUILD)/_frozen_mpy.c \
|
2016-08-19 23:24:04 -04:00
|
|
|
|
|
|
|
OBJ = $(PY_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
|
2016-08-23 02:48:09 -04:00
|
|
|
OBJ += $(addprefix $(BUILD)/, $(SRC_ASF:.c=.o))
|
2016-08-24 16:17:55 -04:00
|
|
|
OBJ += $(addprefix $(BUILD)/, $(SRC_AUTOGEN:.c=.o))
|
|
|
|
|
|
|
|
SRC_QSTR += $(SRC_C)
|
2016-08-19 23:24:04 -04:00
|
|
|
|
|
|
|
ifeq ($(CROSS), 1)
|
|
|
|
all: $(BUILD)/firmware.bin
|
|
|
|
else
|
|
|
|
all: $(BUILD)/firmware.elf
|
|
|
|
endif
|
|
|
|
|
|
|
|
$(BUILD)/_frozen_mpy.c: frozentest.mpy $(BUILD)/genhdr/qstrdefs.generated.h
|
|
|
|
$(ECHO) "MISC freezing bytecode"
|
|
|
|
$(Q)../tools/mpy-tool.py -f -q $(BUILD)/genhdr/qstrdefs.preprocessed.h -mlongint-impl=none $< > $@
|
|
|
|
|
|
|
|
$(BUILD)/firmware.elf: $(OBJ)
|
|
|
|
$(ECHO) "LINK $@"
|
|
|
|
$(Q)$(LD) $(LDFLAGS) -o $@ $^ $(LIBS)
|
|
|
|
$(Q)$(SIZE) $@
|
|
|
|
|
|
|
|
$(BUILD)/firmware.bin: $(BUILD)/firmware.elf
|
|
|
|
$(ECHO) "Create $@"
|
2016-08-23 19:47:53 -04:00
|
|
|
$(Q)$(OBJCOPY) -O binary -j .vectors -j .text -j .data $^ $@
|
2016-08-19 23:24:04 -04:00
|
|
|
|
|
|
|
deploy: $(BUILD)/firmware.bin
|
|
|
|
$(ECHO) "Writing $< to the board"
|
|
|
|
$(BOSSAC) -u $<
|
|
|
|
|
|
|
|
# Run emulation build on a POSIX system with suitable terminal settings
|
|
|
|
run:
|
|
|
|
stty raw opost -echo
|
|
|
|
build/firmware.elf
|
|
|
|
@echo Resetting terminal...
|
|
|
|
# This sleep is useful to spot segfaults
|
|
|
|
sleep 1
|
|
|
|
reset
|
|
|
|
|
|
|
|
test: $(BUILD)/firmware.elf
|
|
|
|
$(Q)/bin/echo -e "print('hello world!', list(x+1 for x in range(10)), end='eol\\\\n')\\r\\n\\x04" | $(BUILD)/firmware.elf | tail -n2 | grep "^hello world! \\[1, 2, 3, 4, 5, 6, 7, 8, 9, 10\\]eol"
|
|
|
|
|
|
|
|
include ../py/mkrules.mk
|