by on
Arduino

A few months ago Paul Stoffregon asked to borrow an arduino mega 2560 to look at a bug that he was working around. I had access to several as I was working on a project for a client that was based on the same board. Around the same time I made the mistake of trying to add a watch dog timer to a complicated piece of code that I inherited. The results were disastrous and made me look more closely at both the stripped down opti-boot boot-loader that the arduino team is using and the not so stripped down but still buggy stk500v2 code that is currently on the arduino mega2560 which is there because opti-boot doesn’t handle the larger memory.

I was not so happy.

I am less happy with the fact that two years after issues #181 and a year and a half after #393 were filed you can still buy an arduino mega2560 with these bugs and re-burning the boot-loader will not fix the problem.

Issue #393.

void setup() {
 Serial.begin(9600);
}

void loop() {
 Serial.println("test!!!");
}

The above sketch will not load through the bootloader.

#include <avr/wdt.h>

print "Hello world\n";
wdt_enable(WDTO_15MS);

print "I am going to not get stuck..\n";
for(x=0; x<100; x++) {
  wdt_reset();
  x++;
  delay(10);
}
print "I am going to get stuck now..\n";
for(x=0; 1; x++) {
  delay(10);
}

The above sketch will hang the board until you power down or re-burn the boot-loader, setting the WDT to 15ms and waiting is a common practice for getting a clean software reset. But more importantly the WDT is an vital tool to make sure that systems don’t get stuck for long periods when things go wrong (and they do).

Fortunately some people aren’t waiting and there is source code for the bootloader that has these issues resolved is here.

https://github.com/msproul/Arduino-stk500v2-bootloader

and a hex file for the bootloader is at the bottom of the issue #181 if this direct link doesn’t work.

 

Leave a Reply

  • (will not be published)