Go Down

Topic: Bootloader installation problems - mega2560 - ARVISP mkII (Read 581 times) previous topic - next topic

Len Morgan

I have an AVRISP mkII and I'm trying to program the Optiboot loader into it (I HAVE to have a working Watchdog Timer).  I've read that it's supposedly already installed on R3 Megas but it isn't.

The optiboot compiles correctly and I get hex files.  When I try to make the mega1280 (since Optiboot doesn't seem to have a 2560 target), I get fuse programming errors and it stops.  If I use Arduino-1.0 to upload a bootloader and select the AVRISP mkII, it works just fine, but I haven't recompiled that code so it's the hex file that comes with the IDE.

I have the following questions:

1) What do I have to do to put the Optiboot loader onto this chip (so I can use the WDT)?
2) Is a version of Optiboot available that will work with a Mega2560 or will I have to give up 1/2 of my Flash memory to get a Watchdog timer (seems like a high price to pay but I need it more than the extra Flash right now)?

Thank you in advance,

len morgan

johnwasser

The Mega has too much memory to run a bootloader that speaks STK500V1.  You need an STK500V2 bootloader.

How long a WDT interval do you need?  As long as the bootloader gives control to setup() before the WDT times out again you should not have a problem with the bootloader.

Have you tried the WDT with the standard bootloader?

Here is a WDT test sketch.  It blinks slower and slower until the toggle delay grows beyond the WDT limit. At that point the WDT times out and resets the system.
Code: [Select]

#include <avr/wdt.h>

unsigned long ToggleDelay;

const int LEDpin = 13;

void toggle_led()
{
  digitalWrite(LEDpin, !digitalRead(LEDpin));
}

void setup()
{
  wdt_disable();
  ToggleDelay = 1;
  pinMode(LEDpin, OUTPUT);
  wdt_enable(WDTO_250MS);  // Set watchdog to 1/4 second
}

void loop()
{
  wdt_reset();
  toggle_led();
  delay(ToggleDelay);
  ToggleDelay += 5;
}
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Len Morgan

Thanks for the reply and test code!

I'm looking for the max (about 8 seconds).  It's not critical that I reset that quickly but it IS important that it doesn't lock up and require a 100 mile drive to push the reset button.

I tried whatever comes loaded on the R3 Arduinos (any idea what that is?) and it timed out properly but never came back after the timeout.  I have read that this is the main problem with the Arduino and the watchdog circuit.  It seems that on reset (by the WDT) the timeout is changed to 15mS and enabled so the bootloader never gets a chance to make it to my setup() code before retriggering.  That appeared to be what was happening to me.

On a related matter, the Arduino IDE ships with several bootloaders (STK500V?, Optiboot, etc).  How do you tell it which one to use or does it pick based on the particular microprocessor you have selected under "Tools->Board"?

I'll try your code in the morning and see what happens.  Is there anyway to find out which bootloader is programmed in the chip?

Thanks,

len morgan

johnwasser

> I tried whatever comes loaded on the R3 Arduinos (any idea what that is?) and it timed out properly but never came back after the timeout. 

The test code works fine for me on my Arduino UNO R2. :(


> I have read that this is the main problem with the Arduino and the watchdog circuit.  It seems
> that on reset (by the WDT) the timeout is changed to 15mS and enabled so the bootloader never
> gets a chance to make it to my setup() code before retriggering.  That appeared to be what was
> happening to me.

I had read that the WDT doesn't get disabled after a timeout and that if the bootloader took too long you could get into a WDT loop but I had not read that the WDT interval gets reset to 15ms.  I just burned the Arduino 1.0 UNO bootloader into my UNO R2 and the WDT test sketch still works fine.


> On a related matter, the Arduino IDE ships with several bootloaders (STK500V?, Optiboot, etc). 
> How do you tell it which one to use or does it pick based on the particular microprocessor
> you have selected under "Tools->Board"?

Yes.  The 'boards.txt' files have a pointer to the bootloader for each type of board.  You can put your own 'boards.txt' file in the 'hardware' folder inside your sketch folder and the IDE will pick that up next time you start it.


> Is there anyway to find out which bootloader is programmed in the chip?

Not really.  The only way I know of to be sure is to burn a fresh bootloader.
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Len Morgan

There is no joy in Mudville today.  I tried your code (but upped the timeout to 4 seconds so I could recover) and modified it to put in a print out of the current delay each time it's changed.  It counted up just fine (to 4.55 seconds but I'm not sure how accurate the timeout is) then it just hung there.

I seem to remember reading that this is a problem with Mega boards only.  It may actually be a defect in the chip itself.  Even if the code did sort of work though, the boot up delay is well over two seconds so I'll never get to setup() before the timer goes off unless I use at least a 4 second timeout.  That's ok with me since I want 8 seconds anyway, but it does appear that the timer is getting changed to some other value (like 15mS) before my code starts running.

I guess I'm going to have to dig out the datasheets and see if I can put the equivalent of wdt_disable() early in the boot loader.  I can't see this as causing a problem because I'm starting from scratch at that point anyway.

len morgan

Go Up