Advertisement
Guest User

AVR Dragon JTAG Makefile

a guest
Feb 23rd, 2013
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Make 5.68 KB | None | 0 0
  1. # Hey Emacs, this is a -*- makefile -*-
  2.  
  3. # AVR-GCC Makefile template, derived from the WinAVR template (which
  4. # is public domain), believed to be neutral to any flavor of "make"
  5. # (GNU make, BSD make, SysV make)
  6.  
  7.  
  8. MCU = atmega164a
  9. FORMAT = ihex
  10. TARGET = main
  11. SRC = $(TARGET).c
  12. ASRC =
  13. OPT = 1
  14.  
  15. # Name of this Makefile (used for "make depend").
  16. MAKEFILE = Makefile
  17.  
  18. # Debugging format.
  19. # Native formats for AVR-GCC's -g are stabs [default], or dwarf-2.
  20. # AVR (extended) COFF requires stabs, plus an avr-objcopy run.
  21. DEBUG = stabs
  22.  
  23. # Compiler flag to set the C Standard level.
  24. # c89   - "ANSI" C
  25. # gnu89 - c89 plus GCC extensions
  26. # c99   - ISO C99 standard (not yet fully implemented)
  27. # gnu99 - c99 plus GCC extensions
  28. CSTANDARD = -std=gnu99
  29.  
  30. # Place -D or -U options here
  31. CDEFS =
  32.  
  33. # Place -I options here
  34. CINCS =
  35.  
  36.  
  37. CDEBUG = -g$(DEBUG)
  38. CWARN = -Wall -Wstrict-prototypes
  39. CTUNING = -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
  40. #CEXTRA = -Wa,-adhlns=$(<:.c=.lst)
  41. CFLAGS = $(CDEBUG) $(CDEFS) $(CINCS) -O$(OPT) $(CWARN) $(CSTANDARD) $(CEXTRA)
  42.  
  43.  
  44. #ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
  45.  
  46.  
  47. #Additional libraries.
  48.  
  49. # Minimalistic printf version
  50. PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
  51.  
  52. # Floating point printf version (requires MATH_LIB = -lm below)
  53. PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
  54.  
  55. PRINTF_LIB =
  56.  
  57. # Minimalistic scanf version
  58. SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
  59.  
  60. # Floating point + %[ scanf version (requires MATH_LIB = -lm below)
  61. SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
  62.  
  63. SCANF_LIB =
  64.  
  65. MATH_LIB = -lm
  66.  
  67. # External memory options
  68.  
  69. # 64 KB of external RAM, starting after internal RAM (ATmega128!),
  70. # used for variables (.data/.bss) and heap (malloc()).
  71. #EXTMEMOPTS = -Wl,--section-start,.data=0x801100,--defsym=__heap_end=0x80ffff
  72.  
  73. # 64 KB of external RAM, starting after internal RAM (ATmega128!),
  74. # only used for heap (malloc()).
  75. #EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff
  76.  
  77. EXTMEMOPTS =
  78.  
  79. #LDMAP = $(LDFLAGS) -Wl,-Map=$(TARGET).map,--cref
  80. LDFLAGS = $(EXTMEMOPTS) $(LDMAP) $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
  81.  
  82.  
  83. # Programming support using avrdude. Settings and variables.
  84.  
  85. AVRDUDE_PROGRAMMER = dragon_jtag
  86. AVRDUDE_PORT = usb
  87.  
  88. AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
  89. #AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
  90.  
  91.  
  92. # Uncomment the following if you want avrdude's erase cycle counter.
  93. # Note that this counter needs to be initialized first using -Yn,
  94. # see avrdude manual.
  95. #AVRDUDE_ERASE_COUNTER = -y
  96.  
  97. # Uncomment the following if you do /not/ wish a verification to be
  98. # performed after programming the device.
  99. #AVRDUDE_NO_VERIFY = -V
  100.  
  101. # Increase verbosity level.  Please use this when submitting bug
  102. # reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
  103. # to submit bug reports.
  104. #AVRDUDE_VERBOSE = -v -v
  105.  
  106. AVRDUDE_BASIC = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
  107. AVRDUDE_FLAGS = $(AVRDUDE_BASIC) $(AVRDUDE_NO_VERIFY) $(AVRDUDE_VERBOSE) $(AVRDUDE_ERASE_COUNTER)
  108.  
  109.  
  110. CC = avr-gcc
  111. OBJCOPY = avr-objcopy
  112. OBJDUMP = avr-objdump
  113. SIZE = avr-size
  114. NM = avr-nm
  115. AVRDUDE = avrdude
  116. REMOVE = rm -f
  117. MV = mv -f
  118.  
  119. # Define all object files.
  120. OBJ = $(SRC:.c=.o) $(ASRC:.S=.o)
  121.  
  122. # Define all listing files.
  123. LST = $(ASRC:.S=.lst) $(SRC:.c=.lst)
  124.  
  125. # Combine all necessary flags and optional flags.
  126. # Add target processor to flags.
  127. ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS)
  128. ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
  129.  
  130.  
  131. # Default target.
  132. all: build
  133.  
  134. build: elf hex eep
  135.  
  136. elf: $(TARGET).elf
  137. hex: $(TARGET).hex
  138. eep: $(TARGET).eep
  139. lss: $(TARGET).lss
  140. sym: $(TARGET).sym
  141.  
  142.  
  143. # Program the device.  
  144. program: $(TARGET).hex $(TARGET).eep
  145.     $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
  146.  
  147.  
  148.  
  149.  
  150. # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
  151. COFFCONVERT=$(OBJCOPY) --debugging \
  152. --change-section-address .data-0x800000 \
  153. --change-section-address .bss-0x800000 \
  154. --change-section-address .noinit-0x800000 \
  155. --change-section-address .eeprom-0x810000
  156.  
  157.  
  158. coff: $(TARGET).elf
  159.     $(COFFCONVERT) -O coff-avr $(TARGET).elf $(TARGET).cof
  160.  
  161.  
  162. extcoff: $(TARGET).elf
  163.     $(COFFCONVERT) -O coff-ext-avr $(TARGET).elf $(TARGET).cof
  164.  
  165.  
  166. .SUFFIXES: .elf .hex .eep .lss .sym
  167.  
  168. .elf.hex:
  169.     $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
  170.  
  171. .elf.eep:
  172.     -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
  173.     --change-section-lma .eeprom=0 -O $(FORMAT) $< $@
  174.  
  175. # Create extended listing file from ELF output file.
  176. .elf.lss:
  177.     $(OBJDUMP) -h -S $< > $@
  178.  
  179. # Create a symbol table from ELF output file.
  180. .elf.sym:
  181.     $(NM) -n $< > $@
  182.  
  183.  
  184.  
  185. # Link: create ELF output file from object files.
  186. $(TARGET).elf: $(OBJ)
  187.     $(CC) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS)
  188.  
  189.  
  190. # Compile: create object files from C source files.
  191. .c.o:
  192.     $(CC) -c $(ALL_CFLAGS) $< -o $@
  193.  
  194.  
  195. # Compile: create assembler files from C source files.
  196. .c.s:
  197.     $(CC) -S $(ALL_CFLAGS) $< -o $@
  198.  
  199.  
  200. # Assemble: create object files from assembler source files.
  201. .S.o:
  202.     $(CC) -c $(ALL_ASFLAGS) $< -o $@
  203.  
  204.  
  205.  
  206. # Target: clean project.
  207. clean:
  208.     $(REMOVE) $(TARGET).hex $(TARGET).eep $(TARGET).cof $(TARGET).elf \
  209.     $(TARGET).map $(TARGET).sym $(TARGET).lss \
  210.     $(OBJ) $(LST) $(SRC:.c=.s) $(SRC:.c=.d)
  211.  
  212. depend:
  213.     if grep '^# DO NOT DELETE' $(MAKEFILE) >/dev/null; \
  214.     then \
  215.         sed -e '/^# DO NOT DELETE/,$$d' $(MAKEFILE) > \
  216.             $(MAKEFILE).$$$$ && \
  217.         $(MV) $(MAKEFILE).$$$$ $(MAKEFILE); \
  218.     fi
  219.     echo '# DO NOT DELETE THIS LINE -- make depend depends on it.' \
  220.         >> $(MAKEFILE); \
  221.     $(CC) -M -mmcu=$(MCU) $(CDEFS) $(CINCS) $(SRC) $(ASRC) >> $(MAKEFILE)
  222.  
  223. .PHONY: all build elf hex eep lss sym program coff extcoff clean depend
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement