avr.mk 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. # Hey Emacs, this is a -*- makefile -*-
  2. ##############################################################################
  3. # Compiler settings
  4. #
  5. CC = avr-gcc
  6. OBJCOPY = avr-objcopy
  7. OBJDUMP = avr-objdump
  8. SIZE = avr-size
  9. AR = avr-ar rcs
  10. NM = avr-nm
  11. HEX = $(OBJCOPY) -O $(FORMAT) -R .eeprom -R .fuse -R .lock -R .signature
  12. EEP = $(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 --no-change-warnings -O $(FORMAT)
  13. BIN =
  14. COMPILEFLAGS += -funsigned-char
  15. COMPILEFLAGS += -funsigned-bitfields
  16. COMPILEFLAGS += -ffunction-sections
  17. COMPILEFLAGS += -fdata-sections
  18. COMPILEFLAGS += -fpack-struct
  19. COMPILEFLAGS += -fshort-enums
  20. CFLAGS += $(COMPILEFLAGS)
  21. CFLAGS += -fno-inline-small-functions
  22. CFLAGS += -fno-strict-aliasing
  23. CPPFLAGS += $(COMPILEFLAGS)
  24. CPPFLAGS += -fno-exceptions
  25. LDFLAGS +=-Wl,--gc-sections
  26. OPT_DEFS += -DF_CPU=$(F_CPU)UL
  27. MCUFLAGS = -mmcu=$(MCU)
  28. # List any extra directories to look for libraries here.
  29. # Each directory must be seperated by a space.
  30. # Use forward slashes for directory separators.
  31. # For a directory that has spaces, enclose it in quotes.
  32. EXTRALIBDIRS =
  33. #---------------- External Memory Options ----------------
  34. # 64 KB of external RAM, starting after internal RAM (ATmega128!),
  35. # used for variables (.data/.bss) and heap (malloc()).
  36. #EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff
  37. # 64 KB of external RAM, starting after internal RAM (ATmega128!),
  38. # only used for heap (malloc()).
  39. #EXTMEMOPTS = -Wl,--section-start,.data=0x801100,--defsym=__heap_end=0x80ffff
  40. EXTMEMOPTS =
  41. #---------------- Debugging Options ----------------
  42. # Debugging format.
  43. # Native formats for AVR-GCC's -g are dwarf-2 [default] or stabs.
  44. # AVR Studio 4.10 requires dwarf-2.
  45. # AVR [Extended] COFF format requires stabs, plus an avr-objcopy run.
  46. DEBUG = dwarf-2
  47. # For simulavr only - target MCU frequency.
  48. DEBUG_MFREQ = $(F_CPU)
  49. # Set the DEBUG_UI to either gdb or insight.
  50. # DEBUG_UI = gdb
  51. DEBUG_UI = insight
  52. # Set the debugging back-end to either avarice, simulavr.
  53. DEBUG_BACKEND = avarice
  54. #DEBUG_BACKEND = simulavr
  55. # GDB Init Filename.
  56. GDBINIT_FILE = __avr_gdbinit
  57. # When using avarice settings for the JTAG
  58. JTAG_DEV = /dev/com1
  59. # Debugging port used to communicate between GDB / avarice / simulavr.
  60. DEBUG_PORT = 4242
  61. # Debugging host used to communicate between GDB / avarice / simulavr, normally
  62. # just set to localhost unless doing some sort of crazy debugging when
  63. # avarice is running on a different computer.
  64. DEBUG_HOST = localhost
  65. #============================================================================
  66. # Autodecct teensy loader
  67. ifneq (, $(shell which teensy-loader-cli 2>/dev/null))
  68. TEENSY_LOADER_CLI = teensy-loader-cli
  69. else
  70. TEENSY_LOADER_CLI = teensy_loader_cli
  71. endif
  72. # Program the device.
  73. program: $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).eep
  74. $(PROGRAM_CMD)
  75. teensy: $(BUILD_DIR)/$(TARGET).hex
  76. $(TEENSY_LOADER_CLI) -mmcu=$(MCU) -w -v $(BUILD_DIR)/$(TARGET).hex
  77. flip: $(BUILD_DIR)/$(TARGET).hex
  78. batchisp -hardware usb -device $(MCU) -operation erase f
  79. batchisp -hardware usb -device $(MCU) -operation loadbuffer $(BUILD_DIR)/$(TARGET).hex program
  80. batchisp -hardware usb -device $(MCU) -operation start reset 0
  81. dfu: $(BUILD_DIR)/$(TARGET).hex sizeafter
  82. ifneq (, $(findstring 0.7, $(shell dfu-programmer --version 2>&1)))
  83. dfu-programmer $(MCU) erase --force
  84. else
  85. dfu-programmer $(MCU) erase
  86. endif
  87. dfu-programmer $(MCU) flash $(BUILD_DIR)/$(TARGET).hex
  88. dfu-programmer $(MCU) reset
  89. dfu-start:
  90. dfu-programmer $(MCU) reset
  91. dfu-programmer $(MCU) start
  92. flip-ee: $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).eep
  93. $(COPY) $(BUILD_DIR)/$(TARGET).eep $(BUILD_DIR)/$(TARGET)eep.hex
  94. batchisp -hardware usb -device $(MCU) -operation memory EEPROM erase
  95. batchisp -hardware usb -device $(MCU) -operation memory EEPROM loadbuffer $(BUILD_DIR)/$(TARGET)eep.hex program
  96. batchisp -hardware usb -device $(MCU) -operation start reset 0
  97. $(REMOVE) $(BUILD_DIR)/$(TARGET)eep.hex
  98. dfu-ee: $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).eep
  99. ifneq (, $(findstring 0.7, $(shell dfu-programmer --version 2>&1)))
  100. dfu-programmer $(MCU) flash --eeprom $(BUILD_DIR)/$(TARGET).eep
  101. else
  102. dfu-programmer $(MCU) flash-eeprom $(BUILD_DIR)/$(TARGET).eep
  103. endif
  104. dfu-programmer $(MCU) reset
  105. # Generate avr-gdb config/init file which does the following:
  106. # define the reset signal, load the target file, connect to target, and set
  107. # a breakpoint at main().
  108. gdb-config:
  109. @$(REMOVE) $(GDBINIT_FILE)
  110. @echo define reset >> $(GDBINIT_FILE)
  111. @echo SIGNAL SIGHUP >> $(GDBINIT_FILE)
  112. @echo end >> $(GDBINIT_FILE)
  113. @echo file $(BUILD_DIR)/$(TARGET).elf >> $(GDBINIT_FILE)
  114. @echo target remote $(DEBUG_HOST):$(DEBUG_PORT) >> $(GDBINIT_FILE)
  115. ifeq ($(DEBUG_BACKEND),simulavr)
  116. @echo load >> $(GDBINIT_FILE)
  117. endif
  118. @echo break main >> $(GDBINIT_FILE)
  119. debug: gdb-config $(BUILD_DIR)/$(TARGET).elf
  120. ifeq ($(DEBUG_BACKEND), avarice)
  121. @echo Starting AVaRICE - Press enter when "waiting to connect" message displays.
  122. @$(WINSHELL) /c start avarice --jtag $(JTAG_DEV) --erase --program --file \
  123. $(BUILD_DIR)/$(TARGET).elf $(DEBUG_HOST):$(DEBUG_PORT)
  124. @$(WINSHELL) /c pause
  125. else
  126. @$(WINSHELL) /c start simulavr --gdbserver --device $(MCU) --clock-freq \
  127. $(DEBUG_MFREQ) --port $(DEBUG_PORT)
  128. endif
  129. @$(WINSHELL) /c start avr-$(DEBUG_UI) --command=$(GDBINIT_FILE)
  130. # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
  131. COFFCONVERT = $(OBJCOPY) --debugging
  132. COFFCONVERT += --change-section-address .data-0x800000
  133. COFFCONVERT += --change-section-address .bss-0x800000
  134. COFFCONVERT += --change-section-address .noinit-0x800000
  135. COFFCONVERT += --change-section-address .eeprom-0x810000
  136. coff: $(BUILD_DIR)/$(TARGET).elf
  137. @$(SECHO) $(MSG_COFF) $(BUILD_DIR)/$(TARGET).cof
  138. $(COFFCONVERT) -O coff-avr $< $(BUILD_DIR)/$(TARGET).cof
  139. extcoff: $(BUILD_DIR)/$(TARGET).elf
  140. @$(SECHO) $(MSG_EXTENDED_COFF) $(BUILD_DIR)/$(TARGET).cof
  141. $(COFFCONVERT) -O coff-ext-avr $< $(BUILD_DIR)/$(TARGET).cof