AVR ISP adapter (avr109/910 compatible, using ATmega16)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
1.8 KiB

  1. CC := avr-gcc
  2. LD := avr-ld
  3. OBJCOPY := avr-objcopy
  4. OBJDUMP := avr-objdump
  5. SIZE := avr-size
  6. TARGET = ispprog
  7. SOURCE = $(wildcard *.c)
  8. BUILD_DIR = build
  9. #CONFIG = ispprog
  10. CONFIG = ispprog2
  11. AVRDUDE_PROG := -c butterfly -b 19200 -P /dev/ttyUSB0
  12. #AVRDUDE_PROG := -c dragon_isp -P usb
  13. # ---------------------------------------------------------------------------
  14. ifeq ($(CONFIG), ispprog)
  15. # (7.3728MHz ext. crystal)
  16. AVRDUDE_MCU=m16
  17. AVRDUDE_FUSES=lfuse:w:0xff:m hfuse:w:0xda:m
  18. MCU=atmega16
  19. endif
  20. ifeq ($(CONFIG), ispprog2)
  21. # (8MHz int. osc, 2.7V BOD)
  22. AVRDUDE_MCU=m328p -F
  23. AVRDUDE_FUSES=lfuse:w:0xe2:m hfuse:w:0xdc:m efuse:w:0x02:m
  24. MCU = atmega328p
  25. endif
  26. # ---------------------------------------------------------------------------
  27. CFLAGS = -pipe -g -Os -mmcu=$(MCU) -Wall -fdata-sections -ffunction-sections
  28. CFLAGS += -Wa,-adhlns=$(BUILD_DIR)/$(*D)/$(*F).lst -MMD -MP -MF $(BUILD_DIR)/$(*D)/$(*F).d
  29. CFLAGS += -DCONFIG_$(CONFIG)=1
  30. LDFLAGS = -Wl,-Map,$(@:.elf=.map),--cref,--relax,--gc-sections
  31. # ---------------------------------------------------------------------------
  32. $(TARGET): $(BUILD_DIR)/$(TARGET).elf
  33. @$(SIZE) -B -x --mcu=$(MCU) $<
  34. $(BUILD_DIR)/$(TARGET).elf: $(patsubst %,$(BUILD_DIR)/%,$(SOURCE:.c=.o))
  35. @echo " Linking file: $@"
  36. @$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^
  37. @$(OBJDUMP) -h -S $@ > $(@:.elf=.lss)
  38. @$(OBJCOPY) -j .text -j .data -O ihex $@ $(@:.elf=.hex)
  39. @$(OBJCOPY) -j .text -j .data -O binary $@ $(@:.elf=.bin)
  40. $(BUILD_DIR)/%.o: %.c $(MAKEFILE_LIST)
  41. @echo " Building file: $<"
  42. @$(shell test -d $(BUILD_DIR)/$(*D) || mkdir -p $(BUILD_DIR)/$(*D))
  43. @$(CC) $(CFLAGS) -o $@ -c $<
  44. include $(shell find $(BUILD_DIR) -name \*.d 2> /dev/null)
  45. clean:
  46. rm -rf $(BUILD_DIR)
  47. install: $(BUILD_DIR)/$(TARGET).elf
  48. avrdude $(AVRDUDE_PROG) -p $(AVRDUDE_MCU) -U flash:w:$(<:.elf=.hex)
  49. fuses:
  50. avrdude $(AVRDUDE_PROG) -p $(AVRDUDE_MCU) $(patsubst %,-U %, $(AVRDUDE_FUSES))