Simple single-color 8x8x8 LED Cube with AVRs
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

makefile 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  1. # Makefile
  2. #
  3. # On command line:
  4. #
  5. # make all = Make software.
  6. #
  7. # make clean = Clean out built project files.
  8. #
  9. # make coff = Convert ELF to AVR COFF (for use with AVR Studio 3.x or VMLAB).
  10. #
  11. # make extcoff = Convert ELF to AVR Extended COFF (for use with AVR Studio
  12. # 4.07 or greater).
  13. #
  14. # make program = Download the hex file to the device, using avrdude. Please
  15. # customize the avrdude settings below first!
  16. #
  17. # make filename.s = Just compile filename.c into the assembler code only
  18. #
  19. # To rebuild project do "make clean" then "make all".
  20. #
  21. # MCU name
  22. MCU = atmega32
  23. # Main Oscillator Frequency
  24. # This is only used to define F_OSC in all assembler and c-sources.
  25. F_CPU = 16000000
  26. # Output format. (can be srec, ihex, binary)
  27. FORMAT = ihex
  28. # Target file name (without extension).
  29. TARGET = main
  30. # List C source files here. (C dependencies are automatically generated.)
  31. SRC = $(TARGET).c
  32. SRC += uart.c # Additional Source-File
  33. SRC += cube.c
  34. # List Assembler source files here.
  35. # Make them always end in a capital .S. Files ending in a lowercase .s
  36. # will not be considered source files but generated files (assembler
  37. # output from the compiler), and will be deleted upon "make clean"!
  38. # Even though the DOS/Win* filesystem matches both .s and .S the same,
  39. # it will preserve the spelling of the filenames, and gcc itself does
  40. # care about how the name is spelled on its command-line.
  41. ASRC =
  42. # Optimization level, can be [0, 1, 2, 3, s].
  43. # 0 = turn off optimization. s = optimize for size.
  44. # (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
  45. OPT = s
  46. # Debugging format.
  47. # Native formats for AVR-GCC's -g are stabs [default], or dwarf-2.
  48. # AVR (extended) COFF requires stabs, plus an avr-objcopy run.
  49. #DEBUG = stabs
  50. DEBUG = dwarf-2
  51. # List any extra directories to look for include files here.
  52. # Each directory must be seperated by a space.
  53. EXTRAINCDIRS =
  54. # Compiler flag to set the C Standard level.
  55. # c89 - "ANSI" C
  56. # gnu89 - c89 plus GCC extensions
  57. # c99 - ISO C99 standard (not yet fully implemented)
  58. # gnu99 - c99 plus GCC extensions
  59. CSTANDARD = -std=gnu99
  60. # Place -D or -U options here
  61. CDEFS =
  62. # Place -I options here
  63. CINCS =
  64. # Compiler flags.
  65. # -g*: generate debugging information
  66. # -O*: optimization level
  67. # -f...: tuning, see GCC manual and avr-libc documentation
  68. # -Wall...: warning level
  69. # -Wa,...: tell GCC to pass this to the assembler.
  70. # -adhlns...: create assembler listing
  71. CFLAGS = -g$(DEBUG)
  72. CFLAGS += $(CDEFS) $(CINCS)
  73. CFLAGS += -O$(OPT)
  74. CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
  75. CFLAGS += -Wall -Wstrict-prototypes
  76. CFLAGS += -Wa,-adhlns=$(<:.c=.lst)
  77. CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
  78. CFLAGS += $(CSTANDARD)
  79. CFLAGS += -DF_CPU=$(F_CPU)
  80. # Assembler flags.
  81. # -Wa,...: tell GCC to pass this to the assembler.
  82. # -ahlms: create listing
  83. # -gstabs: have the assembler create line number information; note that
  84. # for use in COFF files, additional information about filenames
  85. # and function names needs to be present in the assembler source
  86. # files -- see avr-libc docs [FIXME: not yet described there]
  87. ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
  88. ASFLAGS += -DF_CPU=$(F_CPU)
  89. #Additional libraries.
  90. # Minimalistic printf version
  91. PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
  92. # Floating point printf version (requires MATH_LIB = -lm below)
  93. PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
  94. PRINTF_LIB =
  95. # Minimalistic scanf version
  96. SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
  97. # Floating point + %[ scanf version (requires MATH_LIB = -lm below)
  98. SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
  99. SCANF_LIB =
  100. MATH_LIB = -lm
  101. # External memory options
  102. # 64 KB of external RAM, starting after internal RAM (ATmega128!),
  103. # used for variables (.data/.bss) and heap (malloc()).
  104. #EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff
  105. # 64 KB of external RAM, starting after internal RAM (ATmega128!),
  106. # only used for heap (malloc()).
  107. #EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff
  108. EXTMEMOPTS =
  109. # Linker flags.
  110. # -Wl,...: tell GCC to pass this to linker.
  111. # -Map: create map file
  112. # --cref: add cross reference to map file
  113. LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
  114. LDFLAGS += $(EXTMEMOPTS)
  115. LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
  116. # Programming support using avrdude. Settings and variables.
  117. # Programming hardware: alf avr910 avrisp bascom bsd
  118. # dt006 pavr picoweb pony-stk200 sp12 stk200 stk500
  119. #
  120. # Type: avrdude -c ?
  121. # to get a full listing.
  122. #
  123. AVRDUDE_PROGRAMMER = stk500
  124. # com1 = serial port. Use lpt1 to connect to parallel port.
  125. AVRDUDE_PORT = com1 # programmer connected to serial device
  126. AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
  127. #AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
  128. # Uncomment the following if you want avrdude's erase cycle counter.
  129. # Note that this counter needs to be initialized first using -Yn,
  130. # see avrdude manual.
  131. #AVRDUDE_ERASE_COUNTER = -y
  132. # Uncomment the following if you do /not/ wish a verification to be
  133. # performed after programming the device.
  134. #AVRDUDE_NO_VERIFY = -V
  135. # Increase verbosity level. Please use this when submitting bug
  136. # reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
  137. # to submit bug reports.
  138. #AVRDUDE_VERBOSE = -v -v
  139. AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
  140. AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
  141. AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
  142. AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
  143. # ---------------------------------------------------------------------------
  144. # Define directories, if needed.
  145. DIRAVR = /usr/local/CrossPack-AVR
  146. DIRAVRBIN = $(DIRAVR)/bin
  147. DIRAVRUTILS = $(DIRAVR)/bin
  148. DIRINC = .
  149. DIRLIB = $(DIRAVR)/lib
  150. # Define programs and commands.
  151. SHELL = bash
  152. CC = avr-gcc
  153. OBJCOPY = avr-objcopy
  154. OBJDUMP = avr-objdump
  155. SIZE = avr-size
  156. NM = avr-nm
  157. AVRDUDE = avrdude
  158. REMOVE = rm -f
  159. COPY = cp
  160. # Define Messages
  161. # English
  162. MSG_ERRORS_NONE = Errors: none
  163. MSG_BEGIN = -------- begin --------
  164. MSG_END = -------- end --------
  165. MSG_SIZE_BEFORE = Size before:
  166. MSG_SIZE_AFTER = Size after:
  167. MSG_COFF = Converting to AVR COFF:
  168. MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
  169. MSG_FLASH = Creating load file for Flash:
  170. MSG_EEPROM = Creating load file for EEPROM:
  171. MSG_EXTENDED_LISTING = Creating Extended Listing:
  172. MSG_SYMBOL_TABLE = Creating Symbol Table:
  173. MSG_LINKING = Linking:
  174. MSG_COMPILING = Compiling:
  175. MSG_ASSEMBLING = Assembling:
  176. MSG_CLEANING = Cleaning project:
  177. # Define all object files.
  178. OBJ = $(SRC:.c=.o) $(ASRC:.S=.o)
  179. # Define all listing files.
  180. LST = $(ASRC:.S=.lst) $(SRC:.c=.lst)
  181. # Compiler flags to generate dependency files.
  182. ### GENDEPFLAGS = -Wp,-M,-MP,-MT,$(*F).o,-MF,.dep/$(@F).d
  183. GENDEPFLAGS = -MD -MP -MF .dep/$(@F).d
  184. # Combine all necessary flags and optional flags.
  185. # Add target processor to flags.
  186. ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
  187. ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
  188. # Default target.
  189. all: begin gccversion sizebefore build sizeafter finished end
  190. build: elf hex eep lss sym
  191. elf: $(TARGET).elf
  192. hex: $(TARGET).hex
  193. eep: $(TARGET).eep
  194. lss: $(TARGET).lss
  195. sym: $(TARGET).sym
  196. # Eye candy.
  197. # AVR Studio 3.x does not check make's exit code but relies on
  198. # the following magic strings to be generated by the compile job.
  199. begin:
  200. @echo
  201. @echo $(MSG_BEGIN)
  202. finished:
  203. @echo $(MSG_ERRORS_NONE)
  204. end:
  205. @echo $(MSG_END)
  206. @echo
  207. # Display size of file.
  208. HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
  209. ELFSIZE = $(SIZE) -A $(TARGET).elf
  210. sizebefore:
  211. @if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); echo; fi
  212. sizeafter:
  213. @if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi
  214. # Display compiler version information.
  215. gccversion :
  216. @$(CC) --version
  217. # Program the device.
  218. program: $(TARGET).hex $(TARGET).eep
  219. $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
  220. # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
  221. COFFCONVERT=$(OBJCOPY) --debugging \
  222. --change-section-address .data-0x800000 \
  223. --change-section-address .bss-0x800000 \
  224. --change-section-address .noinit-0x800000 \
  225. --change-section-address .eeprom-0x810000
  226. coff: $(TARGET).elf
  227. @echo
  228. @echo $(MSG_COFF) $(TARGET).cof
  229. $(COFFCONVERT) -O coff-avr $< $(TARGET).cof
  230. extcoff: $(TARGET).elf
  231. @echo
  232. @echo $(MSG_EXTENDED_COFF) $(TARGET).cof
  233. $(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
  234. # Create final output files (.hex, .eep) from ELF output file.
  235. %.hex: %.elf
  236. @echo
  237. @echo $(MSG_FLASH) $@
  238. $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
  239. %.eep: %.elf
  240. @echo
  241. @echo $(MSG_EEPROM) $@
  242. -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
  243. --change-section-lma .eeprom=0 -O $(FORMAT) $< $@
  244. # Create extended listing file from ELF output file.
  245. %.lss: %.elf
  246. @echo
  247. @echo $(MSG_EXTENDED_LISTING) $@
  248. $(OBJDUMP) -h -S $< > $@
  249. # Create a symbol table from ELF output file.
  250. %.sym: %.elf
  251. @echo
  252. @echo $(MSG_SYMBOL_TABLE) $@
  253. $(NM) -n $< > $@
  254. # Link: create ELF output file from object files.
  255. .SECONDARY : $(TARGET).elf
  256. .PRECIOUS : $(OBJ)
  257. %.elf: $(OBJ)
  258. @echo
  259. @echo $(MSG_LINKING) $@
  260. $(CC) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS)
  261. # Compile: create object files from C source files.
  262. %.o : %.c
  263. @echo
  264. @echo $(MSG_COMPILING) $<
  265. $(CC) -c $(ALL_CFLAGS) $< -o $@
  266. # Compile: create assembler files from C source files.
  267. %.s : %.c
  268. $(CC) -S $(ALL_CFLAGS) $< -o $@
  269. # Assemble: create object files from assembler source files.
  270. %.o : %.S
  271. @echo
  272. @echo $(MSG_ASSEMBLING) $<
  273. $(CC) -c $(ALL_ASFLAGS) $< -o $@
  274. # Target: clean project.
  275. clean: begin clean_list finished end
  276. clean_list :
  277. @echo
  278. @echo $(MSG_CLEANING)
  279. $(REMOVE) $(TARGET).hex
  280. $(REMOVE) $(TARGET).eep
  281. $(REMOVE) $(TARGET).obj
  282. $(REMOVE) $(TARGET).cof
  283. $(REMOVE) $(TARGET).elf
  284. $(REMOVE) $(TARGET).map
  285. $(REMOVE) $(TARGET).obj
  286. $(REMOVE) $(TARGET).a90
  287. $(REMOVE) $(TARGET).sym
  288. $(REMOVE) $(TARGET).lnk
  289. $(REMOVE) $(TARGET).lss
  290. $(REMOVE) $(OBJ)
  291. $(REMOVE) $(LST)
  292. $(REMOVE) $(SRC:.c=.s)
  293. $(REMOVE) $(SRC:.c=.d)
  294. $(REMOVE) .dep/*
  295. # Include the dependency files.
  296. -include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
  297. # Listing of phony targets.
  298. .PHONY : all begin finish end sizebefore sizeafter gccversion \
  299. build elf hex eep lss sym coff extcoff \
  300. clean clean_list program