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