# define the cpu used by the Mulle board export CPU = k60 # Default GDB port export GDBPORT ?= 3333 # MULLE_SERIAL is used to select which specific Mulle board we are compiling for. # This was called MULLE_BOARD_SERIAL_NUMBER previously, renamed because # MULLE_BOARD_SERIAL_NUMBER is too long to type. ifdef MULLE_SERIAL ifeq "200" "$(word 1, $(sort 200 $(MULLE_SERIAL)))" # >= 200 ifneq "220" "$(word 1, $(sort 220 $(MULLE_SERIAL)))" # < 220 CPU_MODEL = K60DN256ZVLL10 # It seems some of the MK60DZ10 devices have problems with JTAG speeds >= around 400 KHz # when programming, we reduce the speed to 300 KHz with this command. CPU_OOCD_FLAGS += -c 'adapter_khz 300' else # >= 220 CPU_MODEL = K60DN512VLL10 endif endif CFLAGS += -DMULLE_SERIAL=$(MULLE_SERIAL) endif ### CPU part number (must have a specific linker script for each part) # Note that MK60DN256ZVLL10 (version 1.x) and MK60DN256VLL10 (version 2.x, no Z) # only differ in some register locations etc, not in the actual memory layout, # so it is safe to use the same linker script for both version 1.x and version # 2.x silicon. # The linker script needs to know the flash and RAM sizes of the device. ifeq ($(CPU_MODEL),) CPU_MODEL = K60DN512VLL10 endif export CPU_MODEL # Host OS name OS := $(shell uname) # OpenOCD settings for Mulle board. # Try to determine which version of the OpenOCD config file we should use. # Specify PROGRAMMER_VERSION or PROGRAMMER_SERIAL to choose a specific programmer board. ifeq ($(PROGRAMMER_VERSION),) ifneq ($(PROGRAMMER_SERIAL),) # Makefile-way of comparing numbers, using lexicographical sorting since we don't have any arithmetic comparisons. # Programmers with serial 100 -- 148 are version 0.60 # Programmers with serial 301 -- 330 are version 0.70 ifeq "100" "$(word 1, $(sort 100 $(PROGRAMMER_SERIAL)))" # >= 100 ifneq "149" "$(word 1, $(sort 149 $(PROGRAMMER_SERIAL)))" # < 149 PROGRAMMER_VERSION = 0.60 else # >= 149 PROGRAMMER_VERSION = 0.70 endif endif endif # Default to version 0.60 programmer for now. PROGRAMMER_VERSION ?= 0.60 endif export OPENOCD_CONFIG = $(RIOTBOARD)/$(BOARD)/dist/openocd/mulle-programmer-$(PROGRAMMER_VERSION).conf # Add serial matching command ifneq ($(PROGRAMMER_SERIAL),) OPENOCD_EXTRA_INIT += -c 'ftdi_serial $(PROGRAMMER_SERIAL)' endif OPENOCD_EXTRA_INIT += $(CPU_OOCD_FLAGS) ifeq ($(PORT),) # try to find tty name by serial number, only works on Linux currently. ifeq ($(OS),Linux) ifneq ($(PROGRAMMER_SERIAL),) PORT := $(shell $(RIOTBASE)/dist/tools/usb-serial/find-tty.sh '^$(PROGRAMMER_SERIAL)$$') else # find-tty.sh will return the first USB tty if no serial is given. PORT := $(shell $(RIOTBASE)/dist/tools/usb-serial/find-tty.sh) endif else ifeq ($(OS),Darwin) PORT := $(shell ls -1 /dev/tty.usbserial* | head -n 1) endif endif # TODO: add support for windows as host platform ifeq ($(PORT),) # None of the above methods worked, set some sane default value for PORT. $(info CAUTION: No terminal port for your host system found!) PORT := /dev/ttyUSB0 endif export PORT # Default optimization level, possible to override from command line. OPTIMIZATION ?= -Os # Default debug level DEBUG_CFLAGS ?= -g3 -ggdb # Target triple for the build. Use arm-none-eabi if you are unsure. export TARGET_TRIPLE ?= arm-none-eabi # Toolchain prefix, defaults to target triple followed by a dash, you will most likely not need to touch this. export PREFIX ?= $(if $(TARGET_TRIPLE),$(TARGET_TRIPLE)-) export GDBPREFIX ?= $(PREFIX) # define tools used for building the project export CC = $(PREFIX)gcc export CXX = $(PREFIX)g++ export AR = $(PREFIX)ar export AS = $(PREFIX)as export LINK = $(PREFIX)gcc export SIZE = $(PREFIX)size export OBJCOPY = $(PREFIX)objcopy export OPENOCD ?= openocd export GDB ?= $(GDBPREFIX)gdb export DBG = $(GDB) export TERMPROG ?= $(RIOTBASE)/dist/tools/pyterm/pyterm export FLASHER = $(RIOTBASE)/dist/tools/openocd/openocd.sh export DEBUGGER = $(RIOTBASE)/dist/tools/openocd/openocd.sh export DEBUGSERVER = $(RIOTBASE)/dist/tools/openocd/openocd.sh export RESET = $(RIOTBASE)/dist/tools/openocd/openocd.sh export TERMFLAGS += -p "$(PORT)" export FFLAGS = flash export DEBUGGER_FLAGS = debug export DEBUGSERVER_FLAGS = debug-server export RESET_FLAGS = reset # We need special handling of the watchdog if we want to speed up the flash # verification by using the MCU to compute the image checksum after flashing. # wdog-disable.bin is a precompiled binary which will disable the watchdog and # return control to the debugger (OpenOCD) export OPENOCD_PRE_VERIFY_CMDS += \ -c 'load_image $(RIOTCPU)/kinetis_common/dist/wdog-disable.bin 0x20000000 bin' \ -c 'resume 0x20000000' export OPENOCD_EXTRA_INIT export PRE_FLASH_CHECK_SCRIPT = $(RIOTCPU)/kinetis_common/dist/check-fcfield-hex.sh .PHONY: flash flash: $(RIOTCPU)/kinetis_common/dist/wdog-disable.bin # Reset the default goal. .DEFAULT_GOAL := # define build specific options CPU_USAGE = -mcpu=cortex-m4 FPU_USAGE = -mfloat-abi=soft -msoft-float export CFLAGS += \ $(DEBUG_CFLAGS) \ -std=gnu99 \ $(OPTIMIZATION) \ -Wall -Wstrict-prototypes -Werror=implicit-function-declaration \ $(CPU_USAGE) \ $(FPU_USAGE) \ -mlittle-endian \ -mthumb \ -fno-common \ -fshort-enums \ -ffunction-sections \ -fdata-sections \ -fno-builtin \ -fno-strict-aliasing \ -fsigned-char \ # export CXXFLAGS += \ -ffunction-sections \ -fdata-sections \ -fno-builtin \ # export ASFLAGS += \ $(DEBUG_CFLAGS) \ $(CPU_USAGE) \ $(FPU_USAGE) \ -mlittle-endian \ # export LINKFLAGS += \ $(DEBUG_CFLAGS) \ -std=gnu99 \ $(CPU_USAGE) \ $(FPU_USAGE) \ -mlittle-endian \ -static \ -mthumb \ -nostartfiles \ -Wl,--fatal-warnings \ # export LINKFLAGS += -T$(LINKERSCRIPT) export OFLAGS ?= -O ihex ifdef BUILD_WITH_CLANG ifneq ($(BUILD_WITH_CLANG),0) export CFLAGS += -target $(TARGET_TRIPLE) export CXXFLAGS += -target $(TARGET_TRIPLE) export LINKFLAGS += -target $(TARGET_TRIPLE) export CC = clang export CXX = clang++ export LINK = clang export LLVMPREFIX ?= llvm- export AS = $(LLVMPREFIX)as export AR = $(LLVMPREFIX)ar export NM = $(LLVMPREFIX)nm # There is no LLVM linker yet, use binutils. #export LINKER = $(LLVMPREFIX)ld # objcopy does not have a clear substitute in LLVM #export OBJCOPY = $(LLVMPREFIX)objcopy export OBJDUMP = $(LLVMPREFIX)objdump # LLVM lacks a binutils strip tool as well... #export STRIP = $(LLVMPREFIX)strip export SIZE = $(LLVMPREFIX)size # Since Clang is not installed as a separate instance for each crossdev target # we need to tell it where to look for platform specific includes (Newlib # headers instead of Linux/Glibc headers.) # On GCC this is done when building the cross compiler toolchain so we do not # actually need to specify the include paths for system includes. # Ubuntu gcc-arm-embedded toolchain (https://launchpad.net/gcc-arm-embedded) # places newlib headers in several places, but the primary source seem to be # /etc/alternatives/gcc-arm-none-eabi-include # Gentoo crossdev places newlib headers in /usr/arm-none-eabi/include # Ubuntu also seem to put a copy of the newlib headers in the same place as # Gentoo crossdev, but we prefer to look at /etc/alternatives first. # On OSX, newlib includes are possibly located in # /usr/local/opt/arm-none-eabi*/arm-none-eabi/include NEWLIB_INCLUDE_PATTERNS ?= \ /etc/alternatives/gcc-$(TARGET_TRIPLE)-include \ /usr/$(TARGET_TRIPLE)/include \ /usr/local/opt/$(TARGET_TRIPLE)*/$(TARGET_TRIPLE)/include \ # # Use the wildcard Makefile function to search for existing directories matching # the patterns above. We use the -isystem gcc/clang argument to add the include # directories as system include directories. NEWLIB_INCLUDES ?= \ $(foreach dir, \ $(foreach pat, $(NEWLIB_INCLUDE_PATTERNS), $(wildcard $(pat))), \ -isystem $(dir)) endif endif export INCLUDES += $(NEWLIB_INCLUDES) # use newlib nano-specs if available ifeq ($(shell $(LINK) -specs=nano.specs -E - 2>/dev/null >/dev/null