diff options
| author | Fred Sundvik <fsundvik@gmail.com> | 2018-02-10 23:09:03 +0200 |
|---|---|---|
| committer | Jack Humbert <jack.humb@gmail.com> | 2018-02-10 17:13:38 -0500 |
| commit | 8c2ae4a4701439e98569dc2f2acee7016b4c0f20 (patch) | |
| tree | 835e57a8f18b7a8259f24bbd5d8a3c784e843688 /tmk_core | |
| parent | fca31693df15f62cc3fd5851a0d1bae40eb179c2 (diff) | |
| download | qmk_firmware-8c2ae4a4701439e98569dc2f2acee7016b4c0f20.tar.gz qmk_firmware-8c2ae4a4701439e98569dc2f2acee7016b4c0f20.zip | |
Fix reset for STM32 devices
Diffstat (limited to 'tmk_core')
| -rw-r--r-- | tmk_core/common/chibios/bootloader.c | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/tmk_core/common/chibios/bootloader.c b/tmk_core/common/chibios/bootloader.c index fc17fca1b..2dd3ade34 100644 --- a/tmk_core/common/chibios/bootloader.c +++ b/tmk_core/common/chibios/bootloader.c | |||
| @@ -6,32 +6,32 @@ | |||
| 6 | #ifdef STM32_BOOTLOADER_ADDRESS | 6 | #ifdef STM32_BOOTLOADER_ADDRESS |
| 7 | /* STM32 */ | 7 | /* STM32 */ |
| 8 | 8 | ||
| 9 | #if defined(STM32F0XX) | ||
| 10 | /* This code should be checked whether it runs correctly on platforms */ | 9 | /* This code should be checked whether it runs correctly on platforms */ |
| 11 | #define SYMVAL(sym) (uint32_t)(((uint8_t *)&(sym)) - ((uint8_t *)0)) | 10 | #define SYMVAL(sym) (uint32_t)(((uint8_t *)&(sym)) - ((uint8_t *)0)) |
| 12 | extern uint32_t __ram0_end__; | 11 | extern uint32_t __ram0_end__; |
| 12 | #define BOOTLOADER_MAGIC 0xDEADBEEF | ||
| 13 | #define MAGIC_ADDR (unsigned long*)(SYMVAL(__ram0_end__) - 4) | ||
| 13 | 14 | ||
| 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 | #elif defined(STM32F3XX) | ||
| 20 | /* This code should be checked whether it runs correctly on platforms. | ||
| 21 | * It was added for clueboard60 BUT HAS NOT BEEN TESTED. | ||
| 22 | * FIXME - Test this | ||
| 23 | */ | ||
| 24 | #define SYMVAL(sym) (uint32_t)(((uint8_t *)&(sym)) - ((uint8_t *)0)) | ||
| 25 | extern uint32_t __ram0_end__; | ||
| 26 | 15 | ||
| 27 | void bootloader_jump(void) { | 16 | void bootloader_jump(void) { |
| 28 | *((unsigned long *)(SYMVAL(__ram0_end__) - 4)) = 0xDEADBEEF; // set magic flag => reset handler will jump into boot loader | 17 | *MAGIC_ADDR = BOOTLOADER_MAGIC; // set magic flag => reset handler will jump into boot loader |
| 29 | NVIC_SystemReset(); | 18 | NVIC_SystemReset(); |
| 30 | } | 19 | } |
| 31 | 20 | ||
| 32 | #else /* defined(STM32F0XX) */ | 21 | void enter_bootloader_mode_if_requested(void) { |
| 33 | #error Check that the bootloader code works on your platform and add it to bootloader.c! | 22 | unsigned long* check = MAGIC_ADDR; |
| 34 | #endif /* defined(STM32F0XX) */ | 23 | if(*check == BOOTLOADER_MAGIC) { |
| 24 | *check = 0; | ||
| 25 | __set_CONTROL(0); | ||
| 26 | __set_MSP(*(__IO uint32_t*)STM32_BOOTLOADER_ADDRESS); | ||
| 27 | __enable_irq(); | ||
| 28 | |||
| 29 | typedef void (*BootJump_t)(void); | ||
| 30 | BootJump_t boot_jump = *(BootJump_t*)(STM32_BOOTLOADER_ADDRESS + 4); | ||
| 31 | boot_jump(); | ||
| 32 | while(1); | ||
| 33 | } | ||
| 34 | } | ||
| 35 | 35 | ||
| 36 | #elif defined(KL2x) || defined(K20x) /* STM32_BOOTLOADER_ADDRESS */ | 36 | #elif defined(KL2x) || defined(K20x) /* STM32_BOOTLOADER_ADDRESS */ |
| 37 | /* Kinetis */ | 37 | /* Kinetis */ |
