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

Go To Last Post
5 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 ~/