Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MicroBridge bootloader hanging indefinitely after watchdog timer reset #1

Open
haugenmitch opened this issue Mar 2, 2022 · 0 comments

Comments

@haugenmitch
Copy link
Owner

There is a bug in the bootloader that causes it to hang indefinitely when the watch dog timer expires and resets the Arduino. This hang prevents the board from reprogramming itself or launching into the currently loaded program. This can be fixed, though, if a println() statement is executed shortly before the reset occurs. It is not known why this causes the reset to proceed properly, but it may have to do with the bootloader checking for data on the serial line.

In order to test this, use the following code example:

#include <avr/wdt.h>
#include <EEPROM.h>

int x = 1000;

void setup() {
  wdt_disable();
  
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(LED_BUILTIN, OUTPUT);
  
  Serial.begin(9600);
  Serial.println("Setup");
}

void loop() {
  // uncomment this line to get the bootloader to reprogram the board
  // Serial.println(x);
  
  digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
  delay(x); // wait for a second
  digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
  delay(x); // wait for a second
  
  x = x / 10 * 9;  // reduce the timeout by 10% each loop
  
  if (x <= 0) {
     EEPROM.write(E2END, 0xF0);
     wdt_enable(WDTO_1S);
     while(true);
  }
}

On an Arduino with the standard bootloader, this code (as is) will blink the on board LED quicker and quicker until the board resets itself and starts the process all over again. On an Arduino with this bootloader, this code (as is) will hang indefinitely after a reset is attempted at the end of the first run of the program. However, uncommenting the println() statement at the beginning of the loop() function will cause the reset to proceed as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant