Detect inifite loop in customed bootloader

Hi, I work in custumed bootloader based on this proyect DualOptiboot, compiled con debug on and burned in atmega1284. I load test binary file in external SPI flash, but in this process, I have a problem (buffer overflow) and the file was saved with errors. When I started the bootloader it apparently load binary file in the internal flash but does jump to the application code and the MCU crashed (serial port show: SASASASASA....). This problem is solved, but I want to catch this error to recover the MCU and load another code saved in the external flash, for example:

int main(void)
{
  ...  
  // Adaboot no-wait mod
  ch = MCUSR;
  MCUSR = 0;
    
#ifdef DEBUG_ON  
    putch('S');
#endif

  // Read flag saved in external flash or eeprom 
  if( flag is true ){
    // load basic code
    // clear flag
  }

  if (!(ch & _BV(EXTRF))) //if not external reset
  {
    if (ch & _BV(WDRF)) //if reset by watchdog
      CheckFlashImage();
#ifdef DEBUG_ON
    putch('A');
#endif
    SPCR &= ~_BV(SPE) & ~_BV(MSTR);
    appStart(ch);
  }
  ...
}

How can I detect that the bootloader is in an infinite loop and configure a flag to recover the mcu

Why do you think it's the bootloader that is in an infinite loop, rather than the application it probably thinks it has successfully loaded and started, crashing?

I can't think of a way to detect the bootloader looping; it's already using the watchdog for other purposes.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.