aboutsummaryrefslogtreecommitdiff
path: root/dev/arduino-terminal/Makefile
diff options
context:
space:
mode:
Diffstat (limited to 'dev/arduino-terminal/Makefile')
-rw-r--r--dev/arduino-terminal/Makefile112
1 files changed, 112 insertions, 0 deletions
diff --git a/dev/arduino-terminal/Makefile b/dev/arduino-terminal/Makefile
new file mode 100644
index 0000000..d60dafb
--- /dev/null
+++ b/dev/arduino-terminal/Makefile
@@ -0,0 +1,112 @@
+##
+## Makefile to create firmware image including arduino sources
+##
+##
+
+
+# Arduino variant
+#
+VARIANT=mega
+
+
+# CPU model
+#
+MCU=atmega2560
+
+
+# CPU Frequency
+#
+F_CPU=16000000L
+
+
+# Serial port used for uploading and monitoring
+#
+SERIAL=/dev/ttyACM0
+BAUD=115200
+
+
+# Name of image to produce (can be arbitrary)
+#
+TARGET=firmware
+
+
+# Toolchain and flags
+#
+CC=avr-gcc
+CFLAGS=-Os -Wall -ffunction-sections -fdata-sections -mmcu=$(MCU) -DF_CPU=$(F_CPU) -MMD -DUSB_VID=0x2341 -DUSB_PID=0x8037 -DARDUINO=106
+
+CXX=avr-g++
+CXXFLAGS=$(CFLAGS)
+
+LD=avr-gcc
+LDFLAGS= -Os -Wl,--gc-sections -mmcu=$(MCU)
+
+AR=avr-ar
+
+AS=avr-as
+ASFLAGS=-mmcu=$(MCU)
+
+OC=avr-objcopy
+OCFLAGS=
+
+OD=avr-objdump
+AVRDUDE=avrdude
+AVRDUDEFLAGS= -DV -p $(MCU) -P $(SERIAL) -c stk500v2 -b 115200
+
+AVRSIZE=avr-size
+
+# Derived variables
+SOURCEDIRS=\
+ src \
+ ext/arduino/core \
+ $(wildcard ext/arduino/lib/*)
+
+INCLUDES=\
+ include \
+ ext/arduino/core \
+ ext/arduino/variants/$(VARIANT) \
+ $(wildcard ext/arduino/lib/*)
+
+SOURCES=\
+ $(foreach dir,$(SOURCEDIRS),$(wildcard $(dir)/*.c)) \
+ $(foreach dir,$(SOURCEDIRS),$(wildcard $(dir)/*.cpp))
+
+OBJECTS=$(addsuffix .o, $(basename $(SOURCES)))
+
+# Rules
+all: $(TARGET).hex
+
+$(TARGET).hex: $(TARGET).elf
+ $(OC) $(OCFLAGS) -O ihex -R .eeprom $< $@
+
+$(TARGET).elf: $(OBJECTS)
+ $(LD) $(LDFLAGS) -o $@ $^
+
+# Sources
+%.o: %.c
+ $(CC) $(CFLAGS) -I$(dir $<) $(addprefix -I, $(INCLUDES)) -o $@ -c $<
+
+%.o: %.cpp
+ $(CXX) $(CXXFLAGS) -I$(dir $<) $(addprefix -I, $(INCLUDES)) -o $@ -c $<
+
+# Utility rules
+size: $(TARGET).hex
+ $(AVRSIZE) --format=avr --mcu=$(MCU) $(TARGET).elf
+
+upload: $(TARGET).hex
+ $(AVRDUDE) $(AVRDUDEFLAGS) -U flash:w:$(TARGET).hex:i
+
+monitor:
+ cu -l $(SERIAL) -s $(BAUD) --parity=none -h
+
+clean:
+ @rm -f *.o
+ @for dir in $(SOURCEDIRS); do \
+ rm -f $$dir/*.o; \
+ rm -f $$dir/*.d; \
+ done
+ @rm -f $(TARGET).hex
+ @rm -f $(TARGET).elf
+ @rm -f $(GDBINITFILE)
+
+.PHONY: clean