Makefile 941 B

12345678910111213141516171819202122232425262728293031323334
  1. MCU = atmega8u2
  2. F_CPU = 16000000UL
  3. TARGET = usbi2c
  4. SRC = main.c usb.c i2c.c tiny.c
  5. # Set to 1 to attach to USB only while PB6 (external VBUS divider/sense) is high
  6. VBUS ?= 0
  7. CFLAGS = -mmcu=$(MCU) -DF_CPU=$(F_CPU) -DUSE_VBUS_DETECT=$(VBUS) -Os -std=gnu11 \
  8. -Wall -Wextra -ffunction-sections -fdata-sections -fshort-enums
  9. LDFLAGS = -mmcu=$(MCU) -Wl,--gc-sections
  10. all: $(TARGET).hex size
  11. $(TARGET).elf: $(SRC) usb.h i2c.h tiny.h
  12. avr-gcc $(CFLAGS) $(SRC) -o $@ $(LDFLAGS)
  13. $(TARGET).hex: $(TARGET).elf
  14. avr-objcopy -O ihex -R .eeprom $< $@
  15. size: $(TARGET).elf
  16. avr-size $<
  17. # Flash through USBasp
  18. flash: $(TARGET).hex
  19. avrdude -c usbasp -p m8u2 -U flash:w:$(TARGET).hex:i
  20. # Crystal oscillator, CKDIV8 off (same values as Arduino Uno R3 8U2). Needed once.
  21. fuses:
  22. avrdude -c usbasp -p m8u2 -U lfuse:w:0xFF:m -U hfuse:w:0xD9:m -U efuse:w:0xF4:m
  23. clean:
  24. rm -f *.elf *.hex
  25. .PHONY: all size flash fuses clean