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