]> git.gir.st - tmk_keyboard.git/blob - tmk_core/common/chibios/bootloader.c
Add correct chibios/bootloader_jump for infinity KB.
[tmk_keyboard.git] / tmk_core / common / chibios / bootloader.c
1 #include "bootloader.h"
2
3 #include "ch.h"
4 #include "hal.h"
5
6 #ifdef STM32_BOOTLOADER_ADDRESS
7 /* STM32 */
8
9 #if defined(STM32F0XX)
10 /* This code should be checked whether it runs correctly on platforms */
11 #define SYMVAL(sym) (uint32_t)(((uint8_t *)&(sym)) - ((uint8_t *)0))
12 extern uint32_t __ram0_end__;
13
14 void bootloader_jump(void) {
15 *((unsigned long *)(SYMVAL(__ram0_end__) - 4)) = 0xDEADBEEF; // set magic flag => reset handler will jump into boot loader
16 NVIC_SystemReset();
17 }
18
19 #else /* defined(STM32F0XX) */
20 #error Check that the bootloader code works on your platform and add it to bootloader.c!
21 #endif /* defined(STM32F0XX) */
22
23 #elif defined(KL2x) || defined(K20x) /* STM32_BOOTLOADER_ADDRESS */
24 /* Kinetis */
25
26 #if defined(KIIBOHD_BOOTLOADER)
27 /* Kiibohd Bootloader (MCHCK and Infinity KB) */
28 #define SCB_AIRCR (*(volatile uint32_t *)0xE000ED0C) // Application Interrupt and Reset Control
29 #define VBAT (*(volatile uint8_t *)0x4003E000) // VBAT register file (32 bytes)
30 const uint8_t sys_reset_to_loader_magic[] = "\xff\x00\x7fRESET TO LOADER\x7f\x00\xff";
31 void bootloader_jump(void) {
32 __builtin_memcpy((void *)&VBAT, (const void *)sys_reset_to_loader_magic, sizeof(sys_reset_to_loader_magic));
33 // request reset
34 SCB_AIRCR = 0x05FA0004;
35 }
36
37 #else /* defined(KIIBOHD_BOOTLOADER) */
38 /* Default for Kinetis - expecting an ARM Teensy */
39 void bootloader_jump(void) {
40 chThdSleepMilliseconds(100);
41 __BKPT(0);
42 }
43 #endif /* defined(KIIBOHD_BOOTLOADER) */
44
45 #else /* neither STM32 nor KINETIS */
46 void bootloader_jump(void) {}
47 #endif
Imprint / Impressum