commit 1a77421caf094c84ae37c867508589bf5771188f Author: Ain <41307858+nero@users.noreply.github.com> Date: Sun Jan 28 19:40:35 2018 +0000 Basic import diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a715db0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +*.o +*.elf +*.lst +*.hex +*.bin +*.asm diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..67e23ac --- /dev/null +++ b/Makefile @@ -0,0 +1,54 @@ +OPTIMIZE = -O2 +CPPFLAGS += -DF_CPU=$(MCU_FREQ) +override CFLAGS = -g --std=c99 -Wall $(OPTIMIZE) -mmcu=$(MCU_TARGET) +override LDFLAGS = +CC = avr-gcc +OBJCOPY = avr-objcopy +OBJDUMP = avr-objdump +AVRDUDE_ARGS = + +ifdef BOARD +include boards/$(BOARD).mk +endif + +default: $(PROG).hex + +clean: + rm -rf *.o drivers/*.o *.elf *.lst *.hex *.bin *.asm + +# dependencies +blink.elf: drivers/led.o + +# generic rules +%.o: %.c + $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $^ + +%.elf: %.o + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ + +%.lst: %.elf + $(OBJDUMP) -h -S $< > $@ + +%.hex: %.elf + $(OBJCOPY) -j .text -j .data -O ihex $< $@ + +%.bin: %.elf + $(OBJCOPY) -j .text -j .data -O binary $< $@ + +%.asm: %.elf + $(OBJDUMP) -z -j .text -m avr5 -d $< > $@ + +# flashing definitions and helper target +AVRDUDE_ARGS += -p$(MCU_TARGET) +AVRDUDE_ARGS += -c$(AVRDUDE_TYPE) +ifdef AVRDUDE_TTY +AVRDUDE_ARGS += -P$(AVRDUDE_TTY) +endif +ifdef AVRDUDE_BAUD +AVRDUDE_ARGS += -b$(AVRDUDE_BAUD) +endif + +ifdef AVRDUDE_TYPE +flash: $(PROG).hex + avrdude $(AVRDUDE_ARGS) -U flash:w:$(PROG).hex +endif diff --git a/boards/nano.mk b/boards/nano.mk new file mode 100644 index 0000000..d3d0873 --- /dev/null +++ b/boards/nano.mk @@ -0,0 +1,7 @@ +MCU_TARGET = atmega328p +MCU_FREQ = 16000000UL +CPPFLAGS += -DLED_PORT=PORTB -DLED_PIN=5 + +AVRDUDE_TYPE = arduino +AVRDUDE_TTY = /dev/ttyUSB0 +AVRDUDE_BAUD = 57600