Update MEGA 2560 bootloader

Hello, I read that there was a bug in the Mega 2560 bootloader that causes it to hang when there are three ! in a row, I have come across this several times.

I found this bootloader, and am guessing this is the new bootloader Arduino-stk500v2-bootloader/stk500boot_v2_mega2560.hex at master · arduino/Arduino-stk500v2-bootloader · GitHub

If it is the new one, how do I go about writing it to my mega 2560?
If it is not, where can I find the new one?

Thanks in advance for any help I recieve

To burn a new bootloader, you need a programmer.
I use Atmel AVR ISP MKii.
If you have another Arduino you can use that:

hmmm... i didnt really want to buy something extra, i will see if i can get hold of my friends uno

I managed to get hold of my friends uno

it was much simpler and more painless than i expected

Shuttleu:
I managed to get hold of my friends uno

it was much simpler and more painless than i expected

Not so painless for many that try on their first attempt, congratulations.

So did this bootloader indeed fix the !!! problem?
I wonder if it also includes the fix to handle WDT resets correctly also?

Lefty

retrolefty:
Not so painless for many that try on their first attempt, congratulations.

So did this bootloader indeed fix the !!! problem?
I wonder if it also includes the fix to handle WDT resets correctly also?

Lefty

Thank you!

i can confirm that it has solved my !!! problem, and how do i check the WDT resets?

EDIT: i tried the sketch from this post

#include <avr/wdt.h>

void setup(void)
{
   Serial.begin(57600);    // start serial port
//  wdt_disable();
  wdt_enable(WDTO_8S);   // set the wdt on 8 sec
}

void loop(void)
{ 
    wdt_reset(); // reset the wdt
Serial.println("delays 5000");
 delay(5000);
 wdt_reset(); // reset the wdt
 Serial.println("delays 7000");
 delay(7000);
  wdt_reset(); // reset the wdt
  Serial.println("delays 10000");
 delay(10000);
   Serial.println("delays 15000");
 delay(15000);
}

and i get...
delays 5000
delays 7000
delays 10000
delays 5000
delays 7000
delays 10000
delays 5000
delays 7000
delays 10000
delays 5000
delays 7000
delays 10000

Apparently something is resetting after this

 Serial.println("delays 10000");
delay(10000);

As this is not occurring

   Serial.println("delays 15000");

CrossRoads:
Apparently something is resetting after this

 Serial.println("delays 10000");

delay(10000);




As this is not occurring


Serial.println("delays 15000");

isnt that what the wdt is supposed to do?

also i have been reading about making sure the fuse sets are correct after i have burned the bootloader

what should i be doing/looking at?

I've not used the WDT, how are you setting the time it needs before it decides a reset is necessary?

If you can download code and it runs as expected, I'd say your fuses were okay. Nothing more to check.

CrossRoads:
I've not used the WDT, how are you setting the time it needs before it decides a reset is necessary?

If you can download code and it runs as expected, I'd say your fuses were okay. Nothing more to check.

well im guessing at

 wdt_enable(WDTO_8S);   // set the wdt on 8 sec

it is set to 8 seconds (during the setup)
so when it gets to

delay(10000);

it waits over 8 seconds then times out and resets

Oh, too easy! I should have looked at posted code a little more :grin:

However the problem with the WDT and some older bootloaders is if the WDT is using some minimum time out value that when the system is reset the bootloader doesn't complete it's thing quick enough before the WDT triggers another reset and you are stuck in a bootloader/WDT tight loop that won't end. A proper bootloader these days resets the WDT interrupt when the bootloader starts, to prevent the WDT from tripping again.

So testing the WDT with a 8 second value won't test out the bootloader for proper WDT handling.

Lefty

how about 15ms?

#include <avr/wdt.h>

void setup(){
  Serial.begin(9600);
  Serial.println("Hello world");
  wdt_enable(WDTO_15MS);
}

void loop(){
  Serial.println("I am going to not get stuck..");
  for(int x=0; x<100; x++) {
    wdt_reset();
    x++;
    delay(10);
  }
  wdt_reset();
  Serial.println("I am going to get stuck now..");
  for(int x=0; 1; x++) {
    delay(10);
  }
}

and i get

Hello world
I am going to not get stuck..
I am going to get stuck now..
Hello world
I am going to not get stuck..
I am going to get stuck now..
Hello world
I am going to not get stuck..
I am going to get stuck now..
Hello world
I am going to not get stuck..
I am going to get stuck now..
Hello world
I am going to not get stuck..
I am going to get stuck now..

Looking good! No bootloader hang up condition.

Lefty

So LOL me. I loaded the WDT test using the 15msec timeout value onto a Uno board and it worked fine. So I decided to see if my old mega1280 board did indeed suffer from the WDT problem so I loaded it and bang it bricked the board with led13 blinking at a very fast rate. Couldn't load anything else via the IDE. So went to Nick's great bootloader writer and it fixed me right up, highly recommended sketch ( Gammon Forum : Electronics : Microprocessors : Atmega bootloader programmer )

Out of curiosity I tried the WDT test again on the mega board hoping that maybe the bootloader code in Nick's sketch handles that bug, but no luck the test bricked the mega1280 board once again. So back to looking around for a updated mega1280 bootloader that handles WDT interrupts properly.

Lefty