Pages: 1 2 [3] 4   Go Down
Author Topic: Watchdog in Arduino Library - or at least support by bootloader  (Read 29037 times)
0 Members and 1 Guest are viewing this topic.
Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I don't support your words.
 If the delay() is used, the watchdog will reset all time.
Reset button don't work. I have to  power off.

It's a bug in the bootloader, not the sketch. If you change the fuse to load the sketch (and bypass the bootloader) it will work correctly. Or, better, get a bootloader that handles the WDT correctly.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 19
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Regarding "
Tested on the Mega2560 board once I replaced the bootloader with this working one:

https://raw.github.com/arduino/Arduino-stk500v2-bootloader/master/goodHexFiles/stk500boot_v2_mega2560.hex
"

I found another bootloader (which seems to be the one installed with the Arduino IDE) under
https://github.com/arduino/Arduino/tree/master/hardware/arduino/
bootloaders/stk500v2/stk500boot_v2_mega2560.hex   

It has the same file name as "this working one", but its size is 103kB versus 21kB for the other.
Obviously, these are different bootloaders, and should have a different version, means e.g. stk500boot_v3_mega2560.hex for the working one. Besides of this, what are the differences between the two, other than watchdog support?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 19
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks Nick to have solved the problem for the Mega2560 (now only the correctly working bootloader should be delivered with new Mega 2560 and new versions of the IDE).

Meanwhile, I have ordered the new Arduino Due. Has anyone yet successfully used watchdog with this one? Means, does the standard Due bootloader support watchdog, and what are the equivalent lines of code for the SAM3XE8 in the Arduino IDE?
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I don't know, I suggest you post this question in the Due part of the forum.
Logged

SF Bay Area (USA)
Offline Offline
Tesla Member
***
Karma: 124
Posts: 6647
Strongly opinionated, but not official!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Obviously, these are different bootloaders, and should have a different version, means e.g. stk500boot_v3_mega2560.hex for the working one.
"Stk500v2" is the name of the protocol supported by this bootloader, the v2 is NOT the version of bootloader itself.
I don't think that there is a separate version number for the bootloader.  Although that WOULD be a good idea.
(Hmm.  It does have the date that the code was compiled:
Bootloader>? CPU stats
Arduino explorer stk500V2 by MLS
Compiled on = Jan 28 2013

)
Quote
but its size is 103kB versus 21kB for the other.
Um?  Not that I could see.
https://github.com/arduino/Arduino/blob/master/hardware/arduino/bootloaders/stk500v2/stk500boot_v2_mega2560.hex shows as "514 lines (513 sloc) 22.989 kb"
While the newer code at https://github.com/arduino/Arduino-stk500v2-bootloader/blob/master/goodHexFiles/stk500boot_v2_mega2560.hex shows as "file 469 lines (468 sloc) 20.964 kb "
Perhaps you were comparing HTML pretty-printed web page against 'raw' file size?
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

It has the same file name as "this working one", but its size is 103kB versus 21kB for the other.

We have to take that with a grain of salt, as the maximum size of the bootloader on the Mega2560 is 8K bytes (see datasheet, page 330).

The idea that a chip with 256 Kb of program memory would have a 103 Kb bootloader is, if I may say, laughable.
Logged

SF Bay Area (USA)
Offline Offline
Tesla Member
***
Karma: 124
Posts: 6647
Strongly opinionated, but not official!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well, size of the .hex file will always be somewhat more than twice the size of the actual code...
20k is a reasonable .hex file size for an 8k bootloader.
Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 133
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


hello, I need the strech by bluetooth shit, and I get it, but I must be attentive to press the reset arduino-one.

when bleutooch connects, there squeezed reset and this loads the strech.

I tried to use the wacthdog, when this is connected to a reset,
but I can not load the strech, someone has done something similar to what
comment?


Code:

#include <avr/wdt.h>

int led = 9;           // the pin that the LED is attached to
int brightness = 0;    // how bright the LED is
int fadeAmount = 5;    // how many points to fade the LED by
void setup ()
{
  Serial.begin (115200);
    pinMode(led, OUTPUT);

//  Serial.println ("Restarted.");
while(!Serial){
  ;

wdt_reset ();   
wdt_disable();

 }  // end of setup

void loop ()
{


analogWrite(led, brightness);   

  // change the brightness for next time through the loop:
  brightness = brightness + fadeAmount;

  // reverse the direction of the fading at the ends of the fade:
  if (brightness == 0 || brightness == 255) {
    fadeAmount = -fadeAmount ;
  }     
  // wait for 30 milliseconds to see the dimming effect   
  delay(30);   





 
}  // end of loop



http://www.ebay.com/itm/Wireless-Bluetooth-Transceiver-Module-RS232-TTL-/200520318414?_trksid=p2047675.m1850&_trkparms=aid%3D222002%26algo%3DSIC.FIT%26ao%3D1%26asc%3D11%26meid%3D6299423035725889752%26pid%3D100011%26prg%3D1005%26rk%3D4%26sd%3D320968741708%26
Logged

NAPERVILLE, IL
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Nick,
re: Regarding "
Tested on the Mega2560 board once I replaced the bootloader with this working one:

https://raw.github.com/arduino/Arduino-stk500v2-bootloader/master/goodHexFiles/stk500boot_v2_mega2560.hex"

Do you know if this is the bootloader in the Arduino 1.04 IDE release?

I've been battling dropped ethernet  connection on my webserver application for weeks. It occurs anywhere from hours to days. The application continues to run, but over time, a client will not be able to connect. I have a Mega2560  and want to implement watchdog timer based on your example. The code verifies, but I haven't uploaded it yet to test based on the comments on this post (the need to replace the bootloader)

Is your recommendation of the bootloader you specified still valid? Any help is appreciated.

Thanks,
Rich
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

There seem to be two booloader files shipping with 1.04 namely:

Code:
// File =  Mega2560-prod-firmware-2011-06-29.hex
// Loader start: 3E000, length: 8192
// MD5 sum = 1E 35 14 08 1F 65 7F 8C 96 50 69 9F 19 1E 3D F0

// File =  stk500boot_v2_mega2560.hex
// Loader start: 3E000, length: 8192
// MD5 sum = D9 E6 6B 4E D1 A6 11 2C 61 8F 9B D5 5D 24 E2 13

However neither has the MD5 sum of the one that I found to work namely:

Code:
// File =  stk500boot_v2_mega2560_fixes_watchdog_problem.hex
// Loader start: 3E000, length: 8192
// MD5 sum = 8A F4 7A 29 43 A0 D8 7C DB ED 09 A3 8F 40 24 1E

I would still recommend the "fixed" one from:


https://raw.github.com/arduino/Arduino-stk500v2-bootloader/master/goodHexFiles/stk500boot_v2_mega2560.hex
Logged

NAPERVILLE, IL
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Nick, thanks for your reply. Ummmm... how do I actually load this? Using the Arduino IDE under tools->Burn Bootloader  ? Obviously from my question I've never done this and would appreciate pointing me in the right direction. Is there documentation you could site? All I could find in  http://arduino.cc/en/Guide/Environment  using IDE tools->Burn Bootloader is:
 "Ensure that you've selected the correct board from the Boards menu before burning the bootloader."

Thanks in advance.
Rich
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You need an external device. A board can't burn its own bootloader. If you have a second Arduino one option is the sketch described here:

http://www.gammon.com.au/forum/?id=11635

Using the IDE you also need another device, such as another Arduino with the "Arduino as ISP" sketch on it, or a programmer like USBtinyISP or similar. These are available from places like Adafruit, Sparkfun, eBay, etc.
Logged

NAPERVILLE, IL
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Nick, thanks for your reply. I do have another Arduino ( Uno, rev 3). I reviewed the sketch you specified in your reply. To other readers... Nick's reply is more then just a sketch, it's a tutorial on how to burn a new bootloader using a second arduino.
Question: before doing this, is there any harm in testing the sketch you listed on page 1 with my existing bootloader? If my bootloader (by chance) were correct, I would get the results listed on page 2 ,your  Reply #22 . If not, what will occur? It won't brick my Mega will it? What happened when you ran with the "bad" bootloader,  Reply #20?
I'm asking because of FernandoGarcia 's reply #25 "I uploaded these examples in my arduino mega 2560 and was a fight to get remove them." as well as RetroLefty's post #29 example code comment: "Note that current arduino mega boards will fail this test and brick". Yikes!
To restate my environment: Mega2560, Arduino IDE 1.0.4

thanks
Rich
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Question: before doing this, is there any harm in testing the sketch you listed on page 1 with my existing bootloader? If my bootloader (by chance) were correct, I would get the results listed on page 2 ,your  Reply #22 . If not, what will occur? It won't brick my Mega will it? What happened when you ran with the "bad" bootloader,  Reply #20?

First, there are ways around a "bricked" processor, particularly this type of bricking. The problem is that the sketch runs, sets up the watchdog timer, and the watchdog then interrupts the bootloader.

The trick is to not let the sketch run. You power the board off completely, hold down reset, keep holding down reset you apply power (plug the USB cable in). At this stage the sketch hasn't run (you have reset held down). Now with a free hand (this can be the tricky bit) you start uploading a fresh sketch. As it starts to upload you release reset (and not before), and the bootloader kicks in, without having the watchdog timer enabled.

Or, you simply use things like my bootloader uploader to simply replace the bootloader which has the side-effect of erasing program memory, and thus erasing the problem sketch. So you have two ways around it.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 1
UESTC
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

pls check this:
>>Arduino Mini 328
 no delay() befero wdt_enable(), and one wdt_reset() just after wdt_enable() and another wdt_reset() in first line in loop();
 
like this:
void setup()
{
  wdt_enable(WDTO_4S);
  wdt_reset();
}
void loop()
{
    wdt_reset ();
    while(1)
    {
    //user loop
    }
}
Logged

Pages: 1 2 [3] 4   Go Up
Jump to: