Makefile 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. # Name: Makefile
  2. # Project: custom-class example
  3. # Author: Christian Starkjohann
  4. # Creation Date: 2008-04-07
  5. # Tabsize: 4
  6. # Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH
  7. # License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
  8. # This Revision: $Id: Makefile 692 2008-11-07 15:07:40Z cs $
  9. DEVICE = atmega16
  10. F_CPU = 16000000 # in Hz
  11. FUSE_L = # see below for fuse values for particular devices
  12. FUSE_H =
  13. #AVRDUDE = avrdude -c stk500v2 -p $(DEVICE) -P /dev/tty.PL2303-00002006
  14. AVRDUDE = sudo avrdude -c stk500v2 -p $(DEVICE) -P /dev/tty.PL2303-00002126
  15. CFLAGS = -Iusbdrv -I. -DDEBUG_LEVEL=0
  16. #-std=gnu99
  17. OBJECTS = usbdrv/usbdrv.o usbdrv/usbdrvasm.o usbdrv/oddebug.o main.o uart.o fifo.o sram.o crc.o debug.o
  18. COMPILE = avr-gcc -Wall -Os -DF_CPU=$(F_CPU) $(CFLAGS) -mmcu=$(DEVICE)
  19. ##############################################################################
  20. # Fuse values for particular devices
  21. ##############################################################################
  22. # If your device is not listed here, go to
  23. # http://palmavr.sourceforge.net/cgi-bin/fc.cgi
  24. # and choose options for external crystal clock and no clock divider
  25. #
  26. ################################## ATMega8 ##################################
  27. # ATMega8 FUSE_L (Fuse low byte):
  28. # 0x9f = 1 0 0 1 1 1 1 1
  29. # ^ ^ \ / \--+--/
  30. # | | | +------- CKSEL 3..0 (external >8M crystal)
  31. # | | +--------------- SUT 1..0 (crystal osc, BOD enabled)
  32. # | +------------------ BODEN (BrownOut Detector enabled)
  33. # +-------------------- BODLEVEL (2.7V)
  34. # ATMega8 FUSE_H (Fuse high byte):
  35. # 0xc9 = 1 1 0 0 1 0 0 1 <-- BOOTRST (boot reset vector at 0x0000)
  36. # ^ ^ ^ ^ ^ ^ ^------ BOOTSZ0
  37. # | | | | | +-------- BOOTSZ1
  38. # | | | | + --------- EESAVE (don't preserve EEPROM over chip erase)
  39. # | | | +-------------- CKOPT (full output swing)
  40. # | | +---------------- SPIEN (allow serial programming)
  41. # | +------------------ WDTON (WDT not always on)
  42. # +-------------------- RSTDISBL (reset pin is enabled)
  43. #
  44. ############################## ATMega48/88/168 ##############################
  45. # ATMega*8 FUSE_L (Fuse low byte):
  46. # 0xdf = 1 1 0 1 1 1 1 1
  47. # ^ ^ \ / \--+--/
  48. # | | | +------- CKSEL 3..0 (external >8M crystal)
  49. # | | +--------------- SUT 1..0 (crystal osc, BOD enabled)
  50. # | +------------------ CKOUT (if 0: Clock output enabled)
  51. # +-------------------- CKDIV8 (if 0: divide by 8)
  52. # ATMega*8 FUSE_H (Fuse high byte):
  53. # 0xde = 1 1 0 1 1 1 1 0
  54. # ^ ^ ^ ^ ^ \-+-/
  55. # | | | | | +------ BODLEVEL 0..2 (110 = 1.8 V)
  56. # | | | | + --------- EESAVE (preserve EEPROM over chip erase)
  57. # | | | +-------------- WDTON (if 0: watchdog always on)
  58. # | | +---------------- SPIEN (allow serial programming)
  59. # | +------------------ DWEN (debug wire enable)
  60. # +-------------------- RSTDISBL (reset pin is enabled)
  61. #
  62. ############################## ATTiny25/45/85 ###############################
  63. # ATMega*5 FUSE_L (Fuse low byte):
  64. # 0xef = 1 1 1 0 1 1 1 1
  65. # ^ ^ \+/ \--+--/
  66. # | | | +------- CKSEL 3..0 (clock selection -> crystal @ 12 MHz)
  67. # | | +--------------- SUT 1..0 (BOD enabled, fast rising power)
  68. # | +------------------ CKOUT (clock output on CKOUT pin -> disabled)
  69. # +-------------------- CKDIV8 (divide clock by 8 -> don't divide)
  70. # ATMega*5 FUSE_H (Fuse high byte):
  71. # 0xdd = 1 1 0 1 1 1 0 1
  72. # ^ ^ ^ ^ ^ \-+-/
  73. # | | | | | +------ BODLEVEL 2..0 (brownout trigger level -> 2.7V)
  74. # | | | | +---------- EESAVE (preserve EEPROM on Chip Erase -> not preserved)
  75. # | | | +-------------- WDTON (watchdog timer always on -> disable)
  76. # | | +---------------- SPIEN (enable serial programming -> enabled)
  77. # | +------------------ DWEN (debug wire enable)
  78. # +-------------------- RSTDISBL (disable external reset -> enabled)
  79. #
  80. ################################ ATTiny2313 #################################
  81. # ATTiny2313 FUSE_L (Fuse low byte):
  82. # 0xef = 1 1 1 0 1 1 1 1
  83. # ^ ^ \+/ \--+--/
  84. # | | | +------- CKSEL 3..0 (clock selection -> crystal @ 12 MHz)
  85. # | | +--------------- SUT 1..0 (BOD enabled, fast rising power)
  86. # | +------------------ CKOUT (clock output on CKOUT pin -> disabled)
  87. # +-------------------- CKDIV8 (divide clock by 8 -> don't divide)
  88. # ATTiny2313 FUSE_H (Fuse high byte):
  89. # 0xdb = 1 1 0 1 1 0 1 1
  90. # ^ ^ ^ ^ \-+-/ ^
  91. # | | | | | +---- RSTDISBL (disable external reset -> enabled)
  92. # | | | | +-------- BODLEVEL 2..0 (brownout trigger level -> 2.7V)
  93. # | | | +-------------- WDTON (watchdog timer always on -> disable)
  94. # | | +---------------- SPIEN (enable serial programming -> enabled)
  95. # | +------------------ EESAVE (preserve EEPROM on Chip Erase -> not preserved)
  96. # +-------------------- DWEN (debug wire enable)
  97. # symbolic targets:
  98. help:
  99. @echo "This Makefile has no default rule. Use one of the following:"
  100. @echo "make hex ....... to build main.hex"
  101. @echo "make program ... to flash fuses and firmware"
  102. @echo "make fuse ...... to flash the fuses"
  103. @echo "make flash ..... to flash the firmware (use this on metaboard)"
  104. @echo "make clean ..... to delete objects and hex file"
  105. all: hex
  106. hex: main.hex
  107. program: flash fuse
  108. # rule for programming fuse bits:
  109. fuse:
  110. @[ "$(FUSE_H)" != "" -a "$(FUSE_L)" != "" ] || \
  111. { echo "*** Edit Makefile and choose values for FUSE_L and FUSE_H!"; exit 1; }
  112. $(AVRDUDE) -U hfuse:w:$(FUSE_H):m -U lfuse:w:$(FUSE_L):m
  113. # rule for uploading firmware:
  114. flash: main.hex
  115. $(AVRDUDE) -U flash:w:main.hex:i
  116. # rule for deleting dependent files (those which can be built by Make):
  117. clean:
  118. rm -f main.hex main.lst main.obj main.cof main.list main.map main.eep.hex main.elf *.o usbdrv/*.o main.s usbdrv/oddebug.s usbdrv/usbdrv.s
  119. # Generic rule for compiling C files:
  120. .c.o:
  121. $(COMPILE) -c $< -o $@
  122. # Generic rule for assembling Assembler source files:
  123. .S.o:
  124. $(COMPILE) -x assembler-with-cpp -c $< -o $@
  125. # "-x assembler-with-cpp" should not be necessary since this is the default
  126. # file type for the .S (with capital S) extension. However, upper case
  127. # characters are not always preserved on Windows. To ensure WinAVR
  128. # compatibility define the file type manually.
  129. # Generic rule for compiling C to assembler, used for debugging only.
  130. .c.s:
  131. $(COMPILE) -S $< -o $@
  132. # file targets:
  133. # Since we don't want to ship the driver multipe times, we copy it into this project:
  134. usbdrv:
  135. cp -r ../../../usbdrv .
  136. main.elf: usbdrv $(OBJECTS) # usbdrv dependency only needed because we copy it
  137. $(COMPILE) -o main.elf $(OBJECTS)
  138. main.hex: main.elf
  139. rm -f main.hex main.eep.hex
  140. avr-objcopy -j .text -j .data -O ihex main.elf main.hex
  141. avr-size main.hex
  142. # debugging targets:
  143. disasm: main.elf
  144. avr-objdump -d main.elf
  145. cpp:
  146. $(COMPILE) -E main.c