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