2013-02-21 00:43:25 -04:00
|
|
|
TOOLCHAIN = AVR
|
|
|
|
|
|
|
|
include $(MK_DIR)/find_arduino.mk
|
|
|
|
include $(MK_DIR)/find_tools.mk
|
|
|
|
|
|
|
|
#
|
|
|
|
# Tool options
|
|
|
|
#
|
|
|
|
DEFINES = -DF_CPU=$(F_CPU)
|
2014-03-25 22:15:31 -03:00
|
|
|
DEFINES += -DSKETCH=\"$(SKETCH)\" -DAPM_BUILD_DIRECTORY=APM_BUILD_$(SKETCH)
|
2015-05-20 21:11:20 -03:00
|
|
|
DEFINES += $(EXTRAFLAGS)
|
2013-02-21 00:43:25 -04:00
|
|
|
DEFINES += -DCONFIG_HAL_BOARD=$(HAL_BOARD)
|
|
|
|
WARNFLAGS = -Wformat -Wall -Wshadow -Wpointer-arith -Wcast-align
|
2014-05-08 02:15:43 -03:00
|
|
|
WARNFLAGS += -Wwrite-strings -Wformat=2 -Wno-unused-parameter -Wno-missing-field-initializers
|
2013-02-21 00:43:25 -04:00
|
|
|
WARNFLAGSCXX = -Wno-reorder
|
|
|
|
DEPFLAGS = -MD -MT $@
|
|
|
|
|
2015-05-17 18:19:28 -03:00
|
|
|
CXXOPTS = -ffunction-sections -fdata-sections -fno-exceptions -fsigned-char -fno-use-cxa-atexit
|
2013-02-21 00:43:25 -04:00
|
|
|
COPTS = -ffunction-sections -fdata-sections -fsigned-char
|
|
|
|
|
|
|
|
ASOPTS = -x assembler-with-cpp
|
|
|
|
LISTOPTS = -adhlns=$(@:.o=.lst)
|
|
|
|
|
|
|
|
NATIVE_CPUFLAGS = -D_GNU_SOURCE
|
|
|
|
NATIVE_CPULDFLAGS = -g
|
|
|
|
NATIVE_OPTFLAGS = -O0 -g
|
|
|
|
|
|
|
|
AVR_CPUFLAGS = -mmcu=$(MCU) -mcall-prologues
|
|
|
|
AVR_CPULDFLAGS = -Wl,-m,avr6
|
|
|
|
AVR_OPTFLAGS = -Os
|
|
|
|
|
|
|
|
CPUFLAGS= $($(TOOLCHAIN)_CPUFLAGS)
|
|
|
|
CPULDFLAGS= $($(TOOLCHAIN)_CPULDFLAGS)
|
|
|
|
OPTFLAGS= $($(TOOLCHAIN)_OPTFLAGS)
|
|
|
|
|
|
|
|
CXXFLAGS = -g $(CPUFLAGS) $(DEFINES) -Wa,$(LISTOPTS) $(OPTFLAGS)
|
2015-05-17 18:26:48 -03:00
|
|
|
CXXFLAGS += -std=gnu++11 $(WARNFLAGS) $(WARNFLAGSCXX) $(DEPFLAGS) $(CXXOPTS)
|
2013-02-21 00:43:25 -04:00
|
|
|
CFLAGS = -g $(CPUFLAGS) $(DEFINES) -Wa,$(LISTOPTS) $(OPTFLAGS)
|
|
|
|
CFLAGS += $(WARNFLAGS) $(DEPFLAGS) $(COPTS)
|
|
|
|
ASFLAGS = -g $(CPUFLAGS) $(DEFINES) -Wa,$(LISTOPTS) $(DEPFLAGS)
|
|
|
|
ASFLAGS += $(ASOPTS)
|
|
|
|
LDFLAGS = -g $(CPUFLAGS) $(OPTFLAGS) $(WARNFLAGS)
|
|
|
|
LDFLAGS += -Wl,--gc-sections -Wl,-Map -Wl,$(SKETCHMAP)
|
|
|
|
|
|
|
|
ifneq ($(BOARD),mega)
|
|
|
|
LDFLAGS += $(CPULDFLAGS)
|
|
|
|
endif
|
|
|
|
|
|
|
|
# under certain situations with certain avr-gcc versions the --relax flag causes
|
|
|
|
# a bug. Give the user a way to disable this flag per-sketch.
|
|
|
|
# I know this is a rotten hack but we're really close to sunset on AVR.
|
|
|
|
EXCLUDE_RELAX := $(wildcard $(SRCROOT)/norelax.inoflag)
|
|
|
|
ifeq ($(EXCLUDE_RELAX),)
|
|
|
|
LDFLAGS += -Wl,--relax
|
|
|
|
endif
|
|
|
|
|
|
|
|
LIBS = -lm
|
|
|
|
|
|
|
|
ifeq ($(VERBOSE),)
|
|
|
|
v = @
|
|
|
|
else
|
|
|
|
v =
|
|
|
|
endif
|
|
|
|
|
|
|
|
# Library object files
|
|
|
|
LIBOBJS := $(SKETCHLIBOBJS)
|
|
|
|
|
2015-05-20 21:11:20 -03:00
|
|
|
HARDWARE ?= arduino
|
|
|
|
BOARD ?= mega2560
|
|
|
|
|
2013-02-21 00:43:25 -04:00
|
|
|
# Find the hardware directory to use
|
|
|
|
HARDWARE_DIR := $(firstword $(wildcard $(SKETCHBOOK)/hardware/$(HARDWARE) \
|
2015-07-31 23:24:23 -03:00
|
|
|
$(ARDUINO)/hardware/$(HARDWARE)/avr \
|
|
|
|
$(ARDUINO)/hardware/$(HARDWARE) \
|
|
|
|
)\
|
|
|
|
)
|
2013-02-21 00:43:25 -04:00
|
|
|
ifeq ($(HARDWARE_DIR),)
|
|
|
|
$(error ERROR: hardware directory for $(HARDWARE) not found)
|
|
|
|
endif
|
|
|
|
|
|
|
|
# Find the boards.txt that we are using
|
|
|
|
BOARDFILE := $(wildcard $(HARDWARE_DIR)/boards.txt)
|
|
|
|
ifeq ($(BOARDFILE),)
|
|
|
|
$(error ERROR: could not locate boards.txt for hardware $(HARDWARE))
|
|
|
|
endif
|
|
|
|
|
|
|
|
# Extract needed build parameters from the boardfile
|
|
|
|
MCU := $(shell grep $(BOARD).build.mcu $(BOARDFILE) | cut -d = -f 2)
|
|
|
|
F_CPU := $(shell grep $(BOARD).build.f_cpu $(BOARDFILE) | cut -d = -f 2)
|
|
|
|
HARDWARE_CORE := $(shell grep $(BOARD).build.core $(BOARDFILE) | cut -d = -f 2)
|
|
|
|
UPLOAD_SPEED := $(shell grep $(BOARD).upload.speed $(BOARDFILE) | cut -d = -f 2)
|
|
|
|
|
|
|
|
# User can define USERAVRDUDEFLAGS = -V in their config.mk to skip verification
|
2013-03-08 02:53:09 -04:00
|
|
|
USERAVRDUDEFLAGS ?=
|
2013-03-05 08:32:55 -04:00
|
|
|
#make sure the avrdude conf file is referenced correctly in cygwin
|
|
|
|
ifneq ($(findstring CYGWIN, $(SYSTYPE)),)
|
|
|
|
USERAVRDUDEFLAGS := -C $(ARDUINO)/hardware/tools/avr/etc/avrdude.conf
|
2013-03-08 02:53:09 -04:00
|
|
|
endif
|
|
|
|
#make sure the avrdude conf file is referenced correctly in mingw
|
|
|
|
ifneq ($(findstring MINGW, $(SYSTYPE)),)
|
|
|
|
USERAVRDUDEFLAGS := -C $(ARDUINO)/hardware/tools/avr/etc/avrdude.conf
|
2013-03-05 08:32:55 -04:00
|
|
|
endif
|
2013-06-13 17:24:34 -03:00
|
|
|
#make sure the avrdude conf file is referenced correctly in darwin
|
|
|
|
ifneq ($(findstring Darwin, $(SYSTYPE)),)
|
|
|
|
USERAVRDUDEFLAGS := -C $(ARDUINO)/hardware/tools/avr/etc/avrdude.conf
|
|
|
|
endif
|
2013-02-21 00:43:25 -04:00
|
|
|
|
|
|
|
ifeq ($(UPLOAD_PROTOCOL),)
|
|
|
|
UPLOAD_PROTOCOL := $(shell grep $(BOARD).upload.protocol $(BOARDFILE) | cut -d = -f 2)
|
|
|
|
endif
|
|
|
|
|
|
|
|
# Adding override for mega since boards.txt uses stk500 instead of
|
|
|
|
# arduino on 22 release
|
|
|
|
ifeq ($(BOARD),mega)
|
|
|
|
UPLOAD_PROTOCOL := arduino
|
|
|
|
endif
|
|
|
|
|
2013-03-05 08:32:55 -04:00
|
|
|
#On Cygwin, the wiring programmer will perform the DTR reset for us
|
|
|
|
ifneq ($(findstring CYGWIN, $(SYSTYPE)),)
|
|
|
|
UPLOAD_PROTOCOL := wiring
|
|
|
|
endif
|
|
|
|
|
2013-02-21 00:43:25 -04:00
|
|
|
ifeq ($(MCU),)
|
|
|
|
$(error ERROR: Could not locate board $(BOARD) in $(BOARDFILE))
|
|
|
|
endif
|
|
|
|
|
|
|
|
################################################################################
|
|
|
|
# Built products
|
|
|
|
#
|
|
|
|
|
|
|
|
# The ELF file
|
|
|
|
SKETCHELF = $(BUILDROOT)/$(SKETCH).elf
|
2014-11-13 02:27:53 -04:00
|
|
|
BUILDELF = $(notdir $(SKETCHELF))
|
2013-02-21 00:43:25 -04:00
|
|
|
|
|
|
|
# HEX file
|
|
|
|
SKETCHHEX = $(BUILDROOT)/$(SKETCH).hex
|
|
|
|
|
|
|
|
# EEP file
|
|
|
|
SKETCHEEP = $(BUILDROOT)/$(SKETCH).eep
|
|
|
|
|
|
|
|
# Map file
|
|
|
|
SKETCHMAP = $(BUILDROOT)/$(SKETCH).map
|
|
|
|
|
|
|
|
# All of the objects that may be built
|
|
|
|
ALLOBJS = $(SKETCHOBJS) $(LIBOBJS)
|
|
|
|
|
|
|
|
# All of the dependency files that may be generated
|
|
|
|
ALLDEPS = $(ALLOBJS:%.o=%.d)
|
|
|
|
|
|
|
|
################################################################################
|
|
|
|
# Targets
|
|
|
|
#
|
|
|
|
|
|
|
|
all: $(SKETCHELF) $(SKETCHEEP) $(SKETCHHEX)
|
|
|
|
|
|
|
|
print-%:
|
|
|
|
echo "$*=$($*)"
|
|
|
|
|
|
|
|
.PHONY: upload
|
|
|
|
upload: $(SKETCHHEX)
|
|
|
|
$(AVRDUDE) -c $(UPLOAD_PROTOCOL) -p $(MCU) -P $(PORT) -b$(UPLOAD_SPEED) $(USERAVRDUDEFLAGS) -U flash:w:$(SKETCHHEX):i
|
|
|
|
|
|
|
|
debug:
|
|
|
|
$(AVARICE) --mkII --capture --jtag usb :4242 & \
|
|
|
|
gnome-terminal -x $(GDB) $(SKETCHELF) & \
|
|
|
|
echo -e '\n\nat the gdb prompt type "target remote localhost:4242"'
|
|
|
|
|
|
|
|
# this allows you to flash your image via JTAG for when you
|
|
|
|
# have completely broken your USB
|
|
|
|
jtag-program:
|
|
|
|
$(AVARICE) --mkII --jtag usb --erase --program --file $(SKETCHELF)
|
|
|
|
|
|
|
|
################################################################################
|
|
|
|
# Rules
|
|
|
|
#
|
|
|
|
|
|
|
|
# fetch dependency info from a previous build if any of it exists
|
|
|
|
-include $(ALLDEPS)
|
|
|
|
|
|
|
|
# Link the final object
|
|
|
|
$(SKETCHELF): $(SKETCHOBJS) $(LIBOBJS)
|
|
|
|
$(RULEHDR)
|
|
|
|
$(v)$(LD) $(LDFLAGS) -o $@ $^ $(LIBS)
|
2014-11-13 02:27:53 -04:00
|
|
|
$(v)cp $(SKETCHELF) $(BUILDELF)
|
|
|
|
@echo "Firmware is in $(BUILDELF)"
|
2013-02-21 00:43:25 -04:00
|
|
|
|
|
|
|
# Create the hex file
|
|
|
|
$(SKETCHHEX): $(SKETCHELF)
|
|
|
|
$(RULEHDR)
|
|
|
|
$(v)$(OBJCOPY) -O ihex -R .eeprom $< $@
|
|
|
|
|
|
|
|
# Create the eep file
|
|
|
|
$(SKETCHEEP): $(SKETCHELF)
|
|
|
|
$(RULEHDR)
|
|
|
|
$(v)$(OBJCOPY) -O ihex -j.eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0 $< $@
|
|
|
|
|
2015-06-01 00:02:18 -03:00
|
|
|
SKETCH_INCLUDES = $(SKETCHLIBINCLUDES)
|
|
|
|
SLIB_INCLUDES = -I$(dir $<)/utility $(SKETCHLIBINCLUDES)
|
|
|
|
|
2015-05-31 21:09:43 -03:00
|
|
|
include $(MK_DIR)/build_rules.mk
|