# Makefile for usbasp
# 20061119 Thomas Fischl original
# 20061120 Hanns-Konrad Unger help: and TARGET=atmega48 added
+# 20140308 Peter Henn TARGET=atmega328 added
#
# TARGET=atmega8 HFUSE=0xc9 LFUSE=0xef
# TARGET=atmega48 HFUSE=0xdd LFUSE=0xff
+# TARGET=atmega328 HFUSE=0xd9 LFUSE=0xef EFUSE=0x05
# TARGET=at90s2313
-TARGET=atmega8
-HFUSE=0xc9
+TARGET=atmega328p
+HFUSE=0xd9
LFUSE=0xef
-
+EFUSE=0x05
# ISP=bsd PORT=/dev/parport0
# ISP=ponyser PORT=/dev/ttyS1
@echo " TARGET=${TARGET}"
@echo " LFUSE=${LFUSE}"
@echo " HFUSE=${HFUSE}"
+ifdef EFUSE
+ @echo " EFUSE=${EFUSE}"
+endif
@echo " CLOCK=12000000"
@echo " ISP=${ISP}"
@echo " PORT=${PORT}"
avrdude -c ${ISP} -p ${TARGET} -P ${PORT} -U flash:w:main.hex
fuses:
+ifdef EFUSE
+ avrdude -c ${ISP} -p ${TARGET} -P ${PORT} -u -U hfuse:w:$(HFUSE):m -U lfuse:w:$(LFUSE):m -U efuse:w:$(EFUSE):m
+else
avrdude -c ${ISP} -p ${TARGET} -P ${PORT} -u -U hfuse:w:$(HFUSE):m -U lfuse:w:$(LFUSE):m
+endif
avrdude:
avrdude -c ${ISP} -p ${TARGET} -P ${PORT} -v
+
+# Fuse setting, see http://www.engbedded.com/fusecalc
+#
# Fuse atmega8 high byte HFUSE:
# 0xc9 = 1 1 0 0 1 0 0 1 <-- BOOTRST (boot reset vector at 0x0000)
# ^ ^ ^ ^ ^ ^ ^------ BOOTSZ0
# 0xdc = divide/1,no clock output,fast raising power,low Pw Oszil. 3..8 Mhz
# 0xe0 = divide/1,no clock output,fast raising power,external Oszil.
# 0xff = divide/1,no clock output,slow raising power,low Pw Oszil 8.. Mhz
-
+#
+# Fuse atmega328p high byte hfuse:
+# 0xd9 = 1 1 0 1 1 0 0 1 <-- BOOTRST (boot reset vector at 0x0000)
+# ^ ^ ^ ^ ^ ^ ^------ BOOTSZ0
+# | | | | | +-------- BOOTSZ1
+# | | | | + --------- EESAVE (don't preserve EEPROM over chip erase)
+# | | | +-------------- WDTON (WDT not always on)
+# | | +---------------- SPIEN (allow serial programming)
+# | +------------------ DWEN (debug wire is disabled)
+# +-------------------- RSTDISBL (reset pin is enabled)
+# 0xd9 = ext.reset, no DW, SPI, no watchdog, no save eeprom, reset vector 0x0000
+# Fuse atmega328p low byte lfuse:
+# 0x6d = 0 1 1 0 0 0 1 0 factory setting
+# ^ ^ \ / \--+--/
+# | | | +------- CKSEL 3..0 (internal 8Mhz Oszillator)
+# | | +--------------- SUT 1..0 (start-up time)
+# | +------------------ CKOUT (no clock output)
+# +-------------------- CKDIV8 (divide clock by 8)
+# 0xef = divide/1,no clock output,fast raising power,low Pw Oszil 8.. Mhz
+# Fuse atmega328p extended byte efuse:
+# 0xff = 1 1 1 1 1 1 1 1 factory setting
+# \-+-+-+---/ \-+-/
+# | +------ BODLEVEL (Brown out disabled)
+# +-------------- not used
+# 0xfd = BOD 2,7V
+# Note: avrdude masks not used fuse bits to zero. Therefore use only
+# the lower three bits to define the BOD level, here 0x05
SERIAL = `echo /dev/tty.USA19QI*`
UISP = uisp -dprog=$S -dserial=$(SERIAL) -dpart=auto