aboutsummaryrefslogtreecommitdiff
path: root/tmk_core
diff options
context:
space:
mode:
Diffstat (limited to 'tmk_core')
-rw-r--r--tmk_core/common/chibios/bootloader.c46
1 files changed, 15 insertions, 31 deletions
diff --git a/tmk_core/common/chibios/bootloader.c b/tmk_core/common/chibios/bootloader.c
index dceeaa6b1..743448ee1 100644
--- a/tmk_core/common/chibios/bootloader.c
+++ b/tmk_core/common/chibios/bootloader.c
@@ -2,6 +2,7 @@
2 2
3#include "ch.h" 3#include "ch.h"
4#include "hal.h" 4#include "hal.h"
5#include "wait.h"
5 6
6/* This code should be checked whether it runs correctly on platforms */ 7/* This code should be checked whether it runs correctly on platforms */
7#define SYMVAL(sym) (uint32_t)(((uint8_t *)&(sym)) - ((uint8_t *)0)) 8#define SYMVAL(sym) (uint32_t)(((uint8_t *)&(sym)) - ((uint8_t *)0))
@@ -31,45 +32,28 @@
31 32
32extern uint32_t __ram0_end__; 33extern uint32_t __ram0_end__;
33 34
34# define bootdelay(loopcount) \
35 do { \
36 for (int i = 0; i < loopcount; ++i) { \
37 __asm__ volatile("nop\n\t" \
38 "nop\n\t" \
39 "nop\n\t"); \
40 } \
41 } while (0)
42
43void bootloader_jump(void) { 35void bootloader_jump(void) {
44 *MAGIC_ADDR = BOOTLOADER_MAGIC; // set magic flag => reset handler will jump into boot loader 36 // For STM32 MCUs with dual-bank flash, and we're incapable of jumping to the bootloader. The first valid flash
45 NVIC_SystemReset(); 37 // bank is executed unconditionally after a reset, so it doesn't enter DFU unless BOOT0 is high. Instead, we do
46} 38 // it with hardware...in this case, we pull a GPIO high/low depending on the configuration, connects 3.3V to
47 39 // BOOT0's RC charging circuit, lets it charge the capacitor, and issue a system reset. See the QMK discord
48void enter_bootloader_mode_if_requested(void) { 40 // #hardware channel pins for an example circuit.
49 unsigned long *check = MAGIC_ADDR; 41 palSetPadMode(PAL_PORT(STM32_BOOTLOADER_DUAL_BANK_GPIO), PAL_PAD(STM32_BOOTLOADER_DUAL_BANK_GPIO), PAL_MODE_OUTPUT_PUSHPULL);
50 if (*check == BOOTLOADER_MAGIC) {
51 *check = 0;
52
53 // For STM32 MCUs with dual-bank flash, and we're incapable of jumping to the bootloader. The first valid flash
54 // bank is executed unconditionally after a reset, so it doesn't enter DFU unless BOOT0 is high. Instead, we do
55 // it with hardware...in this case, we pull a GPIO high/low depending on the configuration, connects 3.3V to
56 // BOOT0's RC charging circuit, lets it charge the capacitor, and issue a system reset. See the QMK discord
57 // #hardware channel pins for an example circuit.
58 palSetPadMode(PAL_PORT(STM32_BOOTLOADER_DUAL_BANK_GPIO), PAL_PAD(STM32_BOOTLOADER_DUAL_BANK_GPIO), PAL_MODE_OUTPUT_PUSHPULL);
59# if STM32_BOOTLOADER_DUAL_BANK_POLARITY 42# if STM32_BOOTLOADER_DUAL_BANK_POLARITY
60 palSetPad(PAL_PORT(STM32_BOOTLOADER_DUAL_BANK_GPIO), PAL_PAD(STM32_BOOTLOADER_DUAL_BANK_GPIO)); 43 palSetPad(PAL_PORT(STM32_BOOTLOADER_DUAL_BANK_GPIO), PAL_PAD(STM32_BOOTLOADER_DUAL_BANK_GPIO));
61# else 44# else
62 palClearPad(PAL_PORT(STM32_BOOTLOADER_DUAL_BANK_GPIO), PAL_PAD(STM32_BOOTLOADER_DUAL_BANK_GPIO)); 45 palClearPad(PAL_PORT(STM32_BOOTLOADER_DUAL_BANK_GPIO), PAL_PAD(STM32_BOOTLOADER_DUAL_BANK_GPIO));
63# endif 46# endif
64 47
65 // Wait for a while for the capacitor to charge 48 // Wait for a while for the capacitor to charge
66 bootdelay(STM32_BOOTLOADER_DUAL_BANK_DELAY); 49 wait_ms(100);
67 50
68 // Issue a system reset to get the ROM bootloader to execute, with BOOT0 high 51 // Issue a system reset to get the ROM bootloader to execute, with BOOT0 high
69 NVIC_SystemReset(); 52 NVIC_SystemReset();
70 }
71} 53}
72 54
55void enter_bootloader_mode_if_requested(void) {} // not needed at all, but if anybody attempts to invoke it....
56
73#elif defined(STM32_BOOTLOADER_ADDRESS) // STM32_BOOTLOADER_DUAL_BANK 57#elif defined(STM32_BOOTLOADER_ADDRESS) // STM32_BOOTLOADER_DUAL_BANK
74 58
75extern uint32_t __ram0_end__; 59extern uint32_t __ram0_end__;