Go Down

Topic: Update MEGA 2560 bootloader (Read 2070 times) previous topic - next topic

Shuttleu

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 https://github.com/arduino/Arduino-stk500v2-bootloader/blob/master/goodHexFiles/stk500boot_v2_mega2560.hex

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

CrossRoads

To burn a new bootloader, you need a programmer.
I use Atmel AVR ISP MKii.
If you have another Arduino you can use that:
http://www.gammon.com.au/forum/?id=11635
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Shuttleu

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

Shuttleu

I managed to get hold of my friends uno

it was much simpler and more painless than i expected

retrolefty


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

Shuttleu

#5
Dec 28, 2012, 10:05 pm Last Edit: Dec 28, 2012, 10:18 pm by Shuttleu Reason: 1


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
http://arduino.cc/forum/index.php/topic,45381.msg329036.html#msg329036
Code: [Select]
#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

CrossRoads

Apparently something is resetting after this
Code: [Select]

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


As this is not occurring
Code: [Select]

   Serial.println("delays 15000");
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Shuttleu


Apparently something is resetting after this
Code: [Select]

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


As this is not occurring
Code: [Select]

   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?

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.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Shuttleu


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
Code: [Select]
wdt_enable(WDTO_8S);   // set the wdt on 8 sec
it is set to 8 seconds (during the setup)
so when it gets to
Code: [Select]
delay(10000);
it waits over 8 seconds then times out and resets

CrossRoads

Oh, too easy! I should have looked at posted code a little more  :smiley-mr-green:
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

retrolefty

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

Shuttleu

how about 15ms?
Code: [Select]
#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..

retrolefty

Looking good! No bootloader hang up condition.

Lefty

retrolefty

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 ( http://www.gammon.com.au/forum/?id=11635 )

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

Go Up