Simple single-color 8x8x8 LED Cube with AVRs
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

makefile 11KB

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