2019-10-09 02:27:08 -04:00
|
|
|
# This file is part of the MicroPython project, http://micropython.org/
|
|
|
|
#
|
|
|
|
# The MIT License (MIT)
|
|
|
|
#
|
|
|
|
# Copyright 2019 Sony Semiconductor Solutions Corporation
|
|
|
|
#
|
|
|
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
# of this software and associated documentation files (the "Software"), to deal
|
|
|
|
# in the Software without restriction, including without limitation the rights
|
|
|
|
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
# copies of the Software, and to permit persons to whom the Software is
|
|
|
|
# furnished to do so, subject to the following conditions:
|
|
|
|
#
|
|
|
|
# The above copyright notice and this permission notice shall be included in
|
|
|
|
# all copies or substantial portions of the Software.
|
|
|
|
#
|
|
|
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
# THE SOFTWARE.
|
|
|
|
|
2019-10-11 02:54:36 -04:00
|
|
|
# Select the board to build for.
|
|
|
|
ifeq ($(BOARD),)
|
|
|
|
$(error You must provide a BOARD parameter)
|
|
|
|
else
|
|
|
|
ifeq ($(wildcard boards/$(BOARD)/.),)
|
|
|
|
$(error Invalid BOARD specified)
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
|
|
|
# If the build directory is not given, make it reflect the board name.
|
|
|
|
BUILD ?= build-$(BOARD)
|
|
|
|
|
2019-10-09 02:27:08 -04:00
|
|
|
include ../../py/mkenv.mk
|
|
|
|
|
2019-10-11 02:54:36 -04:00
|
|
|
# Board-specific
|
|
|
|
include boards/$(BOARD)/mpconfigboard.mk
|
|
|
|
|
2019-10-09 02:27:08 -04:00
|
|
|
# Port-specific
|
|
|
|
include mpconfigport.mk
|
|
|
|
|
|
|
|
# CircuitPython-specific
|
|
|
|
include $(TOP)/py/circuitpy_mpconfig.mk
|
|
|
|
|
|
|
|
# qstr definitions (must come before including py.mk)
|
|
|
|
QSTR_DEFS = qstrdefsport.h
|
|
|
|
|
|
|
|
# include py core make definitions
|
|
|
|
include $(TOP)/py/py.mk
|
|
|
|
|
|
|
|
include $(TOP)/supervisor/supervisor.mk
|
|
|
|
|
|
|
|
# Include make rules and variables common across CircuitPython builds.
|
|
|
|
include $(TOP)/py/circuitpy_defns.mk
|
|
|
|
|
|
|
|
CROSS_COMPILE = arm-none-eabi-
|
|
|
|
|
|
|
|
SPRESENSE_SDK = spresense-exported-sdk
|
|
|
|
|
|
|
|
FIRMWARE = $(SPRESENSE_SDK)/firmware
|
|
|
|
|
2020-06-30 08:50:09 -04:00
|
|
|
BOOTLOADER_FILES += \
|
|
|
|
$(FIRMWARE)/AESM.espk \
|
|
|
|
$(FIRMWARE)/dnnrt-mp.espk \
|
|
|
|
$(FIRMWARE)/gnssfw.espk \
|
|
|
|
$(FIRMWARE)/loader.espk \
|
|
|
|
$(FIRMWARE)/sysutil.spk \
|
|
|
|
|
2019-10-11 05:17:28 -04:00
|
|
|
# Platforms are: Linux, Darwin, MSYS, CYGWIN
|
|
|
|
PLATFORM := $(firstword $(subst _, ,$(shell uname -s 2>/dev/null)))
|
|
|
|
|
|
|
|
ifeq ($(PLATFORM),Darwin)
|
|
|
|
# macOS
|
2020-01-09 05:01:45 -05:00
|
|
|
MKSPK = mkspk/mkspk
|
2019-10-11 05:17:28 -04:00
|
|
|
else ifeq ($(PLATFORM),Linux)
|
|
|
|
# Linux
|
2020-01-09 05:01:45 -05:00
|
|
|
MKSPK = mkspk/mkspk
|
2019-10-11 05:17:28 -04:00
|
|
|
else
|
|
|
|
# Cygwin/MSYS2
|
2020-01-09 05:01:45 -05:00
|
|
|
MKSPK = mkspk/mkspk.exe
|
2019-10-11 05:17:28 -04:00
|
|
|
endif
|
|
|
|
|
2019-10-11 05:31:32 -04:00
|
|
|
SERIAL ?= /dev/ttyUSB0
|
|
|
|
|
2019-10-09 02:27:08 -04:00
|
|
|
INC += \
|
|
|
|
-I. \
|
|
|
|
-I../.. \
|
|
|
|
-I../lib/mp-readline \
|
|
|
|
-I../lib/timeutils \
|
|
|
|
-I../../lib/tinyusb/src \
|
|
|
|
-I../../supervisor/shared/usb \
|
2019-10-11 02:54:36 -04:00
|
|
|
-Iboards/$(BOARD) \
|
2019-10-09 02:27:08 -04:00
|
|
|
-I$(BUILD) \
|
|
|
|
-I$(SPRESENSE_SDK)/nuttx/include \
|
|
|
|
-I$(SPRESENSE_SDK)/nuttx/arch \
|
|
|
|
-I$(SPRESENSE_SDK)/nuttx/arch/chip \
|
2019-10-18 05:10:22 -04:00
|
|
|
-I$(SPRESENSE_SDK)/nuttx/arch/os \
|
2020-06-30 08:50:09 -04:00
|
|
|
-I$(SPRESENSE_SDK)/sdk/include \
|
2019-10-09 02:27:08 -04:00
|
|
|
|
|
|
|
CFLAGS += \
|
|
|
|
$(INC) \
|
|
|
|
-DCONFIG_WCHAR_BUILTIN \
|
|
|
|
-DCONFIG_HAVE_DOUBLE \
|
|
|
|
-Dmain=spresense_main \
|
|
|
|
-D_estack=__stack \
|
|
|
|
-c \
|
|
|
|
-pipe \
|
|
|
|
-std=gnu11 \
|
|
|
|
-mcpu=cortex-m4 \
|
|
|
|
-mthumb \
|
|
|
|
-mfpu=fpv4-sp-d16 \
|
|
|
|
-mfloat-abi=hard \
|
|
|
|
-mabi=aapcs \
|
|
|
|
-fno-builtin \
|
|
|
|
-fno-strict-aliasing \
|
|
|
|
-fno-strength-reduce \
|
|
|
|
-fomit-frame-pointer \
|
|
|
|
-ffunction-sections \
|
|
|
|
-fdata-sections \
|
|
|
|
-Wall \
|
|
|
|
|
2020-07-23 20:27:02 -04:00
|
|
|
OPTIMIZATION_FLAGS ?= -O2
|
|
|
|
|
2020-07-22 13:44:41 -04:00
|
|
|
# option to override compiler optimization level, set in boards/$(BOARD)/mpconfigboard.mk
|
2020-07-23 20:27:02 -04:00
|
|
|
CFLAGS += $(OPTIMIZATION_FLAGS)
|
2020-07-21 11:11:08 -04:00
|
|
|
|
|
|
|
|
2019-10-09 02:27:08 -04:00
|
|
|
LIBM = "${shell "$(CC)" $(CFLAGS) -print-file-name=libm.a}"
|
|
|
|
|
|
|
|
LIBGCC = "${shell "$(CC)" $(CFLAGS) -print-libgcc-file-name}"
|
|
|
|
|
|
|
|
LDFLAGS = \
|
|
|
|
--entry=__start \
|
|
|
|
-nostartfiles \
|
|
|
|
-nodefaultlibs \
|
2020-06-30 08:50:09 -04:00
|
|
|
-T$(SPRESENSE_SDK)/nuttx/scripts/ramconfig.ld \
|
2019-10-09 02:27:08 -04:00
|
|
|
--gc-sections \
|
|
|
|
-Map=$(BUILD)/output.map \
|
2019-10-11 11:15:25 -04:00
|
|
|
-o $(BUILD)/firmware.elf \
|
2019-10-09 02:27:08 -04:00
|
|
|
--start-group \
|
|
|
|
-u spresense_main \
|
2020-01-10 07:59:10 -05:00
|
|
|
-u board_timerhook \
|
2019-10-09 02:27:08 -04:00
|
|
|
$(BUILD)/libmpy.a \
|
2020-06-30 08:50:09 -04:00
|
|
|
$(SPRESENSE_SDK)/nuttx/libs/libapps.a \
|
|
|
|
$(SPRESENSE_SDK)/nuttx/libs/libnuttx.a \
|
2019-10-09 02:27:08 -04:00
|
|
|
$(LIBM) \
|
|
|
|
$(LIBGCC) \
|
|
|
|
--end-group \
|
|
|
|
-L$(BUILD) \
|
|
|
|
|
|
|
|
CFLAGS += -DCFG_TUSB_MCU=OPT_MCU_CXD56 -DCFG_TUD_MIDI_RX_BUFSIZE=128 -DCFG_TUD_CDC_RX_BUFSIZE=256 -DCFG_TUD_MIDI_TX_BUFSIZE=128 -DCFG_TUD_CDC_TX_BUFSIZE=256 -DCFG_TUD_MSC_BUFSIZE=512 $(CFLAGS_MOD)
|
|
|
|
|
|
|
|
SRC_COMMON_HAL_EXPANDED = $(addprefix shared-bindings/, $(SRC_COMMON_HAL)) \
|
|
|
|
$(addprefix shared-bindings/, $(SRC_BINDINGS_ENUMS)) \
|
|
|
|
$(addprefix common-hal/, $(SRC_COMMON_HAL))
|
|
|
|
|
|
|
|
SRC_SHARED_MODULE_EXPANDED = $(addprefix shared-bindings/, $(SRC_SHARED_MODULE)) \
|
|
|
|
$(addprefix shared-module/, $(SRC_SHARED_MODULE))
|
|
|
|
|
|
|
|
SRC_S = supervisor/cpu.s
|
|
|
|
|
|
|
|
SRC_C = \
|
|
|
|
background.c \
|
|
|
|
fatfs_port.c \
|
|
|
|
mphalport.c \
|
2019-10-11 02:54:36 -04:00
|
|
|
boards/$(BOARD)/board.c \
|
|
|
|
boards/$(BOARD)/pins.c \
|
2019-10-09 02:27:08 -04:00
|
|
|
lib/utils/stdout_helpers.c \
|
|
|
|
lib/utils/pyexec.c \
|
|
|
|
lib/libc/string0.c \
|
|
|
|
lib/mp-readline/readline.c \
|
|
|
|
lib/timeutils/timeutils.c \
|
|
|
|
lib/oofatfs/ff.c \
|
|
|
|
lib/oofatfs/option/ccsbcs.c \
|
|
|
|
lib/utils/interrupt_char.c \
|
|
|
|
lib/utils/sys_stdio_mphal.c \
|
|
|
|
lib/utils/context_manager_helpers.c \
|
|
|
|
lib/utils/buffer_helper.c \
|
|
|
|
supervisor/shared/memory.c \
|
|
|
|
lib/tinyusb/src/portable/sony/cxd56/dcd_cxd56.c \
|
|
|
|
|
|
|
|
OBJ = $(PY_O) $(SUPERVISOR_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
|
|
|
|
OBJ += $(addprefix $(BUILD)/, $(SRC_S:.s=.o))
|
|
|
|
OBJ += $(addprefix $(BUILD)/, $(SRC_COMMON_HAL_EXPANDED:.c=.o))
|
|
|
|
OBJ += $(addprefix $(BUILD)/, $(SRC_SHARED_MODULE_EXPANDED:.c=.o))
|
2020-03-09 16:52:55 -04:00
|
|
|
ifeq ($(INTERNAL_LIBM),1)
|
|
|
|
OBJ += $(addprefix $(BUILD)/, $(SRC_LIBM:.c=.o))
|
|
|
|
endif
|
|
|
|
OBJ += $(addprefix $(BUILD)/, $(SRC_MOD:.c=.o))
|
2019-10-09 02:27:08 -04:00
|
|
|
|
|
|
|
# List of sources for qstr extraction
|
|
|
|
SRC_QSTR += $(SRC_C) $(SRC_SUPERVISOR) $(SRC_COMMON_HAL_EXPANDED) $(SRC_SHARED_MODULE_EXPANDED)
|
|
|
|
# Sources that only hold QSTRs after pre-processing.
|
2020-03-17 17:21:45 -04:00
|
|
|
SRC_QSTR_PREPROCESSOR +=
|
2019-10-09 02:27:08 -04:00
|
|
|
|
2019-10-11 11:15:25 -04:00
|
|
|
all: $(BUILD)/firmware.spk
|
2019-10-09 02:27:08 -04:00
|
|
|
|
|
|
|
$(FIRMWARE):
|
|
|
|
$(ECHO) ""
|
|
|
|
$(ECHO) "Download the spresense binaries zip archive from:"
|
|
|
|
$(ECHO) "https://developer.sony.com/file/download/download-spresense-firmware-v1-4-000"
|
|
|
|
$(ECHO) "Extract spresense binaries to $(FIRMWARE)"
|
|
|
|
$(ECHO) ""
|
|
|
|
$(ECHO) "run make flash-bootloader again to flash bootloader."
|
|
|
|
exit 1
|
|
|
|
|
2020-03-17 17:21:45 -04:00
|
|
|
$(BUILD)/libmpy.a: $(SPRESENSE_SDK) $(OBJ)
|
2019-10-09 02:27:08 -04:00
|
|
|
$(ECHO) "AR $@"
|
|
|
|
$(Q)$(AR) rcs $(BUILD)/libmpy.a $(OBJ)
|
|
|
|
|
2019-10-11 11:15:25 -04:00
|
|
|
$(BUILD)/firmware.elf: $(BUILD)/libmpy.a
|
2019-10-09 02:27:08 -04:00
|
|
|
$(ECHO) "LD $@"
|
|
|
|
$(Q)$(LD) $(LDFLAGS)
|
|
|
|
|
2020-01-09 05:01:45 -05:00
|
|
|
$(MKSPK):
|
|
|
|
$(MAKE) -C mkspk
|
|
|
|
|
|
|
|
$(BUILD)/firmware.spk: $(BUILD)/firmware.elf $(MKSPK)
|
2019-10-09 02:27:08 -04:00
|
|
|
$(ECHO) "Creating $@"
|
2019-10-11 11:15:25 -04:00
|
|
|
$(MKSPK) -c 2 $(BUILD)/firmware.elf nuttx $(BUILD)/firmware.spk
|
2019-10-09 02:27:08 -04:00
|
|
|
|
2019-10-11 11:15:25 -04:00
|
|
|
flash: $(BUILD)/firmware.spk
|
2019-10-09 02:27:08 -04:00
|
|
|
$(ECHO) "Writing $< to the board"
|
2020-06-30 08:50:09 -04:00
|
|
|
tools/flash_writer.py -s -c $(SERIAL) -d -b 115200 -n $(BUILD)/firmware.spk
|
2019-10-09 02:27:08 -04:00
|
|
|
|
|
|
|
flash-bootloader: $(SPRESENSE_SDK) $(FIRMWARE)
|
|
|
|
$(ECHO) "Writing loader to the board"
|
2020-06-30 08:50:09 -04:00
|
|
|
tools/flash_writer.py -s -c $(SERIAL) -d -b 115200 -n $(BOOTLOADER_FILES)
|
2019-10-09 02:27:08 -04:00
|
|
|
|
|
|
|
include $(TOP)/py/mkrules.mk
|
|
|
|
|
|
|
|
# Print out the value of a make variable.
|
|
|
|
# https://stackoverflow.com/questions/16467718/how-to-print-out-a-variable-in-makefile
|
|
|
|
print-%:
|
|
|
|
@echo $* = $($*)
|