Fix leave Bootloader only in case of valid application code
authorPeter Henn <Peter.Henn@web.de>
Wed, 29 Dec 2021 14:49:37 +0000 (14:49 +0000)
committerPeter Henn <Peter.Henn@web.de>
Fri, 7 Jan 2022 12:15:33 +0000 (12:15 +0000)
- Check, if reset vector points to an application before leaving the
  Bootloader after 5 seconds timeout
- Bugfix wrong test of reset vector from mainline

Bootloaders/DFU/BootloaderDFU.c

index f29af3b..ce76abe 100644 (file)
@@ -237,7 +237,10 @@ int main(void)
                        Delay_MS(1);
                        if (i++ > 5000)
                        {
-                               break;
+                               if (pgm_read_word_near(0) != 0xFFFF)
+                                       break;
+                               else
+                                       i = 0;
                        }
                }
                else
@@ -836,7 +839,7 @@ static void ProcessWriteCommand(void)
                        else                                                               // Start via jump
                        {
                                /* Set the flag to terminate the bootloader at next opportunity if a valid application has been loaded */
-                               if (pgm_read_word_near(0) == 0xFFFF)
+                               if (pgm_read_word_near(0) != 0xFFFF)
                                  RunBootloader = false;
                        }
                }