diff options
| author | skullY <skullydazed@gmail.com> | 2019-08-30 11:19:03 -0700 |
|---|---|---|
| committer | skullydazed <skullydazed@users.noreply.github.com> | 2019-08-30 15:01:52 -0700 |
| commit | b624f32f944acdc59dcb130674c09090c5c404cb (patch) | |
| tree | bc13adbba137d122d9a2c2fb2fafcbb08ac10e25 /tmk_core/common/chibios/bootloader.c | |
| parent | 61af76a10d00aba185b8338604171de490a13e3b (diff) | |
| download | qmk_firmware-b624f32f944acdc59dcb130674c09090c5c404cb.tar.gz qmk_firmware-b624f32f944acdc59dcb130674c09090c5c404cb.zip | |
clang-format changes
Diffstat (limited to 'tmk_core/common/chibios/bootloader.c')
| -rw-r--r-- | tmk_core/common/chibios/bootloader.c | 63 |
1 files changed, 31 insertions, 32 deletions
diff --git a/tmk_core/common/chibios/bootloader.c b/tmk_core/common/chibios/bootloader.c index f9895237b..4cf5dae7e 100644 --- a/tmk_core/common/chibios/bootloader.c +++ b/tmk_core/common/chibios/bootloader.c | |||
| @@ -7,63 +7,62 @@ | |||
| 7 | /* STM32 */ | 7 | /* STM32 */ |
| 8 | 8 | ||
| 9 | /* This code should be checked whether it runs correctly on platforms */ | 9 | /* This code should be checked whether it runs correctly on platforms */ |
| 10 | #define SYMVAL(sym) (uint32_t)(((uint8_t *)&(sym)) - ((uint8_t *)0)) | 10 | # define SYMVAL(sym) (uint32_t)(((uint8_t *)&(sym)) - ((uint8_t *)0)) |
| 11 | extern uint32_t __ram0_end__; | 11 | extern uint32_t __ram0_end__; |
| 12 | #define BOOTLOADER_MAGIC 0xDEADBEEF | 12 | # define BOOTLOADER_MAGIC 0xDEADBEEF |
| 13 | #define MAGIC_ADDR (unsigned long*)(SYMVAL(__ram0_end__) - 4) | 13 | # define MAGIC_ADDR (unsigned long *)(SYMVAL(__ram0_end__) - 4) |
| 14 | |||
| 15 | 14 | ||
| 16 | /** \brief Jump to the bootloader | 15 | /** \brief Jump to the bootloader |
| 17 | * | 16 | * |
| 18 | * FIXME: needs doc | 17 | * FIXME: needs doc |
| 19 | */ | 18 | */ |
| 20 | void bootloader_jump(void) { | 19 | void bootloader_jump(void) { |
| 21 | *MAGIC_ADDR = BOOTLOADER_MAGIC; // set magic flag => reset handler will jump into boot loader | 20 | *MAGIC_ADDR = BOOTLOADER_MAGIC; // set magic flag => reset handler will jump into boot loader |
| 22 | NVIC_SystemReset(); | 21 | NVIC_SystemReset(); |
| 23 | } | 22 | } |
| 24 | 23 | ||
| 25 | /** \brief Enter bootloader mode if requested | 24 | /** \brief Enter bootloader mode if requested |
| 26 | * | 25 | * |
| 27 | * FIXME: needs doc | 26 | * FIXME: needs doc |
| 28 | */ | 27 | */ |
| 29 | void enter_bootloader_mode_if_requested(void) { | 28 | void enter_bootloader_mode_if_requested(void) { |
| 30 | unsigned long* check = MAGIC_ADDR; | 29 | unsigned long *check = MAGIC_ADDR; |
| 31 | if(*check == BOOTLOADER_MAGIC) { | 30 | if (*check == BOOTLOADER_MAGIC) { |
| 32 | *check = 0; | 31 | *check = 0; |
| 33 | __set_CONTROL(0); | 32 | __set_CONTROL(0); |
| 34 | __set_MSP(*(__IO uint32_t*)STM32_BOOTLOADER_ADDRESS); | 33 | __set_MSP(*(__IO uint32_t *)STM32_BOOTLOADER_ADDRESS); |
| 35 | __enable_irq(); | 34 | __enable_irq(); |
| 36 | 35 | ||
| 37 | typedef void (*BootJump_t)(void); | 36 | typedef void (*BootJump_t)(void); |
| 38 | BootJump_t boot_jump = *(BootJump_t*)(STM32_BOOTLOADER_ADDRESS + 4); | 37 | BootJump_t boot_jump = *(BootJump_t *)(STM32_BOOTLOADER_ADDRESS + 4); |
| 39 | boot_jump(); | 38 | boot_jump(); |
| 40 | while(1); | 39 | while (1) |
| 41 | } | 40 | ; |
| 42 | } | 41 | } |
| 42 | } | ||
| 43 | 43 | ||
| 44 | #elif defined(KL2x) || defined(K20x) /* STM32_BOOTLOADER_ADDRESS */ | 44 | #elif defined(KL2x) || defined(K20x) /* STM32_BOOTLOADER_ADDRESS */ |
| 45 | /* Kinetis */ | 45 | /* Kinetis */ |
| 46 | 46 | ||
| 47 | #if defined(KIIBOHD_BOOTLOADER) | 47 | # if defined(KIIBOHD_BOOTLOADER) |
| 48 | /* Kiibohd Bootloader (MCHCK and Infinity KB) */ | 48 | /* Kiibohd Bootloader (MCHCK and Infinity KB) */ |
| 49 | #define SCB_AIRCR_VECTKEY_WRITEMAGIC 0x05FA0000 | 49 | # define SCB_AIRCR_VECTKEY_WRITEMAGIC 0x05FA0000 |
| 50 | const uint8_t sys_reset_to_loader_magic[] = "\xff\x00\x7fRESET TO LOADER\x7f\x00\xff"; | 50 | const uint8_t sys_reset_to_loader_magic[] = "\xff\x00\x7fRESET TO LOADER\x7f\x00\xff"; |
| 51 | void bootloader_jump(void) { | 51 | void bootloader_jump(void) { |
| 52 | __builtin_memcpy((void *)VBAT, (const void *)sys_reset_to_loader_magic, sizeof(sys_reset_to_loader_magic)); | 52 | __builtin_memcpy((void *)VBAT, (const void *)sys_reset_to_loader_magic, sizeof(sys_reset_to_loader_magic)); |
| 53 | // request reset | 53 | // request reset |
| 54 | SCB->AIRCR = SCB_AIRCR_VECTKEY_WRITEMAGIC | SCB_AIRCR_SYSRESETREQ_Msk; | 54 | SCB->AIRCR = SCB_AIRCR_VECTKEY_WRITEMAGIC | SCB_AIRCR_SYSRESETREQ_Msk; |
| 55 | } | 55 | } |
| 56 | 56 | ||
| 57 | #else /* defined(KIIBOHD_BOOTLOADER) */ | 57 | # else /* defined(KIIBOHD_BOOTLOADER) */ |
| 58 | /* Default for Kinetis - expecting an ARM Teensy */ | 58 | /* Default for Kinetis - expecting an ARM Teensy */ |
| 59 | #include "wait.h" | 59 | # include "wait.h" |
| 60 | void bootloader_jump(void) { | 60 | void bootloader_jump(void) { |
| 61 | wait_ms(100); | 61 | wait_ms(100); |
| 62 | __BKPT(0); | 62 | __BKPT(0); |
| 63 | } | 63 | } |
| 64 | #endif /* defined(KIIBOHD_BOOTLOADER) */ | 64 | # endif /* defined(KIIBOHD_BOOTLOADER) */ |
| 65 | 65 | ||
| 66 | #else /* neither STM32 nor KINETIS */ | 66 | #else /* neither STM32 nor KINETIS */ |
| 67 | __attribute__((weak)) | 67 | __attribute__((weak)) void bootloader_jump(void) {} |
| 68 | void bootloader_jump(void) {} | ||
| 69 | #endif | 68 | #endif |
