Add support for ATmega168p CPU
[pub/USBasp.git] / firmware / Makefile
1 #
2 # Makefile for usbasp
3 # 20061119 Thomas Fischl original
4 # 20061120 Hanns-Konrad Unger help: and TARGET=atmega48 added
5 # 20140308 Peter Henn TARGET=atmega328 added
6 # 20140329 Peter Henn F_CPU parameter added
7 #
8
9 # TARGET=atmega8 HFUSE=0xc9 LFUSE=0xef F_CPU=12000000
10 # TARGET=atmega8 HFUSE=0xc9 LFUSE=0xef F_CPU=16000000
11 # TARGET=atmega48 HFUSE=0xdd LFUSE=0xff
12 # TARGET=atmega168 HFUSE=0xdd LFUSE=0xef EFUSE=0x01 F_CPU=12000000
13 # TARGET=atmega168 HFUSE=0xdd LFUSE=0xef EFUSE=0x01 F_CPU=16000000
14 # TARGET=atmega168 HFUSE=0xdd LFUSE=0xe7 EFUSE=0x01 F_CPU=18000000
15 # TARGET=atmega328 HFUSE=0xd9 LFUSE=0xef EFUSE=0x05 F_CPU=12000000
16 # TARGET=atmega328 HFUSE=0xd9 LFUSE=0xef EFUSE=0x05 F_CPU=16000000
17 # TARGET=atmega328 HFUSE=0xd9 LFUSE=0xe7 EFUSE=0x05 F_CPU=18000000
18 # TARGET=at90s2313
19 TARGET=atmega8
20 HFUSE=0xc9
21 LFUSE=0xef
22 F_CPU=12000000
23
24 # ISP=bsd PORT=/dev/parport0
25 # ISP=ponyser PORT=/dev/ttyS1
26 # ISP=stk500 PORT=/dev/ttyS1
27 # ISP=usbasp PORT=/dev/usb/ttyUSB0
28 # ISP=stk500v2 PORT=/dev/ttyUSB0
29 ISP=usbasp
30 PORT=/dev/usb/ttyUSB0
31
32 help:
33 @echo "Usage: make same as make help"
34 @echo " make help same as make"
35 @echo " make main.hex create main.hex"
36 @echo " make clean remove redundant data"
37 @echo " make disasm disasm main"
38 @echo " make flash upload main.hex into flash"
39 @echo " make fuses program fuses"
40 @echo " make avrdude test avrdude"
41 @echo "Current values:"
42 @echo " TARGET=${TARGET}"
43 @echo " LFUSE=${LFUSE}"
44 @echo " HFUSE=${HFUSE}"
45 ifdef EFUSE
46 @echo " EFUSE=${EFUSE}"
47 endif
48 @echo " CLOCK=${F_CPU}"
49 @echo " ISP=${ISP}"
50 @echo " PORT=${PORT}"
51
52 COMPILE = avr-gcc -Wall -O2 -Iusbdrv -I. -mmcu=$(TARGET) -DF_CPU=$(F_CPU)L # -DDEBUG_LEVEL=2
53
54 OBJECTS = usbdrv/usbdrv.o usbdrv/usbdrvasm.o usbdrv/oddebug.o isp.o clock.o tpi.o main.o
55
56 .c.o:
57 $(COMPILE) -c $< -o $@
58 #-Wa,-ahlms=$<.lst
59
60 .S.o:
61 $(COMPILE) -x assembler-with-cpp -c $< -o $@
62 # "-x assembler-with-cpp" should not be necessary since this is the default
63 # file type for the .S (with capital S) extension. However, upper case
64 # characters are not always preserved on Windows. To ensure WinAVR
65 # compatibility define the file type manually.
66
67 .c.s:
68 $(COMPILE) -S $< -o $@
69
70 clean:
71 rm -f main.hex main.lst main.obj main.cof main.list main.map main.eep.hex main.bin *.o main.s usbdrv/*.o
72
73 # file targets:
74 main.bin: $(OBJECTS)
75 $(COMPILE) -o main.bin $(OBJECTS) -Wl,-Map,main.map
76
77 main.hex: main.bin
78 rm -f main.hex main.eep.hex
79 avr-objcopy -j .text -j .data -O ihex main.bin main.hex
80 # ./checksize main.bin
81 # do the checksize script as our last action to allow successful compilation
82 # on Windows with WinAVR where the Unix commands will fail.
83
84 disasm: main.bin
85 avr-objdump -d main.bin
86
87 cpp:
88 $(COMPILE) -E main.c
89
90 flash:
91 avrdude -c ${ISP} -p ${TARGET} -P ${PORT} -U flash:w:main.hex
92
93 fuses:
94 ifdef EFUSE
95 avrdude -c ${ISP} -p ${TARGET} -P ${PORT} -u -U hfuse:w:$(HFUSE):m -U lfuse:w:$(LFUSE):m -U efuse:w:$(EFUSE):m
96 else
97 avrdude -c ${ISP} -p ${TARGET} -P ${PORT} -u -U hfuse:w:$(HFUSE):m -U lfuse:w:$(LFUSE):m
98 endif
99
100 avrdude:
101 avrdude -c ${ISP} -p ${TARGET} -P ${PORT} -v
102
103
104 # Fuse setting, see http://www.engbedded.com/fusecalc
105 #
106 # Fuse atmega8 high byte HFUSE:
107 # 0xc9 = 1 1 0 0 1 0 0 1 <-- BOOTRST (boot reset vector at 0x0000)
108 # ^ ^ ^ ^ ^ ^ ^------ BOOTSZ0
109 # | | | | | +-------- BOOTSZ1
110 # | | | | + --------- EESAVE (don't preserve EEPROM over chip erase)
111 # | | | +-------------- CKOPT (full output swing)
112 # | | +---------------- SPIEN (allow serial programming)
113 # | +------------------ WDTON (WDT not always on)
114 # +-------------------- RSTDISBL (reset pin is enabled)
115 # Fuse atmega8 low byte LFUSE:
116 # 0x9f = 1 0 0 1 1 1 1 1
117 # ^ ^ \ / \--+--/
118 # | | | +------- CKSEL 3..0 (external >8M crystal)
119 # | | +--------------- SUT 1..0 (crystal osc, BOD enabled)
120 # | +------------------ BODEN (BrownOut Detector enabled)
121 # +-------------------- BODLEVEL (2.7V)
122 #
123 # Fuse atmega48 high byte hfuse:
124 # 0xdf = 1 1 0 1 1 1 1 1 factory setting
125 # ^ ^ ^ ^ ^ \-+-/
126 # | | | | | +------ BODLEVEL (Brown out disabled)
127 # | | | | + --------- EESAVE (don't preserve EEPROM over chip erase)
128 # | | | +-------------- WDTON (WDT not always on)
129 # | | +---------------- SPIEN (allow serial programming)
130 # | +------------------ DWEN (debug wire is disabled)
131 # +-------------------- RSTDISBL (reset pin is enabled)
132 # 0xdd = ext.reset, no DW, SPI, no watchdog, no save eeprom, BOD 2.7V
133 # Fuse atmega48 low byte lfuse:
134 # 0x62 = 0 1 1 0 0 0 1 0 factory setting
135 # ^ ^ \ / \--+--/
136 # | | | +------- CKSEL 3..0 (internal 8Mhz Oszillator)
137 # | | +--------------- SUT 1..0 (start-up time)
138 # | +------------------ CKOUT (no clock output)
139 # +-------------------- CKDIV8 (divide clock by 8)
140 # 0xdc = divide/1,no clock output,fast raising power,low Pw Oszil. 3..8 Mhz
141 # 0xe0 = divide/1,no clock output,fast raising power,external Oszil.
142 # 0xff = divide/1,no clock output,slow raising power,low Pw Oszil 8.. Mhz
143 #
144 # Fuse atmega168p high byte hfuse:
145 # 0xdf = 1 1 0 1 1 1 1 1 factory setting
146 # ^ ^ ^ ^ ^ \-+-/
147 # | | | | | +------ BODLEVEL (Brown out disabled)
148 # | | | | + --------- EESAVE (don't preserve EEPROM over chip erase)
149 # | | | +-------------- WDTON (WDT not always on)
150 # | | +---------------- SPIEN (allow serial programming)
151 # | +------------------ DWEN (debug wire is disabled)
152 # +-------------------- RSTDISBL (reset pin is enabled)
153 # 0xdd = ext.reset, no DW, SPI, no watchdog, no save eeprom, BOD 2.7V
154 # Fuse atmega168p low byte lfuse:
155 # 0x62 = 0 1 1 0 0 0 1 0 factory setting
156 # ^ ^ \ / \--+--/
157 # | | | +------- CKSEL 3..0 (internal 8Mhz Oszillator)
158 # | | +--------------- SUT 1..0 (start-up time)
159 # | +------------------ CKOUT (no clock output)
160 # +-------------------- CKDIV8 (divide clock by 8)
161 # 0xef = divide/1,no clock output,fast raising power,low Pw Oszil 8.. Mhz
162 # Fuse atmega168p extended byte efuse:
163 # 0xf9 = 1 1 1 1 1 0 0 1 factory setting
164 # \-+-+-+---/ ^ ^ ^---- BOOTRST (boot reset vector at 0x0000)
165 # ^ | +------ BOOTSZ0
166 # | +-------- BOOTSZ1
167 # +-------------- not used
168 # Note: avrdude masks not used fuse bits to zero. Therefore use only
169 # the lower three bits to define the BOOTSZx and BOOTRST
170 #
171 # Fuse atmega328p high byte hfuse:
172 # 0xd9 = 1 1 0 1 1 0 0 1 <-- BOOTRST (boot reset vector at 0x0000)
173 # ^ ^ ^ ^ ^ ^ ^------ BOOTSZ0
174 # | | | | | +-------- BOOTSZ1
175 # | | | | + --------- EESAVE (don't preserve EEPROM over chip erase)
176 # | | | +-------------- WDTON (WDT not always on)
177 # | | +---------------- SPIEN (allow serial programming)
178 # | +------------------ DWEN (debug wire is disabled)
179 # +-------------------- RSTDISBL (reset pin is enabled)
180 # 0xd9 = ext.reset, no DW, SPI, no watchdog, no save eeprom, reset vector 0x0000
181 # Fuse atmega328p low byte lfuse:
182 # 0x6d = 0 1 1 0 0 0 1 0 factory setting
183 # ^ ^ \ / \--+--/
184 # | | | +------- CKSEL 3..0 (internal 8Mhz Oszillator)
185 # | | +--------------- SUT 1..0 (start-up time)
186 # | +------------------ CKOUT (no clock output)
187 # +-------------------- CKDIV8 (divide clock by 8)
188 # 0xef = divide/1,no clock output,fast raising power,low Pw Oszil 8.. Mhz
189 # Fuse atmega328p extended byte efuse:
190 # 0xff = 1 1 1 1 1 1 1 1 factory setting
191 # \-+-+-+---/ \-+-/
192 # | +------ BODLEVEL (Brown out disabled)
193 # +-------------- not used
194 # 0xfd = BOD 2,7V
195 # Note: avrdude masks not used fuse bits to zero. Therefore use only
196 # the lower three bits to define the BOD level, here 0x05
197
198 SERIAL = `echo /dev/tty.USA19QI*`
199 UISP = uisp -dprog=$S -dserial=$(SERIAL) -dpart=auto
200 # The two lines above are for "uisp" and the AVR910 serial programmer connected
201 # to a Keyspan USB to serial converter to a Mac running Mac OS X.
202 # Choose your favorite programmer and interface.
203
204 uisp: all
205 $(UISP) --erase
206 $(UISP) --upload --verify if=main.hex