HOWTO: reflash bootloader to Mega2560 w/JTAGice mkII and Atmel Studio

Go To Last Post
6 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

(note: this post has been completely rewritten from the original version; it started out as a problem description, but I eventually found the answer, decided to post it here for others to find in the future, and rewrote this post to make it less confusing to people finding it via Google. Replies to it posted prior to 6/17/2018 were based on the post's original content.)

 

Symptoms:

 

  • Mega2560 or Mega2560 ADK... probably a few years old... that worked normally for a few hours/days/weeks/months/years, then suddenly began to malfunction.
  • The USB serial port appears to be functioning in Windows Device Manager, but Arduino IDE is unable to upload to it, and Serial Monitor launches & shows nothing.

 

Prerequisites:

  • Atmel Studio 7
  • JTAGice mkII
  • Arduino SDK (usually, installed automatically when Arduino IDE gets installed)

 

Assumptions:

  • You understand the basics of ISP programming & using Atmel Studio, but don't necessarily know how to apply that knowledge to solving the specific problem of, "How do I reflash the bootloader on an Arduino Mega2560 board using Atmel Studio and a JTAGice mk2, as opposed to doing it via the official Arduino IDE and some other programmer?"

 

Steps:

 

1. Connect the JTAGice mkII to the Mega2560. You'll need the JTAGice mkII's adapter to convert its 2x5 IDC to a 2x3 IDC. It connects to the 2x3 header near the board's center marked "ICSP", with the ribbon cable leading into the JTAGice mk2 pointing towards the rear of the Mega2560 board (where the USB port(s) and DC power jack are located). If the ribbon cable is blocking your finger's access to the reset button, you probably connected it backwards.

 

Some boards might have a second 2x3 connector located near the USB port... that's NOT the one to use for reflashing the bootloader.

 

2. Launch Atmel Studio 7.

 

3. Tools -> Device Programming

 

4. Select "JTAGICE mkII" from the "Tool" dropdown, select "ATmega2560" from the "Device" dropdown, and "ISP" from the "Interface" dropdown, then click "Apply"

 

5. Continue rightward to "Device Signature". Click "Read". If you get an error, stop. You need to resolve it first. Otherwise, you'll get a hexadecimal number (mine says "0x1E9801"). Target Voltage should read something in the vicinity of 5.0-5.1v.

 

6. Navigate to "Memories". Click the "..." after the field for "Flash (256kb)", and find the bootloader for your board. As of June 2018, the correct bootloader for a Mega2560 or Mega2560 ADK board is named "stk500boot_v2_mega2560.hex". It's probably located in your "Arduino SDK" directory, under ./hardware/arduino/avr/bootloaders/stk500v2/.

 

Warning: there's probably ALSO a file in this directory named "Mega2560-prod-firmware-2011-06-29.hex". More likely than not, that's the firmware that got you in trouble to begin with. Apparently, it has a bug involving the watchdog timer that causes it to bootloop when certain things go wrong in an unfortunate sequence. Don't use it.

 

To flash stk500boot_v2_mega2560.hex after selecting the file, click "Program" (make sure "Erase device before programming" and "Verify flash after programming" are checked. Leave "Set programming address" (under "Advanced") un-checked.

 

Now, go to "Fuses". Be very, very careful what you click on this pane... one really unfortunate wrong click in the wrong place on this pane could brick your board. Confirm (and select, if necessary) the following values:

  • Brown-out detection at VCC=2.7v
  • HIGH.SPIEN (checked)
  • HIGH.BOOTSZ: Boot Flash size = 4096 words start address $1F000
  • HIGH.BOOTRST (checked)
  • LOW.CKDIV8 (UN-checked)
  • LOW.SUT_CKSEL: Ext. Crystal Osc. 8.0- MHz; Start-up time : 16k CK + 65ms

 

Other fuses should probably be un-checked:

 

  • LOW.CKDIV8: if this were checked, your board would run at 1/8 the crystal frequency. You probably don't want to do this, because quite a few Arduino libraries make assumptions about the board's clock speed based on the board's defaults.
  • LOW.CKOUT: if this were checked, your board would output one pulse per clock cycle on one of the pins (I forgot which one). It's not harmful if you aren't using that pin, but will drive you nuts for hours trying to track down the source of the problem if the fuse is set & you try using that pin for something (been there, done it, bought the T-shirt).
  • HIGH.JTAGEN: same situation as LOW.CKOUT, but involves 4 pins instead of 1. Also been there, done it, and bought the T-shirt.

 

After setting the correct fuse values, click "Program".

 

That's it! Once you've reflashed the bootloader & set the fuses, your Mega2560 should work just fine, and the problem theoretically shouldn't happen again.

This topic has a solution.

There's no place like ~/

Last Edited: Sun. Jun 17, 2018 - 07:00 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well, it looks like I'm definitely not the first person to bork the Mega2560's bootloader -- http://forum.arduino.cc/index.ph...

 

It looks like the bootloaders are in ${arduino-home}/Arduino/hardware/arduino/avr/bootloaders/stk500v2/  stk500boot_v2_mega2560.hex and Mega2560-prod-firmware-2011-06-29.hex

 

According to that post, the 2011-06-29 one is the original, buggy one that apparently causes what happened to me.

 

Before I pull the trigger, though...

 

  1. Does the "Mega2560 ADK" use the same bootloader as the "regular" Mega2560?
  2. Do I just need to connect my JTAGice mkII to the 3x2 ICSP header, launch Atmel Studio, go to Tools->Device Programming, select the JTAGice mkII, read the serial to confirm it's working, go to "Memories", and write "stk500boot_v2_mega2560.hex"? Or are there additional (not necessarily obvious) things I have to do first?

There's no place like ~/

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I always recommend using the Arduino IDE to Burn the Bootloader. It handles Flash, fuses and lock bits.
I would hope that your third party mega1284 core will have the correct entries in boards.txt

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Actually, THIS post is about my (currently-dysfunctional) Mega2560 ADK. The other thread about the mega1284 is about my subsequent attempt to find an immediately-available alternative to the Mega2560 since it was too late to buy a new Mega2560 and have it arrive before the weekend. Whenever I run into a brick wall with one approach, my first reaction is usually to hedge my bets and find a different brick wall to run into instead ;-)

There's no place like ~/

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Note: the replies above were posted before I solved the problem and rewrote the opening post to clarify it for people finding it for the first time in the future via Google.

There's no place like ~/

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

"5. Continue rightward to "Device Signature". Click "Read". If you get an error, stop. You need to resolve it first. "

 

I have been trying to resolve this error I'm experiencing with a compatible Mega2560 R3, no Device signature being read.

 

I have two Mega2560 R3 and two Uno R3, one Original and one compatible board each.

With the Uno I was able to reprogram the bootloader with the Pololu Programmer and Atmel Studio 7, I used the Arduino IDE bootloader for the Uno.

I had a worked on the Mega2560 R3 a while back and was under the impression it was still working fine, i.e. uploading sketches in Arduino 1.8.12 (Windows 7)

To my surprise I found the Original Mega now suddenly not uploading, but after being able to sort out my Uno bootloader I thought I could sort out the Original and compatible Mega2560 R3 using similar procedure.

 

So this is similar to what you described, with a Pololu USBAVR 2.1 Programmer used with Atmel Studio 7.

Device Programming, Tool: STK500, Device: ATmega2560, Interface: ISP. Apply and Read Device signature.

With both Uno device signatures were read as expected, the Original Mega2560 also read the signature but the compatible Mega did not read the Signature.

Fuses and Lockbits compared between the two Mega, no difference there.

 

I've been suspecting the Y1 oscillator for the Main Chip on the compatible Mega, but one thing I have been unable to confirm yet is how the serial number of Mega can be detected using the Arduino IDE Get board info under tools if the Y1 oscillator would be malfunctioning, then I think I found confirmation that Y1 oscillator must be working from this link

https://github.com/ricaun/Arduin...

If the serial number can be read, I presume the bytes must be read, but as to why the Signature bytes are not being read??? That is the question I would love to understand.

Ive got lots of screenshots and I have been working with AVRDUDESS to familiarise myself with the ARVDUDE commands, AVRDUDESS also does not read the signature, so doubt AVRDUDE will be able to.

 

How is the serial number read using Arduino Get board info?

If this serial number of a device is read, then how is it that the Signature is not read?

Colin Canham
Instrumentation & Automation. Trade Mechanician - Technician - Industrial System Integration solutions for Steel, Platinum, Gold, Diamond, Sugar and Oil & Gas Offshore Exploration sectors.
Embedded Microcontroller systems - new hobby.
MPLAB Snap Programmer for Atmel and Microchip (PG164100), Pololu USB AVR Programmer V2.1 (3172),
Atmel ATtiny85V DIP (ATTINY85-20PU) , Arduino Uno R3 (Compatible) and Arduino Mega2560 R3 Compatible.