3 # 20061119 Thomas Fischl original
4 # 20061120 Hanns-Konrad Unger help: and TARGET=atmega48 added
5 # 20140308 Peter Henn TARGET=atmega328 added
8 # TARGET=atmega8 HFUSE=0xc9 LFUSE=0xef
9 # TARGET=atmega48 HFUSE=0xdd LFUSE=0xff
10 # TARGET=atmega328 HFUSE=0xd9 LFUSE=0xef EFUSE=0x05
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
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}"
39 @echo
" EFUSE=${EFUSE}"
41 @echo
" CLOCK=12000000"
45 COMPILE
= avr-gcc
-Wall
-O2
-Iusbdrv
-I.
-mmcu
=$(TARGET
) # -DDEBUG_LEVEL=2
47 OBJECTS
= usbdrv
/usbdrv.o usbdrv
/usbdrvasm.o usbdrv
/oddebug.o isp.o clock.o tpi.o main.o
50 $(COMPILE
) -c
$< -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.
61 $(COMPILE
) -S
$< -o
$@
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
68 $(COMPILE
) -o main.bin
$(OBJECTS
) -Wl
,-Map
,main.map
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.
78 avr-objdump
-d main.bin
84 avrdude
-c
${ISP} -p
${TARGET} -P
${PORT} -U flash
:w
:main.hex
88 avrdude
-c
${ISP} -p
${TARGET} -P
${PORT} -u
-U hfuse
:w
:$(HFUSE
):m
-U lfuse
:w
:$(LFUSE
):m
-U efuse
:w
:$(EFUSE
):m
90 avrdude
-c
${ISP} -p
${TARGET} -P
${PORT} -u
-U hfuse
:w
:$(HFUSE
):m
-U lfuse
:w
:$(LFUSE
):m
94 avrdude
-c
${ISP} -p
${TARGET} -P
${PORT} -v
97 # Fuse setting, see http://www.engbedded.com/fusecalc
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
111 # | | | +------- CKSEL 3..0 (external >8M crystal)
112 # | | +--------------- SUT 1..0 (crystal osc, BOD enabled)
113 # | +------------------ BODEN (BrownOut Detector enabled)
114 # +-------------------- BODLEVEL (2.7V)
116 # Fuse atmega48 high byte hfuse:
117 # 0xdf = 1 1 0 1 1 1 1 1 factory setting
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
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
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
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
158 # | +------ BODLEVEL (Brown out disabled)
159 # +-------------- not used
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
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.
172 $(UISP
) --upload
--verify if
=main.hex