avr.mk 5.9 KB

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