1 /* Copyright 2017 Fred Sundvik
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.
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.
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/>.
17 #include "bootloader.h"
18 #include "samd51j18a.h"
19 #include "md_bootloader.h"
21 //Set watchdog timer to reset. Directs the bootloader to stay in programming mode.
22 void bootloader_jump(void) {
23 #ifdef KEYBOARD_massdrop_ctrl
24 //CTRL keyboards released with bootloader version below must use RAM method. Otherwise use WDT method.
25 uint8_t ver_ram_method[] = "v2.18Jun 22 2018 17:28:08"; //The version to match (NULL terminated by compiler)
26 uint8_t *ver_check = ver_ram_method; //Pointer to version match string for traversal
27 uint8_t *ver_rom = (uint8_t *)0x21A0; //Pointer to address in ROM where this specific bootloader version would exist
29 while (*ver_check && *ver_rom == *ver_check) { //While there are check version characters to match and bootloader's version matches check's version
30 ver_check++; //Move check version pointer to next character
31 ver_rom++; //Move ROM version pointer to next character
34 if (!*ver_check) { //If check version pointer is NULL, all characters have matched
35 *MAGIC_ADDR = BOOTLOADER_MAGIC; //Set magic number into RAM
36 NVIC_SystemReset(); //Perform system reset
37 while (1) {} //Won't get here
41 WDT->CTRLA.bit.ENABLE = 0;
42 while (WDT->SYNCBUSY.bit.ENABLE) {}
43 while (WDT->CTRLA.bit.ENABLE) {}
44 WDT->CONFIG.bit.WINDOW = 0;
45 WDT->CONFIG.bit.PER = 0;
46 WDT->EWCTRL.bit.EWOFFSET = 0;
47 WDT->CTRLA.bit.ENABLE = 1;
48 while (WDT->SYNCBUSY.bit.ENABLE) {}
49 while (!WDT->CTRLA.bit.ENABLE) {}
50 while (1) {} //Wait on timeout