A TWI / I2C bootloader for AVR MCUs
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.

104 lines
2.7 KiB

  1. CC := avr-gcc
  2. LD := avr-ld
  3. OBJCOPY := avr-objcopy
  4. OBJDUMP := avr-objdump
  5. SIZE := avr-size
  6. TARGET = twiboot
  7. SOURCE = $(wildcard *.c)
  8. # select MCU
  9. MCU = attiny85
  10. AVRDUDE_PROG := -c avr910 -b 115200 -P /dev/ttyUSB0
  11. #AVRDUDE_PROG := -c dragon_isp -P usb
  12. # ---------------------------------------------------------------------------
  13. ifeq ($(MCU), atmega8)
  14. # atmega8:
  15. # Fuse L: 0x84 (8Mhz internal RC-Osz., 2.7V BOD)
  16. # Fuse H: 0xda (512 words bootloader)
  17. AVRDUDE_MCU=m8
  18. AVRDUDE_FUSES=lfuse:w:0x84:m hfuse:w:0xda:m
  19. BOOTLOADER_START=0x1C00
  20. endif
  21. ifeq ($(MCU), atmega88)
  22. # atmega88:
  23. # Fuse L: 0xc2 (8Mhz internal RC-Osz.)
  24. # Fuse H: 0xdd (2.7V BOD)
  25. # Fuse E: 0xfa (512 words bootloader)
  26. AVRDUDE_MCU=m88
  27. AVRDUDE_FUSES=lfuse:w:0xc2:m hfuse:w:0xdd:m efuse:w:0xfa:m
  28. BOOTLOADER_START=0x1C00
  29. endif
  30. ifeq ($(MCU), atmega168)
  31. # atmega168:
  32. # Fuse L: 0xc2 (8Mhz internal RC-Osz.)
  33. # Fuse H: 0xdd (2.7V BOD)
  34. # Fuse E: 0xfa (512 words bootloader)
  35. AVRDUDE_MCU=m168 -F
  36. AVRDUDE_FUSES=lfuse:w:0xc2:m hfuse:w:0xdd:m efuse:w:0xfa:m
  37. BOOTLOADER_START=0x3C00
  38. endif
  39. ifeq ($(MCU), atmega328p)
  40. # atmega328p:
  41. # Fuse L: 0xc2 (8Mhz internal RC-Osz.)
  42. # Fuse H: 0xdc (512 words bootloader)
  43. # Fuse E: 0xfd (2.7V BOD)
  44. AVRDUDE_MCU=m328p -F
  45. AVRDUDE_FUSES=lfuse:w:0xc2:m hfuse:w:0xdc:m efuse:w:0xfd:m
  46. BOOTLOADER_START=0x7C00
  47. endif
  48. ifeq ($(MCU), attiny85)
  49. # attiny85:
  50. # Fuse L: 0xe2 (8Mhz internal RC-Osz.)
  51. # Fuse H: 0xdd (2.7V BOD)
  52. # Fuse E: 0xfe (self programming enable)
  53. AVRDUDE_MCU=t85
  54. AVRDUDE_FUSES=lfuse:w:0xe2:m hfuse:w:0xdd:m efuse:w:0xfe:m
  55. BOOTLOADER_START=0x1C00
  56. CFLAGS_TARGET=-DUSE_CLOCKSTRETCH=1 -DVIRTUAL_BOOT_SECTION=1
  57. endif
  58. # ---------------------------------------------------------------------------
  59. CFLAGS = -pipe -g -Os -mmcu=$(MCU) -Wall -fdata-sections -ffunction-sections
  60. CFLAGS += -Wa,-adhlns=$(*F).lst -DBOOTLOADER_START=$(BOOTLOADER_START) $(CFLAGS_TARGET)
  61. LDFLAGS = -Wl,-Map,$(@:.elf=.map),--cref,--relax,--gc-sections,--section-start=.text=$(BOOTLOADER_START)
  62. LDFLAGS += -nostartfiles
  63. # ---------------------------------------------------------------------------
  64. $(TARGET): $(TARGET).elf
  65. @$(SIZE) -B -x --mcu=$(MCU) $<
  66. $(TARGET).elf: $(SOURCE:.c=.o)
  67. @echo " Linking file: $@"
  68. @$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^
  69. @$(OBJDUMP) -h -S $@ > $(@:.elf=.lss)
  70. @$(OBJCOPY) -j .text -j .data -O ihex $@ $(@:.elf=.hex)
  71. @$(OBJCOPY) -j .text -j .data -O binary $@ $(@:.elf=.bin)
  72. %.o: %.c $(MAKEFILE_LIST)
  73. @echo " Building file: $<"
  74. @$(CC) $(CFLAGS) -o $@ -c $<
  75. clean:
  76. rm -rf $(SOURCE:.c=.o) $(SOURCE:.c=.lst) $(addprefix $(TARGET), .elf .map .lss .hex .bin)
  77. install: $(TARGET).elf
  78. avrdude $(AVRDUDE_PROG) -p $(AVRDUDE_MCU) -U flash:w:$(<:.elf=.hex)
  79. fuses:
  80. avrdude $(AVRDUDE_PROG) -p $(AVRDUDE_MCU) $(patsubst %,-U %, $(AVRDUDE_FUSES))