bootloader.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /* Copyright 2017 Fred Sundvik
  2. *
  3. * This program is free software: you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation, either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include "bootloader.h"
  17. #include "samd51j18a.h"
  18. //Set watchdog timer to reset. Directs the bootloader to stay in programming mode.
  19. void bootloader_jump(void)
  20. {
  21. //Keyboards released with certain bootloader can not enter bootloader from app until workaround is created
  22. uint8_t ver_no_jump[] = "v2.18Jun 22 2018 17:28:08";
  23. uint8_t *ver_check = ver_no_jump;
  24. uint8_t *boot_check = (uint8_t *)0x21A0;
  25. while (*ver_check && *boot_check == *ver_check)
  26. {
  27. ver_check++;
  28. boot_check++;
  29. }
  30. if (!*ver_check)
  31. {
  32. //Version match
  33. //Software workaround would go here
  34. return; //No software restart method implemented... must use hardware reset button
  35. }
  36. WDT->CTRLA.bit.ENABLE = 0;
  37. while (WDT->SYNCBUSY.bit.ENABLE) {}
  38. while (WDT->CTRLA.bit.ENABLE) {}
  39. WDT->CONFIG.bit.WINDOW = 0;
  40. WDT->CONFIG.bit.PER = 0;
  41. WDT->EWCTRL.bit.EWOFFSET = 0;
  42. WDT->CTRLA.bit.ENABLE = 1;
  43. while (WDT->SYNCBUSY.bit.ENABLE) {}
  44. while (!WDT->CTRLA.bit.ENABLE) {}
  45. while (1) {} //Wait on timeout
  46. }