From 7e26f31e221665ee059b02fc6beda025d39d6e75 Mon Sep 17 00:00:00 2001 From: David Phillips Date: Sun, 13 Dec 2020 16:35:58 +1300 Subject: 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. --- Makefile | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 Makefile (limited to 'Makefile') 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 -- cgit v1.1