diff options
Diffstat (limited to 'platforms/arm_atsam/bootloader.c')
-rw-r--r-- | platforms/arm_atsam/bootloader.c | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/platforms/arm_atsam/bootloader.c b/platforms/arm_atsam/bootloader.c new file mode 100644 index 000000000..9015b00aa --- /dev/null +++ b/platforms/arm_atsam/bootloader.c | |||
@@ -0,0 +1,57 @@ | |||
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 | |||
17 | #include "bootloader.h" | ||
18 | #include "samd51j18a.h" | ||
19 | #include "md_bootloader.h" | ||
20 | |||
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 | ||
28 | |||
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 | ||
32 | } | ||
33 | |||
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) { | ||
38 | } // Won't get here | ||
39 | } | ||
40 | #endif | ||
41 | |||
42 | WDT->CTRLA.bit.ENABLE = 0; | ||
43 | while (WDT->SYNCBUSY.bit.ENABLE) { | ||
44 | } | ||
45 | while (WDT->CTRLA.bit.ENABLE) { | ||
46 | } | ||
47 | WDT->CONFIG.bit.WINDOW = 0; | ||
48 | WDT->CONFIG.bit.PER = 0; | ||
49 | WDT->EWCTRL.bit.EWOFFSET = 0; | ||
50 | WDT->CTRLA.bit.ENABLE = 1; | ||
51 | while (WDT->SYNCBUSY.bit.ENABLE) { | ||
52 | } | ||
53 | while (!WDT->CTRLA.bit.ENABLE) { | ||
54 | } | ||
55 | while (1) { | ||
56 | } // Wait on timeout | ||
57 | } | ||