ArduinoMega with AVRStudio using bootloader

Hi there,

I just bought an ArduinoMega and am keen to start programming it. However, I was wondering if it is possible to use AVR Studio with the ArduinoMega's bootloader to program it. If it is, will the bootloader not be overwritten when it is programmed or would that require intentional fiddling with the fuse settings?

Is the bootloader's flash area protected by default? I am asking because right now I don't have a programmer that I could use to reprogram the ATmega1280 on that board. Apparently the one I have doesn't support that chip. I have a mySmartUSB MK2. Thanks in advance!

Regards, Xander

Quick look into my AVRstudio isn't showing any options to connect through the FTDI chip to program.

You would have to pickup an ISP programmer that supports that chip, and that AVRStudio supports as far as I can tell.

Having said that, you can wire the FTDI to bit bang program the Atmel, and use AVRDude directly outside of AVRStudio using the .HEX you compiled from within.

Ah that is a shame. I was in the understanding that the bootloader pretends to be an STK500. Thanks for checking anyway!

Regards, Xander

Retried, choosing STK500 - no go.

If someone else knows something else to do to make it work, I would also be interested.

I found this http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1245683439

The bootloader is compatible with AVRDUDE so you can just take the HEX file you get with AVR Studio and pass it to AVRDUDE.

No special Makefile required.

but doesn't AVRDUDE need to be told what kind of programmer it is chatting with?

Regards, Xander

Using AVRDUDE I get the following error: C:\WinAVR-20090313\utils\bin>avrdude -c stk500 -P com3 -v -v -pm1280

avrdude: Version 5.6, compiled on Mar 5 2009 at 09:59:30 Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/

System wide configuration file is "C:\WinAVR-20090313\bin\avrdude.conf"

Using Port : com3 Using Programmer : stk500 avrdude: stk500_getsync(): not in sync: resp=0x00

I am not sure how to go from here.

Regards, Xander

Made some progress. avrdude can now chat with the ArduinoMega:

c:\arduino-0016\hardware\tools\avr\bin>c:\arduino-0016\hardware\tools\avr\bin\av rdude.exe -F -c stk500 -P com3 -v -v -pm1280 -D -D -V -C ..\etc\avrdude.conf -b 57600

avrdude.exe: Version 5.4-arduino, compiled on Oct 11 2007 at 19:12:32 Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/

System wide configuration file is "..\etc\avrdude.conf"

Using Port : com3 Using Programmer : stk500 Overriding Baud Rate : 57600 avrdude.exe: successfully opened stk500v1 device -- please use -c stk500v1 AVR Part : ATMEGA1280 Chip Erase delay : 9000 us PAGEL : PD7 BS2 : PA0 RESET disposition : dedicated RETRY pulse : SCK serial program mode : yes parallel program mode : yes Timeout : 200 StabDelay : 100 CmdexeDelay : 25 SyncLoops : 32 ByteDelay : 0 PollIndex : 3 PollValue : 0x53 Memory Detail :

Block Poll Page Polled Memory Type Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack



eeprom 65 10 8 0 no 4096 8 0 9000 9000 0x00 0x00 flash 65 10 256 0 yes 131072 256 512 4500 4500 0x00 0x00 lfuse 0 0 0 0 no 1 0 0 9000 9000 0x00 0x00 hfuse 0 0 0 0 no 1 0 0 9000 9000 0x00 0x00 efuse 0 0 0 0 no 1 0 0 9000 9000 0x00 0x00 lock 0 0 0 0 no 1 0 0 9000 9000 0x00 0x00 calibration 0 0 0 0 no 1 0 0 0 0 0x00 0x00 signature 0 0 0 0 no 3 0 0 0 0 0x00 0x00

Programmer Type : STK500 Description : Atmel STK500 Hardware Version: 2 Firmware Version: 1.16 Vtarget : 0.0 V Varef : 0.0 V Oscillator : Off SCK period : 0.1 us

avrdude.exe: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.02s

avrdude.exe: Device signature = 0x1e9703 avrdude.exe: safemode: lfuse reads as 0 avrdude.exe: safemode: hfuse reads as 0 avrdude.exe: safemode: efuse reads as 0

avrdude.exe: safemode: lfuse reads as 0 avrdude.exe: safemode: hfuse reads as 0 avrdude.exe: safemode: efuse reads as 0 avrdude.exe: safemode: Fuses OK

avrdude.exe done. Thank you.

However, is there a risk of nuking the bootloader if I program it this way or is it protected?

Regards, Xander

The bootloader should be protected. AVRDude is how the IDE programs it anyways, so you SHOULD be okay.

As long as you don't change the fuse settings, you're quite safe.

Thanks for the info. I'll stay away from the fuses then :)

Try this ;)

avrdude -p m168 -P /dev/ttyUSB0 -c stk500v1 -b 19200 -F -u -U flash:w:blink.hex

Don't need to mention what to change ::)

I’ve had it working for a few days now, thanks, though :slight_smile: This is what I have in my Makefile:

#---------------- Programming Options (avrdude) ----------------

# Programming hardware
# Type: avrdude -c ?
# to get a full listing.
#
AVRDUDE_PROGRAMMER = stk500v1

# com1 = serial port. Use lpt1 to connect to parallel port.
AVRDUDE_PORT = com3
AVRDUDE_PORT_SPEED = 57600

AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep


# Uncomment the following if you want avrdude's erase cycle counter.
# Note that this counter needs to be initialized first using -Yn,
# see avrdude manual.
#AVRDUDE_ERASE_COUNTER = -y

# Uncomment the following if you do /not/ wish a verification to be
# performed after programming the device.
AVRDUDE_NO_VERIFY = -V

# Increase verbosity level.  Please use this when submitting bug
# reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude> 
# to submit bug reports.
AVRDUDE_VERBOSE = -v -v

AVRDUDE_NO_AUTOERASE_FLASH = -D

AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -b $(AVRDUDE_PORT_SPEED) -c $(AVRDUDE_PROGRAMMER)
AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
AVRDUDE_FLAGS += $(AVRDUDE_NO_AUTOERASE_FLASH)

A little further down the Makefile I have a target called “program”:

# Program the device.  
program: $(TARGET).hex $(TARGET).eep
      $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)

I’ve been programming the Arduino without weird side effects for about 2 days now using the bootloader.

Regards,
Xander