Created
June 1, 2017 12:11
-
-
Save illustris/e382d8eed0d9e6aa40c3888887b79bc3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The name of your project (used to name the compiled .hex file) | |
TARGET = $(notdir $(CURDIR)) | |
# The teensy version to use, 30, 31, 35, 36, or LC | |
TEENSY = 36 | |
# Set to 24000000, 48000000, or 96000000 to set CPU core speed | |
#TEENSY_CORE_SPEED = 48000000 | |
TEENSY_CORE_SPEED = 180000000 | |
# Some libraries will require this to be defined | |
# If you define this, you will break the default main.cpp | |
#ARDUINO = 10600 | |
# configurable options | |
OPTIONS = -DUSB_SERIAL -DLAYOUT_US_ENGLISH | |
# directory to build in | |
BUILDDIR = $(abspath $(CURDIR)/build) | |
#************************************************************************ | |
# Location of Teensyduino utilities, Toolchain, and Arduino Libraries. | |
# To use this makefile without Arduino, copy the resources from these | |
# locations and edit the pathnames. The rest of Arduino is not needed. | |
#************************************************************************ | |
# path location for Teensy Loader, teensy_post_compile and teensy_reboot | |
TOOLSPATH = $(CURDIR)/tools | |
ifeq ($(OS),Windows_NT) | |
$(error What is Win Dose?) | |
else | |
UNAME_S := $(shell uname -s) | |
ifeq ($(UNAME_S),Darwin) | |
TOOLSPATH = /Applications/Arduino.app/Contents/Java/hardware/tools/ | |
endif | |
endif | |
# path location for Teensy 3 core | |
COREPATH = teensy3 | |
# path location for Arduino libraries | |
LIBRARYPATH = libraries | |
# path location for the arm-none-eabi compiler | |
COMPILERPATH = $(TOOLSPATH)/arm/bin | |
# path location for FreeRTOS directory structure | |
FREERTOSPATH = FreeRTOS/Source | |
FREERTOSPORT = portable/GCC/ARM_CM4F | |
#************************************************************************ | |
# Settings below this point usually do not need to be edited | |
#************************************************************************ | |
# CPPFLAGS = compiler options for C and C++ | |
CPPFLAGS = -Wall -g -Os -mthumb -ffunction-sections -fdata-sections -nostdlib -MMD $(OPTIONS) -DTEENSYDUINO=124 -DF_CPU=$(TEENSY_CORE_SPEED) -Isrc -I$(COREPATH) -I$(FREERTOSPATH)/include -I$(FREERTOSPATH)/$(FREERTOSPORT) | |
# compiler options for C++ only | |
CXXFLAGS = -std=gnu++0x -felide-constructors -fno-exceptions -fno-rtti | |
# compiler options for C only | |
CFLAGS = | |
# linker options | |
LDFLAGS = -Os -Wl,--gc-sections -mthumb | |
# additional libraries to link | |
LIBS = -lm | |
# compiler options specific to teensy version | |
ifeq ($(TEENSY), 30) | |
CPPFLAGS += -D__MK20DX128__ -mcpu=cortex-m4 | |
LDSCRIPT = $(COREPATH)/mk20dx128.ld | |
LDFLAGS += -mcpu=cortex-m4 -T$(LDSCRIPT) | |
else ifeq ($(TEENSY), 31) | |
CPPFLAGS += -D__MK20DX256__ -mcpu=cortex-m4 | |
LDSCRIPT = $(COREPATH)/mk20dx256.ld | |
LDFLAGS += -mcpu=cortex-m4 -T$(LDSCRIPT) | |
else ifeq ($(TEENSY), LC) | |
CPPFLAGS += -D__MKL26Z64__ -mcpu=cortex-m0plus | |
LDSCRIPT = $(COREPATH)/mkl26z64.ld | |
LDFLAGS += -mcpu=cortex-m0plus -T$(LDSCRIPT) | |
LIBS += -larm_cortexM0l_math | |
else ifeq ($(TEENSY), 35) | |
CPPFLAGS += -D__MK64FX512__ -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 | |
LDSCRIPT = $(COREPATH)/mk64fx512.ld | |
LDFLAGS += -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -T$(LDSCRIPT) | |
LIBS += -larm_cortexM4lf_math | |
else ifeq ($(TEENSY), 36) | |
CPPFLAGS += -D__MK66FX1M0__ -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 | |
LDSCRIPT = $(COREPATH)/mk66fx1m0.ld | |
LDFLAGS += -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -T$(LDSCRIPT) | |
LIBS += -larm_cortexM4lf_math | |
else | |
$(error Invalid setting for TEENSY) | |
endif | |
# set arduino define if given | |
ifdef ARDUINO | |
CPPFLAGS += -DARDUINO=$(ARDUINO) | |
else | |
CPPFLAGS += -DUSING_MAKEFILE | |
endif | |
# names for the compiler programs | |
CC = $(abspath $(COMPILERPATH))/arm-none-eabi-gcc | |
CXX = $(abspath $(COMPILERPATH))/arm-none-eabi-g++ | |
OBJCOPY = $(abspath $(COMPILERPATH))/arm-none-eabi-objcopy | |
SIZE = $(abspath $(COMPILERPATH))/arm-none-eabi-size | |
# automatically create lists of the sources and objects | |
LC_FILES := $(shell find $(LIBRARYPATH) -name '*.c') | |
# LC_FILES := $(wildcard $(LIBRARYPATH)/*/*.c) | |
LCPP_FILES := $(shell find $(LIBRARYPATH) -name '*.cpp') | |
#LCPP_FILES := $(wildcard $(LIBRARYPATH)/*/*.cpp) | |
#LC_FILES := $(shell find $(LIBRARYPATH) -name '*.c') | |
TC_FILES := $(wildcard $(COREPATH)/*.c) | |
#LC_FILES := $(shell find $(LIBRARYPATH) -name '*.c') | |
TCPP_FILES := $(wildcard $(COREPATH)/*.cpp) | |
C_FILES := $(wildcard src/*.c) | |
CPP_FILES := $(wildcard src/*.cpp) | |
INO_FILES := $(wildcard src/*.ino) | |
FREERTOS_FILES = $(wildcard $(FREERTOSPATH)/*.c) | |
FREERTOS_FILES += $(wildcard $(FREERTOSPATH)/$(FREERTOSPORT)/*.c) | |
# include paths for libraries | |
#L_INC := $(foreach lib,$(filter %/, $(wildcard $(LIBRARYPATH)/*/)), -I$(lib)) | |
L_INC := $(foreach lib,$(filter %, $(shell find $(LIBRARYPATH) -type d)), -I$(lib)) | |
SOURCES := $(C_FILES:.c=.o) $(CPP_FILES:.cpp=.o) $(INO_FILES:.ino=.o) $(TC_FILES:.c=.o) $(TCPP_FILES:.cpp=.o) $(LC_FILES:.c=.o) $(LCPP_FILES:.cpp=.o) $(FREERTOS_FILES:.c=.o) | |
OBJS := $(foreach src,$(SOURCES), $(BUILDDIR)/$(src)) | |
all: hex | |
build: $(TARGET).elf | |
hex: $(TARGET).hex | |
post_compile: $(TARGET).hex | |
@$(abspath $(TOOLSPATH))/teensy_post_compile -file="$(basename $<)" -path=$(CURDIR) -tools="$(abspath $(TOOLSPATH))" | |
reboot: | |
@-$(abspath $(TOOLSPATH))/teensy_reboot | |
upload: post_compile reboot | |
$(BUILDDIR)/%.o: %.c | |
@echo "[CC]\t$<" | |
@mkdir -p "$(dir $@)" | |
@$(CC) $(CPPFLAGS) $(CFLAGS) $(L_INC) -o "$@" -c "$<" | |
$(BUILDDIR)/%.o: %.cpp | |
@echo "[CXX]\t$<" | |
@mkdir -p "$(dir $@)" | |
@$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(L_INC) -o "$@" -c "$<" | |
$(BUILDDIR)/%.o: %.ino | |
@echo "[CXX]\t$<" | |
@mkdir -p "$(dir $@)" | |
@$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(L_INC) -o "$@" -x c++ -include Arduino.h -c "$<" | |
$(TARGET).elf: $(OBJS) $(LDSCRIPT) | |
@echo "[LD]\t$@" | |
@$(CC) $(LDFLAGS) -o "$@" $(OBJS) $(LIBS) | |
%.hex: %.elf | |
@echo "[HEX]\t$@" | |
@$(SIZE) "$<" | |
@$(OBJCOPY) -O ihex -R .eeprom "$<" "$@" | |
# compiler generated dependency info | |
-include $(OBJS:.o=.d) | |
clean: | |
@echo Cleaning... | |
@rm -rf "$(BUILDDIR)" | |
@rm -f "$(TARGET).elf" "$(TARGET).hex" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment