aboutsummaryrefslogtreecommitdiff
path: root/Makefile
diff options
context:
space:
mode:
authorDavid Phillips <david@yeah.nah.nz>2020-12-13 16:35:58 +1300
committerDavid Phillips <david@yeah.nah.nz>2020-12-13 20:42:33 +1300
commit7e26f31e221665ee059b02fc6beda025d39d6e75 (patch)
tree1a5f66e12680778b001f3cb1d2c49b0f2ce0f04c /Makefile
downloadaltimeter-7e26f31e221665ee059b02fc6beda025d39d6e75.tar.xz
Initial prototype
This patch adds a skeleton of AVR code for a "simulator" target (atmega2560) and for the real intended hardware target (atmega32u4). The simulator target is one that is supported by the QEMU AVR emulator, while the 32u4 is currently not.
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile54
1 files changed, 54 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..879452f
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,54 @@
+CC ?= avr-gcc
+OBJCOPY ?= avr-objcopy
+AVRDUDE ?= avrdude
+QEMU_AVR ?= qemu-system-avr
+
+MCU ?= atmega32u4
+SIM_MCU ?= atmega2560
+CFLAGS += -DF_CPU=16000000UL -mmcu=$(MCU) -O3
+SIM_CFLAGS += -DF_CPU=16000000UL -mmcu=$(SIM_MCU) -g3 -gdwarf-2
+
+$(shell mkdir -p build/{real,sim})
+
+all: build/altimeter_sim.elf build/altimeter.hex
+
+emu: build/altimeter_sim.elf
+ $(QEMU_AVR) -s -S -nographic -machine mega2560 -bios $<
+
+flash: build/altimeter.hex
+ $(AVRDUDE) -F -V -c avr109 -p $(MCU) -P $(PORT) -b 115200 -U flash:w:$<
+
+clean:
+ rm -rf build/
+
+build/altimeter.elf: \
+ build/real/barometer_sim.o \
+ build/real/display_sim.o \
+ build/real/altimeter.o \
+ build/real/util.o
+ $(CC) -o $@ $^ $(CFLAGS)
+
+build/altimeter_sim.elf: \
+ build/sim/barometer_sim.o \
+ build/sim/display_sim.o \
+ build/sim/altimeter.o \
+ build/sim/util.o
+ $(CC) -o $@ $^ $(SIM_CFLAGS)
+
+include config.mk
+
+
+build/sim/%.o: %.c
+ $(CC) -c -o $@ $^ $(SIM_CFLAGS)
+
+build/real/%.o: %.c
+ $(CC) -c -o $@ $^ $(CFLAGS)
+
+build/%.hex: build/%.elf
+ $(OBJCOPY) -O ihex -R .eeprom $< $@
+
+build/%.elf:
+ $(CC) -o $@ $^ $(CFLAGS)
+
+
+.PHONY: all emu flash clean