0

Did I kill it?
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Did I kill it?

by maxwell_henderson on Tue Apr 29, 2008 2:36 pm

So I've got a class that has a board w/ an ATMega128 on it, and the makefiles we've been using have 'make install' setup to download code to the board.

I'm not using this makefile at home, but I spaced out and did 'make install' instead of 'make flash' a few minutes ago.

Now avrdude doesn't see my atmega48. I just get back:
avrdude: initialization failed, rc=-1
Double check connections and try again, or use -F to override
this check.

So I'm a total noob with respect to embedded development, but from what I understand my 'make install' command changed the fuses and now it's in a state where I can't use ISP to flash code onto the chip.

Can I force avrdude to undo this or did I brick the thing? (I'm using usbtinyisp btw)

Thanks :)
maxwell_henderson
 
Posts: 3
Joined: Tue Apr 29, 2008 2:26 pm

by darus67 on Tue Apr 29, 2008 3:54 pm

Can you post the contents of your makefile here?

That way we can see what it did, for sure.
"He's just this guy. You know?"
darus67
 
Posts: 246
Joined: Wed Sep 26, 2007 10:25 pm
Location: Minnesota, USA

by maxwell_henderson on Tue Apr 29, 2008 4:32 pm

Code: Select all | TOGGLE FULL SIZE
# Name: Makefile
# Author: <insert your name here>
# Copyright: <insert your copyright message here>
# License: <insert your license reference here>

# This is a prototype Makefile. Modify it according to your needs.
# You should at least check the settings for
# DEVICE ....... The AVR device you compile for
# CLOCK ........ Target AVR clock rate in Hertz
# OBJECTS ...... The object files created from your source files. This list is
#                usually the same as the list of source files with suffix ".o".
# PROGRAMMER ... Options to avrdude which define the hardware you use for
#                uploading to the AVR and the interface where this hardware
#                is connected.
# FUSES ........ Parameters for avrdude to flash the fuses appropriately.
DEVICE     = atmega48
CLOCK      = 20000000
PROGRAMMER = -c usbtiny -P avrdoper
OBJECTS    = main.o TWI_Master.o lcd.o
FUSES      = -U hfuse:w:0xd9:m -U lfuse:w:0x24:m
# ATMega8 fuse bits (fuse bits for other devices are different!):
# Example for 8 MHz internal oscillator
# Fuse high byte:
# 0xd9 = 1 1 0 1   1 0 0 1 <-- BOOTRST (boot reset vector at 0x0000)
#        ^ ^ ^ ^   ^ ^ ^------ BOOTSZ0
#        | | | |   | +-------- BOOTSZ1
#        | | | |   +---------- EESAVE (set to 0 to preserve EEPROM over chip erase)
#        | | | +-------------- CKOPT (clock option, depends on oscillator type)
#        | | +---------------- SPIEN (if set to 1, serial programming is disabled)
#        | +------------------ WDTON (if set to 0, watchdog is always on)
#        +-------------------- RSTDISBL (if set to 0, RESET pin is disabled)
# Fuse low byte:
# 0x24 = 0 0 1 0   0 1 0 0
#        ^ ^ \ /   \--+--/
#        | |  |       +------- CKSEL 3..0 (8M internal RC)
#        | |  +--------------- SUT 1..0 (slowly rising power)
#        | +------------------ BODEN (if 0, brown-out detector is enabled)
#        +-------------------- BODLEVEL (if 0: 4V, if 1: 2.7V)

# Example for 12 MHz external crystal:
# Fuse high byte:
# 0xc9 = 1 1 0 0   1 0 0 1 <-- BOOTRST (boot reset vector at 0x0000)
#        ^ ^ ^ ^   ^ ^ ^------ BOOTSZ0
#        | | | |   | +-------- BOOTSZ1
#        | | | |   +---------- EESAVE (set to 0 to preserve EEPROM over chip erase)
#        | | | +-------------- CKOPT (clock option, depends on oscillator type)
#        | | +---------------- SPIEN (if set to 1, serial programming is disabled)
#        | +------------------ WDTON (if set to 0, watchdog is always on)
#        +-------------------- RSTDISBL (if set to 0, RESET pin is disabled)
# Fuse low byte:
# 0x9f = 1 0 0 1   1 1 1 1
#        ^ ^ \ /   \--+--/
#        | |  |       +------- CKSEL 3..0 (external >8M crystal)
#        | |  +--------------- SUT 1..0 (crystal osc, BOD enabled)
#        | +------------------ BODEN (if 0, brown-out detector is enabled)
#        +-------------------- BODLEVEL (if 0: 4V, if 1: 2.7V)


# Tune the lines below only if you know what you are doing:

AVRDUDE = avrdude $(PROGRAMMER) -p $(DEVICE)
COMPILE = avr-gcc -Wall -Os -DF_CPU=$(CLOCK) -mmcu=$(DEVICE)

# symbolic targets:
all:   main.hex

.c.o:
   $(COMPILE) -c $< -o $@
   
# How to compile a .cc file into a .o file
.cpp.o:
   $(COMPILE) -c -g $< -o $@
#   $(COMPILE) -c -g  $< -o $@

.S.o:
   $(COMPILE) -x assembler-with-cpp -c $< -o $@
# "-x assembler-with-cpp" should not be necessary since this is the default
# file type for the .S (with capital S) extension. However, upper case
# characters are not always preserved on Windows. To ensure WinAVR
# compatibility define the file type manually.

.c.s:
   $(COMPILE) -S $< -o $@

flash:   all
   $(AVRDUDE) -U flash:w:main.hex:i

fuse:
   $(AVRDUDE) $(FUSES)

# Xcode uses the Makefile targets "", "clean" and "install"
install: flash fuse

# if you use a bootloader, change the command below appropriately:
load: all
   bootloadHID main.hex

clean:
   rm -f main.hex main.elf $(OBJECTS)

# file targets:
main.elf: $(OBJECTS)
   $(COMPILE) -o main.elf $(OBJECTS)

main.hex: main.elf
   rm -f main.hex
   avr-objcopy -j .text -j .data -O ihex main.elf main.hex
# If you have an EEPROM section, you must also create a hex file for the
# EEPROM and add it to the "flash" target.

# Targets for code debugging and analysis:
disasm:   main.elf
   avr-objdump -d main.elf

cpp:
   $(COMPILE) -E main.c


The FUSE setting in the make file should probably be:
Code: Select all | TOGGLE FULL SIZE
FUSES      = -U hfuse:w:0xdf:m -U lfuse:w:0xff:m


And maybe can I run:

avrdude -c usbtiny -P usb -p atmega48 -U hfuse:w:0xdf:m -U lfuse:w:0xff:m -F
maxwell_henderson
 
Posts: 3
Joined: Tue Apr 29, 2008 2:26 pm

by darus67 on Tue Apr 29, 2008 5:12 pm

If I'm interpreting the fuse bits correctly, I believe you have set the chip
to use an external low frequency crystal.

If your board doesn't have the appropriate crystal, the serial programmer
won't work.

The good news is that the serial programming fuse is still enabled.
Its when you disable serial programming that you're really hosed.

I used the fuse bit calculator found here: http://palmavr.sourceforge.net/cgi-bin/fc.cgi
to interpret the fuse bits.
"He's just this guy. You know?"
darus67
 
Posts: 246
Joined: Wed Sep 26, 2007 10:25 pm
Location: Minnesota, USA

by maxwell_henderson on Tue Apr 29, 2008 6:58 pm

Well I had a 12 MHz crystal laying around so I wired it up but I'm still unable to change the fuse... maybe I need something slower like 1MHz?


Code: Select all | TOGGLE FULL SIZE
$ avrdude -c usbtiny -P usb -p atmega48 -U hfuse:w:0xdf:m -F

avrdude: initialization failed, rc=-1
avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.01s

avrdude: Device signature = 0x000000
avrdude: Yikes!  Invalid device signature.
avrdude: Expected signature for ATMEGA48 is 1E 92 05
avrdude: reading input file "0xdf"
avrdude: writing hfuse (1 bytes):

Writing |                                                    | 0% 0.00s ***failed; 
Writing | ################################################## | 100% 0.05s

avrdude: 1 bytes of hfuse written
avrdude: verifying hfuse memory against 0xdf:
avrdude: load data hfuse data from input file 0xdf:
avrdude: input file 0xdf contains 1 bytes
avrdude: reading on-chip hfuse data:

Reading | ################################################## | 100% 0.00s

avrdude: verifying ...
avrdude: verification error, first mismatch at byte 0x0000
         0xdf != 0x00
avrdude: verification error; content mismatch

avrdude: safemode: hfuse changed! Was df, and is now 0
Would you like this fuse to be changed back? [y/n]
maxwell_henderson
 
Posts: 3
Joined: Tue Apr 29, 2008 2:26 pm

by darus67 on Wed Apr 30, 2008 10:41 am

I would guess you need something slower.
The data sheet should have more info about what they mean by
"low frequency"
"He's just this guy. You know?"
darus67
 
Posts: 246
Joined: Wed Sep 26, 2007 10:25 pm
Location: Minnesota, USA

by mattkenny on Thu May 01, 2008 12:25 am

The low frequency crystal setting usually requires a 32.768 kHz crystal (also known as a watch crystal).
mattkenny
 
Posts: 7
Joined: Thu May 01, 2008 12:23 am

Please be positive and constructive with your questions and comments.