3 # 20061119 Thomas Fischl original
4 # 20061120 Hanns-Konrad Unger help: and TARGET=atmega48 added
5 # 20140308 Peter Henn TARGET=atmega328 added
6 # 20140329 Peter Henn F_CPU parameter added
9 # TARGET=atmega8 HFUSE=0xc9 LFUSE=0xef F_CPU=12000000
10 # TARGET=atmega8 HFUSE=0xc9 LFUSE=0xef F_CPU=16000000
11 # TARGET=atmega48 HFUSE=0xdd LFUSE=0xff
12 # TARGET=atmega168 HFUSE=0xdd LFUSE=0xef EFUSE=0x01 F_CPU=12000000
13 # TARGET=atmega168 HFUSE=0xdd LFUSE=0xef EFUSE=0x01 F_CPU=16000000
14 # TARGET=atmega168 HFUSE=0xdd LFUSE=0xe7 EFUSE=0x01 F_CPU=18000000
15 # TARGET=atmega328 HFUSE=0xd9 LFUSE=0xef EFUSE=0x05 F_CPU=12000000
16 # TARGET=atmega328 HFUSE=0xd9 LFUSE=0xef EFUSE=0x05 F_CPU=16000000
17 # TARGET=atmega328 HFUSE=0xd9 LFUSE=0xe7 EFUSE=0x05 F_CPU=18000000
24 # ISP=bsd PORT=/dev/parport0
25 # ISP=ponyser PORT=/dev/ttyS1
26 # ISP=stk500 PORT=/dev/ttyS1
27 # ISP=usbasp PORT=/dev/usb/ttyUSB0
28 # ISP=stk500v2 PORT=/dev/ttyUSB0
33 @echo
"Usage: make same as make help"
34 @echo
" make help same as make"
35 @echo
" make main.hex create main.hex"
36 @echo
" make clean remove redundant data"
37 @echo
" make disasm disasm main"
38 @echo
" make flash upload main.hex into flash"
39 @echo
" make fuses program fuses"
40 @echo
" make avrdude test avrdude"
41 @echo
"Current values:"
42 @echo
" TARGET=${TARGET}"
43 @echo
" LFUSE=${LFUSE}"
44 @echo
" HFUSE=${HFUSE}"
46 @echo
" EFUSE=${EFUSE}"
48 @echo
" CLOCK=${F_CPU}"
52 COMPILE
= avr-gcc
-Wall
-O2
-Iusbdrv
-I.
-mmcu
=$(TARGET
) -DF_CPU
=$(F_CPU
)L
# -DDEBUG_LEVEL=2
54 OBJECTS
= usbdrv
/usbdrv.o usbdrv
/usbdrvasm.o usbdrv
/oddebug.o isp.o clock.o tpi.o main.o
57 $(COMPILE
) -c
$< -o
$@
61 $(COMPILE
) -x assembler-with-cpp
-c
$< -o
$@
62 # "-x assembler-with-cpp" should not be necessary since this is the default
63 # file type for the .S (with capital S) extension. However, upper case
64 # characters are not always preserved on Windows. To ensure WinAVR
65 # compatibility define the file type manually.
68 $(COMPILE
) -S
$< -o
$@
71 rm -f main.hex main.lst main.obj main.cof main.list main.map main.eep.hex main.bin
*.o main.s usbdrv
/*.o
75 $(COMPILE
) -o main.bin
$(OBJECTS
) -Wl
,-Map
,main.map
78 rm -f main.hex main.eep.hex
79 avr-objcopy
-j .text
-j .data
-O ihex main.bin main.hex
80 # ./checksize main.bin
81 # do the checksize script as our last action to allow successful compilation
82 # on Windows with WinAVR where the Unix commands will fail.
85 avr-objdump
-d main.bin
91 avrdude
-c
${ISP} -p
${TARGET} -P
${PORT} -U flash
:w
:main.hex
95 avrdude
-c
${ISP} -p
${TARGET} -P
${PORT} -u
-U hfuse
:w
:$(HFUSE
):m
-U lfuse
:w
:$(LFUSE
):m
-U efuse
:w
:$(EFUSE
):m
97 avrdude
-c
${ISP} -p
${TARGET} -P
${PORT} -u
-U hfuse
:w
:$(HFUSE
):m
-U lfuse
:w
:$(LFUSE
):m
101 avrdude
-c
${ISP} -p
${TARGET} -P
${PORT} -v
104 # Fuse setting, see http://www.engbedded.com/fusecalc
106 # Fuse atmega8 high byte HFUSE:
107 # 0xc9 = 1 1 0 0 1 0 0 1 <-- BOOTRST (boot reset vector at 0x0000)
108 # ^ ^ ^ ^ ^ ^ ^------ BOOTSZ0
109 # | | | | | +-------- BOOTSZ1
110 # | | | | + --------- EESAVE (don't preserve EEPROM over chip erase)
111 # | | | +-------------- CKOPT (full output swing)
112 # | | +---------------- SPIEN (allow serial programming)
113 # | +------------------ WDTON (WDT not always on)
114 # +-------------------- RSTDISBL (reset pin is enabled)
115 # Fuse atmega8 low byte LFUSE:
116 # 0x9f = 1 0 0 1 1 1 1 1
118 # | | | +------- CKSEL 3..0 (external >8M crystal)
119 # | | +--------------- SUT 1..0 (crystal osc, BOD enabled)
120 # | +------------------ BODEN (BrownOut Detector enabled)
121 # +-------------------- BODLEVEL (2.7V)
123 # Fuse atmega48 high byte hfuse:
124 # 0xdf = 1 1 0 1 1 1 1 1 factory setting
126 # | | | | | +------ BODLEVEL (Brown out disabled)
127 # | | | | + --------- EESAVE (don't preserve EEPROM over chip erase)
128 # | | | +-------------- WDTON (WDT not always on)
129 # | | +---------------- SPIEN (allow serial programming)
130 # | +------------------ DWEN (debug wire is disabled)
131 # +-------------------- RSTDISBL (reset pin is enabled)
132 # 0xdd = ext.reset, no DW, SPI, no watchdog, no save eeprom, BOD 2.7V
133 # Fuse atmega48 low byte lfuse:
134 # 0x62 = 0 1 1 0 0 0 1 0 factory setting
136 # | | | +------- CKSEL 3..0 (internal 8Mhz Oszillator)
137 # | | +--------------- SUT 1..0 (start-up time)
138 # | +------------------ CKOUT (no clock output)
139 # +-------------------- CKDIV8 (divide clock by 8)
140 # 0xdc = divide/1,no clock output,fast raising power,low Pw Oszil. 3..8 Mhz
141 # 0xe0 = divide/1,no clock output,fast raising power,external Oszil.
142 # 0xff = divide/1,no clock output,slow raising power,low Pw Oszil 8.. Mhz
144 # Fuse atmega168p high byte hfuse:
145 # 0xdf = 1 1 0 1 1 1 1 1 factory setting
147 # | | | | | +------ BODLEVEL (Brown out disabled)
148 # | | | | + --------- EESAVE (don't preserve EEPROM over chip erase)
149 # | | | +-------------- WDTON (WDT not always on)
150 # | | +---------------- SPIEN (allow serial programming)
151 # | +------------------ DWEN (debug wire is disabled)
152 # +-------------------- RSTDISBL (reset pin is enabled)
153 # 0xdd = ext.reset, no DW, SPI, no watchdog, no save eeprom, BOD 2.7V
154 # Fuse atmega168p low byte lfuse:
155 # 0x62 = 0 1 1 0 0 0 1 0 factory setting
157 # | | | +------- CKSEL 3..0 (internal 8Mhz Oszillator)
158 # | | +--------------- SUT 1..0 (start-up time)
159 # | +------------------ CKOUT (no clock output)
160 # +-------------------- CKDIV8 (divide clock by 8)
161 # 0xef = divide/1,no clock output,fast raising power,low Pw Oszil 8.. Mhz
162 # Fuse atmega168p extended byte efuse:
163 # 0xf9 = 1 1 1 1 1 0 0 1 factory setting
164 # \-+-+-+---/ ^ ^ ^---- BOOTRST (boot reset vector at 0x0000)
165 # ^ | +------ BOOTSZ0
166 # | +-------- BOOTSZ1
167 # +-------------- not used
168 # Note: avrdude masks not used fuse bits to zero. Therefore use only
169 # the lower three bits to define the BOOTSZx and BOOTRST
171 # Fuse atmega328p high byte hfuse:
172 # 0xd9 = 1 1 0 1 1 0 0 1 <-- BOOTRST (boot reset vector at 0x0000)
173 # ^ ^ ^ ^ ^ ^ ^------ BOOTSZ0
174 # | | | | | +-------- BOOTSZ1
175 # | | | | + --------- EESAVE (don't preserve EEPROM over chip erase)
176 # | | | +-------------- WDTON (WDT not always on)
177 # | | +---------------- SPIEN (allow serial programming)
178 # | +------------------ DWEN (debug wire is disabled)
179 # +-------------------- RSTDISBL (reset pin is enabled)
180 # 0xd9 = ext.reset, no DW, SPI, no watchdog, no save eeprom, reset vector 0x0000
181 # Fuse atmega328p low byte lfuse:
182 # 0x6d = 0 1 1 0 0 0 1 0 factory setting
184 # | | | +------- CKSEL 3..0 (internal 8Mhz Oszillator)
185 # | | +--------------- SUT 1..0 (start-up time)
186 # | +------------------ CKOUT (no clock output)
187 # +-------------------- CKDIV8 (divide clock by 8)
188 # 0xef = divide/1,no clock output,fast raising power,low Pw Oszil 8.. Mhz
189 # Fuse atmega328p extended byte efuse:
190 # 0xff = 1 1 1 1 1 1 1 1 factory setting
192 # | +------ BODLEVEL (Brown out disabled)
193 # +-------------- not used
195 # Note: avrdude masks not used fuse bits to zero. Therefore use only
196 # the lower three bits to define the BOD level, here 0x05
198 SERIAL
= `echo /dev/tty.USA19QI*`
199 UISP
= uisp
-dprog
=$S -dserial
=$(SERIAL
) -dpart
=auto
200 # The two lines above are for "uisp" and the AVR910 serial programmer connected
201 # to a Keyspan USB to serial converter to a Mac running Mac OS X.
202 # Choose your favorite programmer and interface.
206 $(UISP
) --upload
--verify if
=main.hex