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
|
|
|
|
|
|
|
|
# include py core make definitions
|
|
|
|
include ../py/py.mk
|
|
|
|
|
|
|
|
CROSS_COMPILE = arm-none-eabi-
|
|
|
|
|
2016-09-20 18:16:12 -04:00
|
|
|
BOSSAC := tools/bossac_osx
|
2016-08-19 23:24:04 -04:00
|
|
|
|
2016-08-23 02:48:09 -04:00
|
|
|
HAL_DIR=hal/$(MCU_SERIES)
|
|
|
|
|
2016-10-14 07:39:42 -04:00
|
|
|
# Frozen bytecode configuration. Any .py files placed in the modules subdirectory
|
|
|
|
# will be frozen into .mpy files and embedded in the firmware (like the ESP8266
|
|
|
|
# port).
|
|
|
|
MPY_CROSS = ../mpy-cross/mpy-cross
|
|
|
|
MPY_TOOL = ../tools/mpy-tool.py
|
|
|
|
FROZEN_MPY_DIR = modules
|
|
|
|
FROZEN_MPY_PY_FILES := $(shell find -L $(FROZEN_MPY_DIR) -type f -name '*.py')
|
|
|
|
FROZEN_MPY_MPY_FILES := $(addprefix $(BUILD)/,$(FROZEN_MPY_PY_FILES:.py=.mpy))
|
|
|
|
|
2016-08-19 23:24:04 -04:00
|
|
|
INC += -I.
|
|
|
|
INC += -I..
|
|
|
|
INC += -I../lib/mp-readline
|
2016-09-02 20:00:30 -04:00
|
|
|
INC += -I../lib/timeutils
|
2016-09-13 14:46:22 -04:00
|
|
|
INC += -Icommon-hal/modules/
|
2016-10-11 18:48:43 -04:00
|
|
|
INC += -Iasf_conf/
|
2016-08-23 02:48:09 -04:00
|
|
|
INC += -Iasf/common/boards/
|
|
|
|
INC += -Iasf/common/services/sleepmgr/
|
2016-10-05 14:07:29 -04:00
|
|
|
INC += -Iasf/common/services/storage/ctrl_access/
|
2016-08-23 02:48:09 -04:00
|
|
|
INC += -Iasf/common/services/usb/
|
|
|
|
INC += -Iasf/common/services/usb/class/cdc/
|
|
|
|
INC += -Iasf/common/services/usb/class/cdc/device/
|
2016-10-05 14:07:29 -04:00
|
|
|
INC += -Iasf/common/services/usb/class/msc/
|
|
|
|
INC += -Iasf/common/services/usb/class/msc/device/
|
2016-08-23 02:48:09 -04:00
|
|
|
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-09-13 14:46:22 -04:00
|
|
|
drivers/sercom \
|
|
|
|
drivers/sercom/i2c \
|
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-09-13 14:46:22 -04:00
|
|
|
drivers/tc \
|
|
|
|
drivers/usb \
|
2016-08-23 02:48:09 -04:00
|
|
|
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)
|
|
|
|
|
2016-08-31 16:37:43 -04:00
|
|
|
CFLAGS_CORTEX_M0 = \
|
|
|
|
-mthumb \
|
|
|
|
-mabi=aapcs-linux \
|
|
|
|
-mcpu=cortex-m0plus \
|
|
|
|
-msoft-float \
|
|
|
|
-mfloat-abi=soft \
|
|
|
|
-fsingle-precision-constant \
|
|
|
|
-Wdouble-promotion \
|
|
|
|
-D__SAMD21G18A__ \
|
2016-10-05 14:07:29 -04:00
|
|
|
-DUSB_DEVICE_PRODUCT_ID=$(USB_PID) \
|
|
|
|
-DUSB_DEVICE_VENDOR_ID=$(USB_VID) \
|
2016-08-31 16:37:43 -04:00
|
|
|
-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 \
|
2016-10-25 17:27:59 -04:00
|
|
|
-DTC_ASYNC=true \
|
2016-08-31 16:37:43 -04:00
|
|
|
-DUSB_DEVICE_LPM_SUPPORT
|
2016-08-19 23:24:04 -04:00
|
|
|
CFLAGS = $(INC) -Wall -Werror -ansi -std=gnu99 -nostdlib $(CFLAGS_CORTEX_M0) $(COPT)
|
|
|
|
|
|
|
|
#Debugging/Optimization
|
2016-10-04 19:13:33 -04:00
|
|
|
# TODO(tannewt): Figure out what NDEBUG does. Adding it to the debug build
|
|
|
|
# reduces code size pretty dramatically.
|
2016-08-19 23:24:04 -04:00
|
|
|
ifeq ($(DEBUG), 1)
|
2016-10-04 19:13:33 -04:00
|
|
|
CFLAGS += -Os -ggdb -DNDEBUG -DENABLE_MICRO_TRACE_BUFFER
|
2016-08-19 23:24:04 -04:00
|
|
|
else
|
2016-08-31 03:16:39 -04:00
|
|
|
CFLAGS += -Os -DNDEBUG
|
2016-08-19 23:24:04 -04:00
|
|
|
endif
|
|
|
|
|
|
|
|
LIBGCC_FILE_NAME = $(shell $(CC) $(CFLAGS) -print-libgcc-file-name)
|
2016-08-31 16:37:43 -04:00
|
|
|
LIBM_FILE_NAME = $(shell $(CC) $(CFLAGS) -print-file-name=libm.a)
|
|
|
|
LDFLAGS = -Lasf/thirdparty/CMSIS/Lib/GCC/ -L $(dir $(LIBGCC_FILE_NAME)) -L $(dir $(LIBM_FILE_NAME)) -nostdlib -T $(LD_FILE) -Map=$@.map --cref --gc-sections
|
2016-09-13 14:46:22 -04:00
|
|
|
LIBS = -larm_cortexM0l_math -lm -lgcc -lc
|
2016-08-19 23:24:04 -04:00
|
|
|
|
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-09-02 20:00:30 -04:00
|
|
|
drivers/nvm/nvm.c \
|
2016-08-23 02:48:09 -04:00
|
|
|
drivers/port/port.c \
|
2016-09-13 14:46:22 -04:00
|
|
|
drivers/sercom/i2c/i2c_sam0/i2c_master.c \
|
2016-08-23 19:47:53 -04:00
|
|
|
drivers/sercom/sercom.c \
|
|
|
|
drivers/sercom/sercom_interrupt.c \
|
2016-10-11 18:48:43 -04:00
|
|
|
drivers/sercom/spi/spi.c \
|
2016-08-23 19:47:53 -04:00
|
|
|
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 \
|
2016-10-25 17:27:59 -04:00
|
|
|
drivers/tc/tc_interrupt.c \
|
2016-08-30 16:10:52 -04:00
|
|
|
drivers/tc/tc_sam_d_r/tc.c \
|
|
|
|
drivers/tcc/tcc.c \
|
2016-08-23 02:48:09 -04:00
|
|
|
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 = \
|
2016-10-13 17:53:31 -04:00
|
|
|
access_vfs.c \
|
2016-10-25 17:27:59 -04:00
|
|
|
autoreset.c \
|
2016-09-02 20:00:30 -04:00
|
|
|
builtin_open.c \
|
|
|
|
fatfs_port.c \
|
2016-08-19 23:24:04 -04:00
|
|
|
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-30 16:10:52 -04:00
|
|
|
modmachine_pwm.c \
|
2016-10-05 15:35:23 -04:00
|
|
|
modneopixel_write.c \
|
2016-09-02 20:00:30 -04:00
|
|
|
moduos.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-10-05 15:35:23 -04:00
|
|
|
samdneopixel.c \
|
2016-10-13 17:53:31 -04:00
|
|
|
$(FLASH_IMPL) \
|
2016-08-23 02:48:09 -04:00
|
|
|
asf/common/services/sleepmgr/samd/sleepmgr.c \
|
2016-10-05 14:07:29 -04:00
|
|
|
asf/common/services/storage/ctrl_access/ctrl_access.c \
|
2016-08-23 02:48:09 -04:00
|
|
|
asf/common/services/usb/class/cdc/device/udi_cdc.c \
|
2016-10-05 14:07:29 -04:00
|
|
|
asf/common/services/usb/class/composite/device/udi_composite_desc.c \
|
|
|
|
asf/common/services/usb/class/msc/device/udi_msc.c \
|
2016-08-23 02:48:09 -04:00
|
|
|
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 \
|
2016-09-13 14:46:22 -04:00
|
|
|
asf/sam0/utils/cmsis/samd21/source/system_samd21.c \
|
2016-08-23 19:47:53 -04:00
|
|
|
asf/sam0/utils/syscalls/gcc/syscalls.c \
|
2016-09-15 20:01:19 -04:00
|
|
|
boards/$(BOARD)/init.c \
|
2016-08-24 20:38:08 -04:00
|
|
|
boards/$(BOARD)/pins.c \
|
2016-09-02 20:00:30 -04:00
|
|
|
lib/fatfs/ff.c \
|
|
|
|
lib/fatfs/option/ccsbcs.c \
|
|
|
|
lib/timeutils/timeutils.c \
|
2016-08-19 23:24:04 -04:00
|
|
|
lib/utils/stdout_helpers.c \
|
|
|
|
lib/utils/pyexec.c \
|
|
|
|
lib/libc/string0.c \
|
2016-08-24 16:17:55 -04:00
|
|
|
lib/mp-readline/readline.c
|
|
|
|
|
2016-09-21 18:13:37 -04:00
|
|
|
STM_SRC_C = $(addprefix stmhal/,\
|
|
|
|
pybstdio.c \
|
|
|
|
input.c \
|
|
|
|
)
|
|
|
|
|
2016-09-13 14:46:22 -04:00
|
|
|
# TODO(tannewt): Use this sed line to extract the RST docs from these sources:
|
|
|
|
# sed': sed -n 's+^//|++p' ../api/machine.c
|
|
|
|
#
|
|
|
|
# RST lines are prefixed with //|
|
|
|
|
SRC_BINDINGS = \
|
|
|
|
modules/machine.c
|
|
|
|
|
|
|
|
SRC_BINDINGS_EXPANDED = $(addprefix shared-bindings/, $(SRC_BINDINGS)) \
|
|
|
|
$(addprefix common-hal/, $(SRC_BINDINGS))
|
|
|
|
|
2016-08-24 16:17:55 -04:00
|
|
|
SRC_AUTOGEN = \
|
2016-10-14 07:39:42 -04:00
|
|
|
$(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))
|
2016-09-21 18:13:37 -04:00
|
|
|
OBJ += $(addprefix $(BUILD)/, $(STM_SRC_C:.c=.o))
|
2016-09-13 14:46:22 -04:00
|
|
|
OBJ += $(addprefix $(BUILD)/, $(SRC_BINDINGS_EXPANDED:.c=.o))
|
2016-08-24 16:17:55 -04:00
|
|
|
|
2016-09-21 18:13:37 -04:00
|
|
|
SRC_QSTR += $(SRC_C) $(SRC_BINDINGS_EXPANDED) $(STM_SRC_C)
|
2016-08-19 23:24:04 -04:00
|
|
|
|
|
|
|
all: $(BUILD)/firmware.bin
|
|
|
|
|
2016-10-14 07:39:42 -04:00
|
|
|
# to build .mpy files from .py files
|
|
|
|
$(BUILD)/$(FROZEN_MPY_DIR)/%.mpy: $(FROZEN_MPY_DIR)/%.py
|
|
|
|
@$(ECHO) "MPY $<"
|
|
|
|
$(Q)$(MKDIR) -p $(dir $@)
|
|
|
|
$(Q)$(MPY_CROSS) -o $@ -s $(^:$(FROZEN_MPY_DIR)/%=%) $^
|
|
|
|
|
|
|
|
# to build frozen_mpy.c from all .mpy files
|
|
|
|
$(BUILD)/frozen_mpy.c: $(FROZEN_MPY_MPY_FILES) $(BUILD)/genhdr/qstrdefs.generated.h
|
|
|
|
@$(ECHO) "Creating $@"
|
|
|
|
$(Q)$(PYTHON) $(MPY_TOOL) -f -q $(BUILD)/genhdr/qstrdefs.preprocessed.h -mlongint-impl=none $(FROZEN_MPY_MPY_FILES) > $@
|
2016-08-19 23:24:04 -04:00
|
|
|
|
|
|
|
$(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
|