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