Go Down

Topic: Broken Arduino Mega magically repears after uploading bootloader. (Read 1 time) previous topic - next topic

Jantje

All
I can hardly believe what happened today; so I hope someone can help me to explain what has happened.
I have an Arduino sketch which I have been running on an UNO for days without problems. As the final solution uses a MEGA 2560 I switched to the MEGA today.
The system exists out of the MEGA powered via the Jack and connected with serial pin 0 and 1 to the serial port of a router (a hacked linksys WRT54GL). No other connections are made.
All worked fine for several hours but then the mega stopped responding.
I connected the mega to the USB port of my PC. The mega was recognized but the serial communication was dead. I tried several times to upload a sketch without success.
I had bootloaded a new bootloader to the mega with the arduino ISP and Arduino IDE 1.0.2 before. I tried to upload the bootloader again and it failed. I retried a couple of times but gave up.
At that time I was thinking that the serial pins of the mega were broken and I considered the board broken =(.
I did a final try to upload the bootloader with avrdude and a AVR ISP which worked on the first try with this command
Code: [Select]
C:\Users\IBM_ADMIN>D:\arduino-1.0.2\hardware/tools/avr/bin/avrdude -CD:\arduino-1.0.2\hardware/tools/avr/etc/avrdude.conf -v -v -v -v -patmega2560 -cstk500v2 -P\\.\COM11 -e -Ulock:w:0x3F:m -Uefuse:w:0xFD:m -Uhfuse:w:0xD8:m -Ulfuse:w:0xFF:m -F
When I plugged the mega in the USB of my PC and opened a serial monitor I saw Serial messages flooding the monitor. So the Mega was magically repaired and my sketch was still running :smiley-eek:.
So it seems as if the bootloader got corrupted. Once in this stage I can understand the behavior and why the sketch runs after the bootloader has been fixed.
If the bootloader is broken and the mega went in watchdog I can even think of a reason why the Arduino as ISP didn't work. 8)

As I would not like this to happen in the future: I would like to know:
->How can a Arduino -only connected to the serial port- corrupt the mega so bad a bootloader burn is needed?
->What can I do to avoid this in the future?

Any ideas?

Best regards
Jantje

PS I burnt the bootloader available at https://github.com/arduino/Arduino-stk500v2-bootloader/tree/master/goodHexFiles to the MEGA
This bootloader fixes the "!!!" and watch dog timer issues.
Do not PM me a question unless you are prepared to pay for consultancy.
Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -

retrolefty

Quote
As I would not like this to happen in the future: I would like to know:
->How can a Arduino -only connected to the serial port- corrupt the mega so bad a bootloader burn is needed?
->What can I do to avoid this in the future?

Any ideas?


Well the only way I've ever seen my mega1280 get 'bricked' was when testing if it's bootloader was written to handle WDT interrupts correctly or not. I person posted a short sketch that enabled the WDT at a ridiculous rate of 25 msec rate and when loaded on a newer Uno bootloader is handled it correctly disabling the WDT. I loaded the same sketch into my mega1280 board and after it loaded pin 13 went nuts flashing at a 25 msec rate, and the IDE couldn't upload to the board, it was the classic stuck in the bootloader/WDT loop that most older arduino boards of all flavors were vulnerable to. Only reburning the bootloader, which also erases the rest of the flash would recover the board. Not saying that is any way the source of your problem and if pin 13 wasn't flashing it probably wasn't but beware your mega 2560 board does have a old vulneable bootloader.

The serial bootloader is convenient for development from the IDE but once a design is finished and debugged and test and ready to be put into some kind of permanent service, there is a lot to be said for uploading the sketch via the upload using programmer option and taking the whole bootloader out of the application.

Lefty

Jantje

Lefty
Thanks for the input. Led 13 was not flashing. But as I burned a new bootloader to fix the WDT and !!! problems this does not remove this possibility. The WDT was the reason why I started of with the UNO (actually I upgraded my duemilenova's with the UNO bootloader for the WDT problem).
I tested the Mega and it all worked fine. So something must have triggered something breaking the bootloader.
I hadn't considered the bootloader getting into a loop but that is indeed a very viable possibility.
I only use WDT as a safety net in case the "put reset pin HIGH" doesn't work. In that case I use 2 seconds as you can see in the code below.
Code: [Select]
// perform hard reset via reset pin and if fails use the watchdog
void MessageHandler::forceHardReset()
{
  Serial.println(F("triggering restart"));
  unsigned long resetTime =millis()+ (unsigned long) myForceRestartDelay;
  //Serial.flush();
  Serial.end();
  while ( resetTime > millis());
  Serial.println(F("Setting Pin High"));
  pinMode(A5,OUTPUT);
  digitalWrite(A5,HIGH);
  Serial.println(F("Pin is High"));
  delay(5000);  // this should be long enough to reset the arduino
  Serial.println(F("this should never happen; have you connected A5 to reset?"));
  delay(1000); //make sure the serial message gets send.
  // use the watchdog to try to reset
  noInterrupts(); // disable interrupts
  wdt_enable(WDTO_2S);
  interrupts();
  delay(5000);
  Serial.println(F("this should never happen; even the watchdog doesn't work?"));
}

Quote
The serial bootloader is convenient for development from the IDE but once a design is finished and debugged and test and ready to be put into some kind of permanent service, there is a lot to be said for uploading the sketch via the upload using programmer option and taking the whole bootloader out of the application.

I fully agree but.... I'm actually designing this solution to be able to continue my development of my mobile robot. Because the robot is in the garden (and it is very likely to be raining); changing settings or the sketch implies I have to go and get the robot on a "safe spot"; open it up and connect my laptop; close it again and bring the robot back to the testing area.
The setup I'm working on allows me to do all these things remotely with a wifi access point that covers the whole area and a wifi router on the robot. The fact the bootloader allows me to load a new sketch with only a serial port is a great feature for me.
Best regards
Jantje
Do not PM me a question unless you are prepared to pay for consultancy.
Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -

pico


I did a final try to upload the bootloader with avrdude and a AVR ISP which worked on the first try with this command
Code: [Select]
C:\Users\IBM_ADMIN>D:\arduino-1.0.2\hardware/tools/avr/bin/avrdude -CD:\arduino-1.0.2\hardware/tools/avr/etc/avrdude.conf -v -v -v -v -patmega2560 -cstk500v2 -P\\.\COM11 -e -Ulock:w:0x3F:m -Uefuse:w:0xFD:m -Uhfuse:w:0xD8:m -Ulfuse:w:0xFF:m -F


That avrdude command does NOT upload any bootloader, it merely resets fuses. So, if that repaired it, your problem was not a corrupted bootloader, it was corrupted fuse values.

WiFi shields/Yun too expensive? Embeddedcoolness.com is now selling the RFXduino nRF24L01+ <-> TCP/IP Linux gateway: Simpler, more affordable, and even more powerful wireless Internet connectivity for *all* your Arduino projects! (nRF24L01+ shield and dev board kits available too.)

Jantje

Pico
Thanks for pointing this out  :D.
I made this command based on the first command the Arduino IDE (1.0.2) launches when trying to burn the bootloader. The IDE uses -cstk500v1 which fails. After some reading I decide to try -cstk500v2 which worked but gave a error and proposed to add -F. With the -F it worked.

So I thought this uploaded the bootloader; but I had wondered how avrdude found the hex file to upload. Thanks for solving this ridle  :D

I don't know much about fuse bits and surely not about getting and setting them. As I wouldn't know how to set these fuse bits I'm tempted to think it must have been the bootloader who sets them (wrongly). But when I go through the code I only find boot_lock_fuse_bits_get there seems to be no set function  :smiley-eek:

More input is needed to get to the bottom of this.

Best regards
Jantje




Do not PM me a question unless you are prepared to pay for consultancy.
Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -

Go Up