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