Rev 3488 Rev 3490
1 # 1 #
2 # Makefile for usbasp 2 # Makefile for usbasp
3 # 20061119 Thomas Fischl original 3 # 20061119 Thomas Fischl original
4 # 20061120 Hanns-Konrad Unger help: and TARGET=atmega48 added 4 # 20061120 Hanns-Konrad Unger help: and TARGET=atmega48 added
5 # 20140209 Milan Horkel added automatic built for more targets 5 # 20140209 Milan Horkel added automatic built for more targets
6   6  
7 ALL_TARGETS=atmega8 atmega88 7 ALL_TARGETS=atmega8 atmega88
8   8  
9 # Default target 9 # Default target
10 # -------------- 10 # --------------
11   11  
12 ifndef $(TARGET) 12 ifndef $(TARGET)
13 TARGET=atmega88 13 TARGET=atmega88
14 endif 14 endif
15   15  
16   16  
17 # Define target dependent constants 17 # Define target dependent constants
18 # --------------------------------- 18 # ---------------------------------
19   19  
20 ifeq ($(TARGET), atmega8) 20 ifeq ($(TARGET), atmega8)
21 HFUSE=0xC9 21 HFUSE=0xC9
22 LFUSE=0x9F 22 LFUSE=0x9F
23 endif 23 endif
24   24  
25 ifeq ($(TARGET), atmega88) 25 ifeq ($(TARGET), atmega88)
26 EFUSE=0xF9 26 EFUSE=0xF9
27 HFUSE=0xDE 27 HFUSE=0xDE
28 LFUSE=0xD7 28 LFUSE=0xD7
29 endif 29 endif
30   30  
31   31  
32 # ISP=bsd PORT=/dev/parport0 32 # ISP=bsd PORT=/dev/parport0
33 # ISP=ponyser PORT=/dev/ttyS1 33 # ISP=ponyser PORT=/dev/ttyS1
34 # ISP=stk500 PORT=/dev/ttyS1 34 # ISP=stk500 PORT=/dev/ttyS1
35 # ISP=usbasp PORT=/dev/usb/ttyUSB0 35 # ISP=usbasp PORT=/dev/usb/ttyUSB0
36 # ISP=stk500v2 PORT=/dev/ttyUSB0 36 # ISP=stk500v2 PORT=/dev/ttyUSB0
37 ISP=usbasp 37 ISP=usbasp
38 PORT=/dev/usb/ttyUSB0 38 PORT=/dev/usb/ttyUSB0
39   39  
40 help: 40 help:
41 @echo "Usage: make same as make help" 41 @echo "Usage: make same as make help"
42 @echo " make help same as make" 42 @echo " make help same as make"
43 @echo " make all build HEX for all target CPUs" 43 @echo " make all build HEX for all target CPUs"
44 @echo " make hex create HEX for default target CPU" 44 @echo " make hex create HEX for default target CPU"
45 @echo " make clean remove redundant data" 45 @echo " make clean remove redundant data"
46 @echo " make disasm create listing" 46 @echo " make disasm create listing"
47 @echo " make flash upload HEX into flash (for default target CPU)" 47 @echo " make flash upload HEX into flash (for default target CPU)"
48 @echo " make fuses program fuses (for default target CPU)" 48 @echo " make fuses program fuses (for default target CPU)"
49 @echo " make avrdude test avrdude" 49 @echo " make avrdude test avrdude"
50 @echo "Current values:" 50 @echo "Current values:"
51 @echo " TARGET=${TARGET}" 51 @echo " TARGET=${TARGET}"
52 @echo " LFUSE=${LFUSE}" 52 @echo " LFUSE=${LFUSE}"
53 @echo " HFUSE=${HFUSE}" 53 @echo " HFUSE=${HFUSE}"
54 @echo " CLOCK=12000000" 54 @echo " CLOCK=12000000"
55 @echo " ISP=${ISP}" 55 @echo " ISP=${ISP}"
56 @echo " PORT=${PORT}" 56 @echo " PORT=${PORT}"
57   57  
58 COMPILE = avr-gcc -Wall -O2 -Iusbdrv -I. -mmcu=$(TARGET) # -DDEBUG_LEVEL=2 58 COMPILE = avr-gcc -Wall -O2 -Iusbdrv -I. -mmcu=$(TARGET) # -DDEBUG_LEVEL=2
59   59  
60 OBJECTS = usbdrv/usbdrv.o usbdrv/usbdrvasm.o usbdrv/oddebug.o isp.o clock.o tpi.o main.o 60 OBJECTS = usbdrv/usbdrv.o usbdrv/usbdrvasm.o usbdrv/oddebug.o isp.o clock.o tpi.o main.o
61   61  
62 .c.o: 62 .c.o:
63 $(COMPILE) -c $< -o $@ 63 $(COMPILE) -c $< -o $@
64 #-Wa,-ahlms=$<.lst 64 #-Wa,-ahlms=$<.lst
65   65  
66 .S.o: 66 .S.o:
67 $(COMPILE) -x assembler-with-cpp -c $< -o $@ 67 $(COMPILE) -x assembler-with-cpp -c $< -o $@
68 # "-x assembler-with-cpp" should not be necessary since this is the default 68 # "-x assembler-with-cpp" should not be necessary since this is the default
69 # file type for the .S (with capital S) extension. However, upper case 69 # file type for the .S (with capital S) extension. However, upper case
70 # characters are not always preserved on Windows. To ensure WinAVR 70 # characters are not always preserved on Windows. To ensure WinAVR
71 # compatibility define the file type manually. 71 # compatibility define the file type manually.
72   72  
73 .c.s: 73 .c.s:
74 $(COMPILE) -S $< -o $@ 74 $(COMPILE) -S $< -o $@
75   75  
76 cleantmp: 76 cleantmp:
77 rm -f usbasp.lst usbasp.obj usbasp.cof usbasp.list usbasp.map usbasp.bin *.o main.s usbdrv/*.o 77 rm -f usbasp.lst usbasp.obj usbasp.cof usbasp.list usbasp.map usbasp.bin *.o main.s usbdrv/*.o
78   78  
79 clean: cleantmp 79 clean: cleantmp
80 rm -f usbasp_$(TARGET).hex usbasp_$(TARGET).eep.hex 80 rm -f usbasp_$(TARGET).hex usbasp_$(TARGET).eep.hex
81   81  
82 # file targets: 82 # file targets:
83 usbasp.bin: $(OBJECTS) 83 usbasp.bin: $(OBJECTS)
84 $(COMPILE) -o usbasp.bin $(OBJECTS) -Wl,-Map,usbasp.map 84 $(COMPILE) -o usbasp.bin $(OBJECTS) -Wl,-Map,usbasp.map
85   85  
86 usbasp.hex: usbasp_$(TARGET).hex 86 usbasp.hex: usbasp_$(TARGET).hex
87   87  
88 usbasp_$(TARGET).hex: usbasp.bin 88 usbasp_$(TARGET).hex: usbasp.bin
89 rm -f usbasp_$(TARGET).hex usbasp_$(TARGET).eep.hex 89 rm -f usbasp_$(TARGET).hex usbasp_$(TARGET).eep.hex
90 avr-objcopy -j .text -j .data -O ihex usbasp.bin $@ 90 avr-objcopy -j .text -j .data -O ihex usbasp.bin $@
91 # ./checksize usbasp.bin 91 # ./checksize usbasp.bin
92 # do the checksize script as our last action to allow successful compilation 92 # do the checksize script as our last action to allow successful compilation
93 # on Windows with WinAVR where the Unix commands will fail. 93 # on Windows with WinAVR where the Unix commands will fail.
94   94  
95 disasm: usbasp.bin 95 disasm: usbasp.bin
96 avr-objdump -d usbasp.bin 96 avr-objdump -d usbasp.bin
97   97  
98 cpp: 98 cpp:
99 $(COMPILE) -E main.c 99 $(COMPILE) -E main.c
100   100  
101 flash: 101 flash:
102 avrdude -c ${ISP} -p ${TARGET} -P ${PORT} -U flash:w:usbasp.hex 102 avrdude -c ${ISP} -p ${TARGET} -P ${PORT} -U flash:w:usbasp.hex
103   103  
104 fuses: 104 fuses:
105 avrdude -c ${ISP} -p ${TARGET} -P ${PORT} -u -U hfuse:w:$(HFUSE):m -U lfuse:w:$(LFUSE):m 105 avrdude -c ${ISP} -p ${TARGET} -P ${PORT} -u -U hfuse:w:$(HFUSE):m -U lfuse:w:$(LFUSE):m
106   106  
107 avrdude: 107 avrdude:
108 avrdude -c ${ISP} -p ${TARGET} -P ${PORT} -v 108 avrdude -c ${ISP} -p ${TARGET} -P ${PORT} -v
109   109  
110 # Fuse atmega8 110 # Fuse atmega8
111 # ------------ 111 # ------------
112 # Fuse atmega8 high byte HFUSE: 112 # Fuse atmega8 high byte HFUSE:
113 # 0xD9 = 1 1 0 1 1 0 0 1 = Factory Default Value 113 # 0xD9 = 1 1 0 1 1 0 0 1 = Factory Default Value
114 # 0xC9 = 1 1 0 0 1 0 0 1 <-- BOOTRST (boot reset vector at 0x0000) 114 # 0xC9 = 1 1 0 0 1 0 0 1 <-- BOOTRST (boot reset vector at 0x0000)
115 # ^ ^ ^ ^ ^ ^ ^------ BOOTSZ0 115 # ^ ^ ^ ^ ^ ^ ^------ BOOTSZ0
116 # | | | | | +-------- BOOTSZ1 116 # | | | | | +-------- BOOTSZ1
117 # | | | | + --------- EESAVE (don't preserve EEPROM over chip erase) 117 # | | | | + --------- EESAVE (don't preserve EEPROM over chip erase)
118 # | | | +-------------- CKOPT (full output swing) 118 # | | | +-------------- CKOPT (full output swing)
119 # | | +---------------- SPIEN (allow serial programming) 119 # | | +---------------- SPIEN (allow serial programming)
120 # | +------------------ WDTON (WDT not always on) 120 # | +------------------ WDTON (WDT not always on)
121 # +-------------------- RSTDISBL (reset pin is enabled) 121 # +-------------------- RSTDISBL (reset pin is enabled)
122 # Fuse atmega8 low byte LFUSE: 122 # Fuse atmega8 low byte LFUSE:
123 # 0xE1 = 1 1 1 0 0 0 0 1 = Factory Default Value 123 # 0xE1 = 1 1 1 0 0 0 0 1 = Factory Default Value
124 # 0x9F = 1 0 0 1 1 1 1 1 124 # 0x9F = 1 0 0 1 1 1 1 1
125 # ^ ^ \ / \--+--/ 125 # ^ ^ \ / \--+--/
126 # | | | +------- CKSEL 3..0 (external >8M crystal) 126 # | | | +------- CKSEL 3..0 (external >8M crystal)
127 # | | +--------------- SUT 1..0 (crystal osc, BOD enabled) 127 # | | +--------------- SUT 1..0 (crystal osc, BOD enabled)
128 # | +------------------ BODEN (BrownOut Detector enabled) 128 # | +------------------ BODEN (BrownOut Detector enabled)
129 # +-------------------- BODLEVEL (2.7V) 129 # +-------------------- BODLEVEL (2.7V)
130 # 130 #
131 # Fuse atmega88 131 # Fuse atmega88
132 # ------------- 132 # -------------
133 # Fuse atmega88 extended byte: 133 # Fuse atmega88 extended byte:
134 # 0xF9 = 1 1 1 1 1 0 0 1 = Factory Default Value (default value is used) 134 # 0xF9 = 1 1 1 1 1 0 0 1 = Factory Default Value (default value is used)
135 # 0xF9 = 1 1 1 1 1 0 0 1 <-- BOOTRST (select vetor) 135 # 0xF9 = 1 1 1 1 1 0 0 1 <-- BOOTRST (select vetor)
136 # \+/ 136 # \+/
137 # +----- BOOTSZ1..0 (Select Boot Size) 137 # +----- BOOTSZ1..0 (Select Boot Size)
138 # Fuse high byte: 138 # Fuse high byte:
139 # 0xDF 1 1 0 1 1 1 1 1 = Factory Default Value (default value may be used) 139 # 0xDF 1 1 0 1 1 1 1 1 = Factory Default Value (default value may be used)
140 # 0xDE = 1 1 0 1 1 1 1 0 140 # 0xDE = 1 1 0 1 1 1 1 0
141 # ^ ^ ^ ^ ^ \-+-/ 141 # ^ ^ ^ ^ ^ \-+-/
142 # | | | | | +------ BODLEVEL (1.7-2.0V) 142 # | | | | | +------ BODLEVEL (1.7-2.0V)
143 # | | | | +---------- EESAVE (don't preserve EEPROM over chip erase) 143 # | | | | +---------- EESAVE (don't preserve EEPROM over chip erase)
144 # | | | +-------------- WDTON (WDT not always on) 144 # | | | +-------------- WDTON (WDT not always on)
145 # | | +---------------- SPIEN (allow serial programming)!!! 145 # | | +---------------- SPIEN (allow serial programming)!!!
146 # | +------------------ DWEN (debug wire not enabled) 146 # | +------------------ DWEN (debug wire not enabled)
147 # +-------------------- RSTDISBL (reset pin is not disabled) 147 # +-------------------- RSTDISBL (reset pin is not disabled)
148 # Fuse low byte: 148 # Fuse low byte:
149 # 0x62 0 1 1 0 0 0 1 0 = Factory Default Value (must be programmed to use xosc) 149 # 0x62 0 1 1 0 0 0 1 0 = Factory Default Value (must be programmed to use xosc)
150 # 0xD7 = 1 1 0 1 0 1 1 1 150 # 0xD7 = 1 1 0 1 0 1 1 1
151 # ^ ^ \ / \--+--/ 151 # ^ ^ \ / \--+--/
152 # | | | +------- CKSEL 3..0 (full swing xosc, BOD enabled) 152 # | | | +------- CKSEL 3..0 (full swing xosc, BOD enabled)
153 # | | +--------------- SUT 1..0 (startup timer - see CKSEL) 153 # | | +--------------- SUT 1..0 (startup timer - see CKSEL)
154 # | +------------------ CKOUT (clock output is not enabled) 154 # | +------------------ CKOUT (clock output is not enabled)
155 # +-------------------- CLKDIV8 (clock divider is not enabled) 155 # +-------------------- CLKDIV8 (clock divider is not enabled)
156   156  
157   157  
158   158  
159 SERIAL = `echo /dev/tty.USA19QI*` 159 SERIAL = `echo /dev/tty.USA19QI*`
160 UISP = uisp -dprog=$S -dserial=$(SERIAL) -dpart=auto 160 UISP = uisp -dprog=$S -dserial=$(SERIAL) -dpart=auto
161 # The two lines above are for "uisp" and the AVR910 serial programmer connected 161 # The two lines above are for "uisp" and the AVR910 serial programmer connected
162 # to a Keyspan USB to serial converter to a Mac running Mac OS X. 162 # to a Keyspan USB to serial converter to a Mac running Mac OS X.
163 # Choose your favorite programmer and interface. 163 # Choose your favorite programmer and interface.
164   164  
165 uisp: all 165 uisp: all
166 $(UISP) --erase 166 $(UISP) --erase
167 $(UISP) --upload --verify if=usbasp_$(TARGET).hex 167 $(UISP) --upload --verify if=usbasp_$(TARGET).hex
168   168  
169 # Execute these steps for each target CPU 169 # Execute these steps for each target CPU
170 # Do not remove empty line in this definition! 170 # Do not remove empty line in this definition!
171 define EXEC 171 define EXEC
172 rm -f usbasp_$(1).hex 172 rm -f usbasp_$(1).hex
173 make TARGET=$(1) cleantmp 173 make TARGET=$(1) cleantmp
174 make TARGET=$(1) usbasp_$(1).hex 174 make TARGET=$(1) usbasp_$(1).hex
175   175  
176 endef 176 endef
177   177  
178 ALL: 178 all:
179 @$(foreach III,$(ALL_TARGETS),$(call EXEC,$(III))) 179 @$(foreach III,$(ALL_TARGETS),$(call EXEC,$(III)))
180 @make cleantmp 180 @make cleantmp