Rev 3472 Rev 3488
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), atmega88) -  
21 HFUSE=0xc9 -  
22 LFUSE=0xef -  
23 endif -  
24   -  
25 ifeq ($(TARGET), atmega8) 20 ifeq ($(TARGET), atmega8)
26 HFUSE=0xc9 21 HFUSE=0xC9
27 LFUSE=0xef 22 LFUSE=0x9F
28 endif 23 endif
29   24  
30 ifeq ($(TARGET), atmega8) 25 ifeq ($(TARGET), atmega88)
-   26 EFUSE=0xF9
31 HFUSE=0xdd 27 HFUSE=0xDE
32 LFUSE=0xff 28 LFUSE=0xD7
33 endif 29 endif
34   30  
35   31  
36   -  
37 # ISP=bsd PORT=/dev/parport0 32 # ISP=bsd PORT=/dev/parport0
38 # ISP=ponyser PORT=/dev/ttyS1 33 # ISP=ponyser PORT=/dev/ttyS1
39 # ISP=stk500 PORT=/dev/ttyS1 34 # ISP=stk500 PORT=/dev/ttyS1
40 # ISP=usbasp PORT=/dev/usb/ttyUSB0 35 # ISP=usbasp PORT=/dev/usb/ttyUSB0
41 # ISP=stk500v2 PORT=/dev/ttyUSB0 36 # ISP=stk500v2 PORT=/dev/ttyUSB0
42 ISP=usbasp 37 ISP=usbasp
43 PORT=/dev/usb/ttyUSB0 38 PORT=/dev/usb/ttyUSB0
44   39  
45 help: 40 help:
46 @echo "Usage: make same as make help" 41 @echo "Usage: make same as make help"
47 @echo " make help same as make" 42 @echo " make help same as make"
48 @echo " make all build HEX for all target CPUs" 43 @echo " make all build HEX for all target CPUs"
49 @echo " make hex create HEX for default target CPU" 44 @echo " make hex create HEX for default target CPU"
50 @echo " make clean remove redundant data" 45 @echo " make clean remove redundant data"
51 @echo " make disasm create listing" 46 @echo " make disasm create listing"
52 @echo " make flash upload HEX into flash (for default target CPU)" 47 @echo " make flash upload HEX into flash (for default target CPU)"
53 @echo " make fuses program fuses (for default target CPU)" 48 @echo " make fuses program fuses (for default target CPU)"
54 @echo " make avrdude test avrdude" 49 @echo " make avrdude test avrdude"
55 @echo "Current values:" 50 @echo "Current values:"
56 @echo " TARGET=${TARGET}" 51 @echo " TARGET=${TARGET}"
57 @echo " LFUSE=${LFUSE}" 52 @echo " LFUSE=${LFUSE}"
58 @echo " HFUSE=${HFUSE}" 53 @echo " HFUSE=${HFUSE}"
59 @echo " CLOCK=12000000" 54 @echo " CLOCK=12000000"
60 @echo " ISP=${ISP}" 55 @echo " ISP=${ISP}"
61 @echo " PORT=${PORT}" 56 @echo " PORT=${PORT}"
62   57  
63 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
64   59  
65 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
66   61  
67 .c.o: 62 .c.o:
68 $(COMPILE) -c $< -o $@ 63 $(COMPILE) -c $< -o $@
69 #-Wa,-ahlms=$<.lst 64 #-Wa,-ahlms=$<.lst
70   65  
71 .S.o: 66 .S.o:
72 $(COMPILE) -x assembler-with-cpp -c $< -o $@ 67 $(COMPILE) -x assembler-with-cpp -c $< -o $@
73 # "-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
74 # 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
75 # characters are not always preserved on Windows. To ensure WinAVR 70 # characters are not always preserved on Windows. To ensure WinAVR
76 # compatibility define the file type manually. 71 # compatibility define the file type manually.
77   72  
78 .c.s: 73 .c.s:
79 $(COMPILE) -S $< -o $@ 74 $(COMPILE) -S $< -o $@
80   75  
81 cleantmp: 76 cleantmp:
82 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
83   78  
84 clean: cleantmp 79 clean: cleantmp
85 rm -f usbasp_$(TARGET).hex usbasp_$(TARGET).eep.hex 80 rm -f usbasp_$(TARGET).hex usbasp_$(TARGET).eep.hex
86   81  
87 # file targets: 82 # file targets:
88 usbasp.bin: $(OBJECTS) 83 usbasp.bin: $(OBJECTS)
89 $(COMPILE) -o usbasp.bin $(OBJECTS) -Wl,-Map,usbasp.map 84 $(COMPILE) -o usbasp.bin $(OBJECTS) -Wl,-Map,usbasp.map
90   85  
91 usbasp.hex: usbasp_$(TARGET).hex 86 usbasp.hex: usbasp_$(TARGET).hex
92   87  
93 usbasp_$(TARGET).hex: usbasp.bin 88 usbasp_$(TARGET).hex: usbasp.bin
94 rm -f usbasp_$(TARGET).hex usbasp_$(TARGET).eep.hex 89 rm -f usbasp_$(TARGET).hex usbasp_$(TARGET).eep.hex
95 avr-objcopy -j .text -j .data -O ihex usbasp.bin $@ 90 avr-objcopy -j .text -j .data -O ihex usbasp.bin $@
96 # ./checksize usbasp.bin 91 # ./checksize usbasp.bin
97 # 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
98 # on Windows with WinAVR where the Unix commands will fail. 93 # on Windows with WinAVR where the Unix commands will fail.
99   94  
100 disasm: usbasp.bin 95 disasm: usbasp.bin
101 avr-objdump -d usbasp.bin 96 avr-objdump -d usbasp.bin
102   97  
103 cpp: 98 cpp:
104 $(COMPILE) -E main.c 99 $(COMPILE) -E main.c
105   100  
106 flash: 101 flash:
107 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
108   103  
109 fuses: 104 fuses:
110 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
111   106  
112 avrdude: 107 avrdude:
113 avrdude -c ${ISP} -p ${TARGET} -P ${PORT} -v 108 avrdude -c ${ISP} -p ${TARGET} -P ${PORT} -v
114   109  
-   110 # Fuse atmega8
-   111 # ------------
115 # Fuse atmega8 high byte HFUSE: 112 # Fuse atmega8 high byte HFUSE:
-   113 # 0xD9 = 1 1 0 1 1 0 0 1 = Factory Default Value
116 # 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)
117 # ^ ^ ^ ^ ^ ^ ^------ BOOTSZ0 115 # ^ ^ ^ ^ ^ ^ ^------ BOOTSZ0
118 # | | | | | +-------- BOOTSZ1 116 # | | | | | +-------- BOOTSZ1
119 # | | | | + --------- EESAVE (don't preserve EEPROM over chip erase) 117 # | | | | + --------- EESAVE (don't preserve EEPROM over chip erase)
120 # | | | +-------------- CKOPT (full output swing) 118 # | | | +-------------- CKOPT (full output swing)
121 # | | +---------------- SPIEN (allow serial programming) 119 # | | +---------------- SPIEN (allow serial programming)
122 # | +------------------ WDTON (WDT not always on) 120 # | +------------------ WDTON (WDT not always on)
123 # +-------------------- RSTDISBL (reset pin is enabled) 121 # +-------------------- RSTDISBL (reset pin is enabled)
124 # Fuse atmega8 low byte LFUSE: 122 # Fuse atmega8 low byte LFUSE:
-   123 # 0xE1 = 1 1 1 0 0 0 0 1 = Factory Default Value
125 # 0x9f = 1 0 0 1 1 1 1 1 124 # 0x9F = 1 0 0 1 1 1 1 1
126 # ^ ^ \ / \--+--/ 125 # ^ ^ \ / \--+--/
127 # | | | +------- CKSEL 3..0 (external >8M crystal) 126 # | | | +------- CKSEL 3..0 (external >8M crystal)
128 # | | +--------------- SUT 1..0 (crystal osc, BOD enabled) 127 # | | +--------------- SUT 1..0 (crystal osc, BOD enabled)
129 # | +------------------ BODEN (BrownOut Detector enabled) 128 # | +------------------ BODEN (BrownOut Detector enabled)
130 # +-------------------- BODLEVEL (2.7V) 129 # +-------------------- BODLEVEL (2.7V)
131 # 130 #
-   131 # Fuse atmega88
-   132 # -------------
132 # Fuse atmega48 high byte hfuse: 133 # Fuse atmega88 extended byte:
-   134 # 0xF9 = 1 1 1 1 1 0 0 1 = Factory Default Value (default value is used)
133 # 0xdf = 1 1 0 1 1 1 1 1 factory setting 135 # 0xF9 = 1 1 1 1 1 0 0 1 <-- BOOTRST (select vetor)
-   136 # \+/
-   137 # +----- BOOTSZ1..0 (Select Boot Size)
-   138 # Fuse high byte:
-   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
134 # ^ ^ ^ ^ ^ \-+-/ 141 # ^ ^ ^ ^ ^ \-+-/
135 # | | | | | +------ BODLEVEL (Brown out disabled) 142 # | | | | | +------ BODLEVEL (1.7-2.0V)
136 # | | | | + --------- EESAVE (don't preserve EEPROM over chip erase) 143 # | | | | +---------- EESAVE (don't preserve EEPROM over chip erase)
137 # | | | +-------------- WDTON (WDT not always on) 144 # | | | +-------------- WDTON (WDT not always on)
138 # | | +---------------- SPIEN (allow serial programming) 145 # | | +---------------- SPIEN (allow serial programming)!!!
139 # | +------------------ DWEN (debug wire is disabled) 146 # | +------------------ DWEN (debug wire not enabled)
140 # +-------------------- RSTDISBL (reset pin is enabled) 147 # +-------------------- RSTDISBL (reset pin is not disabled)
141 # 0xdd = ext.reset, no DW, SPI, no watchdog, no save eeprom, BOD 2.7V -  
142 # Fuse atmega48 low byte lfuse: 148 # Fuse low byte:
-   149 # 0x62 0 1 1 0 0 0 1 0 = Factory Default Value (must be programmed to use xosc)
143 # 0x62 = 0 1 1 0 0 0 1 0 factory setting 150 # 0xD7 = 1 1 0 1 0 1 1 1
144 # ^ ^ \ / \--+--/ 151 # ^ ^ \ / \--+--/
145 # | | | +------- CKSEL 3..0 (internal 8Mhz Oszillator) 152 # | | | +------- CKSEL 3..0 (full swing xosc, BOD enabled)
146 # | | +--------------- SUT 1..0 (start-up time) 153 # | | +--------------- SUT 1..0 (startup timer - see CKSEL)
147 # | +------------------ CKOUT (no clock output) 154 # | +------------------ CKOUT (clock output is not enabled)
148 # +-------------------- CKDIV8 (divide clock by 8) 155 # +-------------------- CLKDIV8 (clock divider is not enabled)
149 # 0xdc = divide/1,no clock output,fast raising power,low Pw Oszil. 3..8 Mhz -  
150 # 0xe0 = divide/1,no clock output,fast raising power,external Oszil. -  
151 # 0xff = divide/1,no clock output,slow raising power,low Pw Oszil 8.. Mhz -  
-   156  
152   157  
153   158  
154 SERIAL = `echo /dev/tty.USA19QI*` 159 SERIAL = `echo /dev/tty.USA19QI*`
155 UISP = uisp -dprog=$S -dserial=$(SERIAL) -dpart=auto 160 UISP = uisp -dprog=$S -dserial=$(SERIAL) -dpart=auto
156 # 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
157 # 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.
158 # Choose your favorite programmer and interface. 163 # Choose your favorite programmer and interface.
159   164  
160 uisp: all 165 uisp: all
161 $(UISP) --erase 166 $(UISP) --erase
162 $(UISP) --upload --verify if=usbasp_$(TARGET).hex 167 $(UISP) --upload --verify if=usbasp_$(TARGET).hex
163   168  
164 # Execute these steps for each target CPU 169 # Execute these steps for each target CPU
165 # Do not remove empty line in this definition! 170 # Do not remove empty line in this definition!
166 define EXEC 171 define EXEC
167 rm -f usbasp_$(1).hex 172 rm -f usbasp_$(1).hex
168 make TARGET=$(1) cleantmp 173 make TARGET=$(1) cleantmp
169 make TARGET=$(1) usbasp_$(1).hex 174 make TARGET=$(1) usbasp_$(1).hex
170   175  
171 endef 176 endef
172   177  
173 ALL: 178 ALL:
174 @$(foreach III,$(ALL_TARGETS),$(call EXEC,$(III))) 179 @$(foreach III,$(ALL_TARGETS),$(call EXEC,$(III)))
175 @make cleantmp 180 @make cleantmp