makefile.i2cmaster 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. # ----------------------------------------------------------------------------
  2. # Makefile to compile and link the I2C Master library and test program
  3. # Author: Peter Fleury
  4. # File: $Id: makefile.i2cmaster,v 1.3 2015/09/16 11:30:30 peter Exp $
  5. #
  6. # Adjust MCU and F_CPU below to your AVR target
  7. #----------------------------------------------------------------------------
  8. # usage:
  9. #
  10. # make = build software
  11. # make clean = Clean out built project files
  12. # make program = Download the hex file to the device, using avrdude.
  13. # Please customize the avrdude settings below first!
  14. #
  15. # make filename.s = Just compile filename.c into the assembler code only.
  16. # make filename.i = Create a preprocessed source file
  17. #
  18. # To rebuild project do "make clean" then "make"
  19. #----------------------------------------------------------------------------
  20. # MCU name
  21. MCU = attiny2313a
  22. # Processor frequency.
  23. # This will define a symbol, F_CPU, in all source code files equal to the
  24. # processor frequency. You can then use this symbol in your source code to
  25. # calculate timings. Do NOT tack on a 'UL' at the end, this will be done
  26. # automatically to create a 32-bit value in your source code.
  27. F_CPU = 4000000
  28. # Target file name (without extension).
  29. TARGET = test_i2cmaster
  30. # List C source files here. (C dependencies are automatically generated.)
  31. SRC = $(TARGET).c
  32. # List Assembler source files here.
  33. # Make them always end in a capital .S. Files ending in a lowercase .s
  34. # will not be considered source files but generated files (assembler
  35. # output from the compiler), and will be deleted upon "make clean"!
  36. # Even though the DOS/Win* filesystem matches both .s and .S the same,
  37. # it will preserve the spelling of the filenames, and gcc itself does
  38. # care about how the name is spelled on its command-line.
  39. ASRC = i2cmaster.S
  40. # List any extra directories to look for include files here.
  41. # Each directory must be seperated by a space.
  42. # Use forward slashes for directory separators.
  43. # For a directory that has spaces, enclose it in quotes.
  44. EXTRAINCDIRS =
  45. #specify alternate location of sources files
  46. # (unlike VPATH= which is a search path for all prerequisites, not just source files)
  47. #vpath %.c /<directory>/
  48. #vpath %.S /<directory>/
  49. # Optimization level, can be [0, 1, 2, 3, s].
  50. # 0 = turn off optimization. s = optimize for size.
  51. # (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
  52. OPT = s
  53. # Place -D or -U options here
  54. CDEFS =
  55. # Place -I options here
  56. CINCS =
  57. #---------------- Compiler Options ----------------
  58. # -gdwarf-2: generate debugging information
  59. # -O*: optimization level
  60. # -f...: tuning, see GCC manual and avr-libc documentation
  61. # -Wall...: warning level
  62. # -Wa,...: tell GCC to pass this to the assembler.
  63. # -adhlns...: create assembler listing
  64. CFLAGS = -DF_CPU=$(F_CPU)UL
  65. CFLAGS += $(CDEFS) $(CINCS)
  66. CFLAGS += -I. $(patsubst %,-I%,$(EXTRAINCDIRS))
  67. CFLAGS += -std=gnu99
  68. CFLAGS += -gdwarf-2
  69. CFLAGS += -O$(OPT)
  70. CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
  71. CFLAGS += -Wall -Wstrict-prototypes
  72. CFLAGS += -Wa,-adhlns=$(<:.c=.lst)
  73. CFLAGS += -save-temps
  74. #---------------- Assembler Options ----------------
  75. # -Wa,...: tell GCC to pass this to the assembler.
  76. # -adhlns=$(<:.S=.lst) create listing
  77. # -gdwarf-2: generate debugging information
  78. ASFLAGS = -DF_CPU=$(F_CPU)UL -x assembler-with-cpp -Wa,-gdwarf2
  79. #---------------- Library Options ----------------
  80. # Minimalistic printf version
  81. PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
  82. # Floating point printf version (requires MATH_LIB = -lm below)
  83. PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
  84. # If this is left blank, then it will use the Standard printf version.
  85. PRINTF_LIB =
  86. #PRINTF_LIB = $(PRINTF_LIB_MIN)
  87. #PRINTF_LIB = $(PRINTF_LIB_FLOAT)
  88. # Minimalistic scanf version
  89. SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
  90. # Floating point + %[ scanf version (requires MATH_LIB = -lm below)
  91. SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
  92. # If this is left blank, then it will use the Standard scanf version.
  93. SCANF_LIB =
  94. #SCANF_LIB = $(SCANF_LIB_MIN)
  95. #SCANF_LIB = $(SCANF_LIB_FLOAT)
  96. MATH_LIB = -lm
  97. #---------------- External Memory Options ----------------
  98. # 64 KB of external RAM, starting after internal RAM (ATmega128!),
  99. # used for variables (.data/.bss) and heap (malloc()).
  100. #EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff
  101. # 64 KB of external RAM, starting after internal RAM (ATmega128!),
  102. # only used for heap (malloc()).
  103. #EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff
  104. EXTMEMOPTS =
  105. #---------------- Linker Options ----------------
  106. # -Wl,...: tell GCC to pass this to linker.
  107. # -Map: create map file
  108. # --cref: add cross reference to map file
  109. LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
  110. LDFLAGS += $(EXTMEMOPTS)
  111. LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
  112. #---------------- Programming Options (avrdude) ----------------
  113. # Programming hardware: Type: avrdude -c ? to get a full listing.
  114. AVRDUDE_PROGRAMMER = usbasp
  115. # usb, com1 = serial port, lpt1 = parallel port
  116. AVRDUDE_PORT = USB
  117. AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
  118. #AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
  119. # Uncomment the following if you do /not/ wish a verification to be performed after programming the device.
  120. #AVRDUDE_NO_VERIFY = -V
  121. # Disable save mode for fuses
  122. AVRDUDE_NO_SAFEMODE = -u
  123. # Uncomment the following if you want avrdude's erase cycle counter.
  124. # Note that this counter needs to be initialized first using -Yn,
  125. #AVRDUDE_ERASE_COUNTER = -y
  126. # Increase verbosity level.
  127. #AVRDUDE_VERBOSE = -v -v
  128. # Adjust programming speed of USBasp
  129. # no -B switch 375khz (default)
  130. # -B 2000 500 hz
  131. # -B 1000 1khz
  132. # -B 500 2khz
  133. # -B 250 4khz
  134. # -B 125 8 khz
  135. # -B 62 16khz
  136. # -B 31 32khz * the cutoff for bit banged isp
  137. # -B 10 93.75 khz
  138. # -B 5 187.5 khz
  139. # -B 2 375 khz
  140. # -B 1 750 khz
  141. # -B .5 1.5mhz
  142. #AVRDUDE_SPEED = -B .5
  143. AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
  144. AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
  145. AVRDUDE_FLAGS += $(AVRDUDE_NO_SAFEMODE)
  146. AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
  147. AVRDUDE_FLAGS += $(AVRDUDE_SPEED)
  148. AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
  149. #============================================================================
  150. # Output format. (can be srec, ihex, binary)
  151. FORMAT = ihex
  152. # Define programs and commands.
  153. #SHELL = win-bash
  154. CC = avr-gcc
  155. OBJCOPY = avr-objcopy
  156. OBJDUMP = avr-objdump
  157. SIZE = avr-size
  158. NM = avr-nm
  159. AVRDUDE = avrdude
  160. REMOVE = rm -rf
  161. COPY = cp
  162. WINSHELL = cmd
  163. # Define Messages
  164. MSG_FLASH = Creating load file for Flash:
  165. MSG_EEPROM = Creating load file for EEPROM:
  166. MSG_EXTENDED_LISTING = Creating Extended Listing:
  167. MSG_SYMBOL_TABLE = Creating Symbol Table:
  168. MSG_LINKING = Linking:
  169. MSG_COMPILING = Compiling:
  170. MSG_ASSEMBLING = Assembling:
  171. MSG_CLEANING = Cleaning project:
  172. # Define all object files.
  173. OBJ = $(SRC:.c=.o) $(ASRC:.S=.o)
  174. # Define all listing files.
  175. LST = $(SRC:.c=.lst) $(ASRC:.S=.lst)
  176. # Compiler flags to generate dependency files.
  177. GENDEPFLAGS = -MD -MP -MF .dep/$(@F).d
  178. # Combine all necessary flags and optional flags.
  179. # Add target processor to flags.
  180. ALL_CFLAGS = -mmcu=$(MCU) $(CFLAGS) $(GENDEPFLAGS)
  181. ALL_ASFLAGS = -mmcu=$(MCU) -I. $(ASFLAGS)
  182. # Default target.
  183. all: gccversion $(TARGET).elf $(TARGET).hex $(TARGET).eep $(TARGET).lss $(TARGET).sym size
  184. # Display compiler version information.
  185. gccversion :
  186. @echo $(OBJ1)
  187. @$(CC) --version
  188. # Create final output files (.hex, .eep) from ELF output file.
  189. %.hex: %.elf
  190. @echo $(MSG_FLASH) $@
  191. $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
  192. %.eep: %.elf
  193. @echo $(MSG_EEPROM) $@
  194. -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 -O $(FORMAT) $< $@
  195. # Create extended listing file from ELF output file.
  196. %.lss: %.elf
  197. @echo $(MSG_EXTENDED_LISTING) $@
  198. $(OBJDUMP) -h -S $< > $@
  199. # Create a symbol table from ELF output file.
  200. %.sym: %.elf
  201. @echo $(MSG_SYMBOL_TABLE) $@
  202. $(NM) -n $< > $@
  203. # Link: create ELF output file from object files.
  204. .SECONDARY : $(TARGET).elf
  205. .PRECIOUS : $(OBJ)
  206. %.elf: $(OBJ)
  207. @echo $(MSG_LINKING) $@
  208. $(CC) -mmcu=$(MCU) $(LDFLAGS) $^ --output $(@F)
  209. # Compile: create object files from C source files.
  210. %.o : %.c
  211. @echo $(MSG_COMPILING) $<
  212. $(CC) -c $(ALL_CFLAGS) $< -o $(@F)
  213. # Compile: create assembler files from C source files.
  214. %.s : %.c
  215. $(CC) -S $(ALL_CFLAGS) $< -o $(@F)
  216. # Assemble: create object files from assembler source files.
  217. %.o : %.S
  218. @echo $(MSG_ASSEMBLING) $<
  219. $(CC) -c $(ALL_ASFLAGS) $< -o $(@F)
  220. # Create preprocessed source for use in sending a bug report.
  221. %.i : %.c
  222. $(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $(@F)
  223. # Display size of file.
  224. size: ${TARGET}.elf
  225. @avr-size -C --mcu=${MCU} ${TARGET}.elf
  226. # Program the device.
  227. program: $(TARGET).hex $(TARGET).eep
  228. $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
  229. # Delete all generated files.
  230. clean:
  231. @echo $(MSG_CLEANING)
  232. $(REMOVE) $(TARGET).hex $(TARGET).eep $(TARGET).cof $(TARGET).elf $(TARGET).map $(TARGET).sym $(TARGET).lss $(OBJ) $(LST) $(SRC:.c=.s) $(SRC:.c=.d) $(SRC:.c=.i) .dep/
  233. # Include the dependency files.
  234. #-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
  235. -include $(shell mkdir .dep 2>NUL) $(wildcard .dep/*)
  236. # Listing of phony targets.
  237. .PHONY : all size gccversion clean program