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