summaryrefslogtreecommitdiff
path: root/platforms/chibios/bootloaders
diff options
context:
space:
mode:
Diffstat (limited to 'platforms/chibios/bootloaders')
-rw-r--r--platforms/chibios/bootloaders/custom.c1
-rw-r--r--platforms/chibios/bootloaders/gd32v_dfu.c7
-rw-r--r--platforms/chibios/bootloaders/halfkay.c2
-rw-r--r--platforms/chibios/bootloaders/kiibohd.c1
-rw-r--r--platforms/chibios/bootloaders/stm32_dfu.c7
-rw-r--r--platforms/chibios/bootloaders/stm32duino.c5
-rw-r--r--platforms/chibios/bootloaders/tinyuf2.c4
-rw-r--r--platforms/chibios/bootloaders/wb32_dfu.c53
8 files changed, 80 insertions, 0 deletions
diff --git a/platforms/chibios/bootloaders/custom.c b/platforms/chibios/bootloaders/custom.c
index bba9fc4637..6c5a433953 100644
--- a/platforms/chibios/bootloaders/custom.c
+++ b/platforms/chibios/bootloaders/custom.c
@@ -17,5 +17,6 @@
#include "bootloader.h"
__attribute__((weak)) void bootloader_jump(void) {}
+__attribute__((weak)) void mcu_reset(void) {}
__attribute__((weak)) void enter_bootloader_mode_if_requested(void) {}
diff --git a/platforms/chibios/bootloaders/gd32v_dfu.c b/platforms/chibios/bootloaders/gd32v_dfu.c
index baa7d1f882..100fc472f8 100644
--- a/platforms/chibios/bootloaders/gd32v_dfu.c
+++ b/platforms/chibios/bootloaders/gd32v_dfu.c
@@ -36,5 +36,12 @@ __attribute__((weak)) void bootloader_jump(void) {
*DBGMCU_CMD = DBGMCU_CMD_RESET;
}
+__attribute__((weak)) void mcu_reset(void) {
+ // Confirmed by karlk90, there is no actual reset to bootloader.
+ // This just resets the controller.
+ *DBGMCU_KEY = DBGMCU_KEY_UNLOCK;
+ *DBGMCU_CMD = DBGMCU_CMD_RESET;
+}
+
/* Jumping to bootloader is not possible from user code. */
void enter_bootloader_mode_if_requested(void) {}
diff --git a/platforms/chibios/bootloaders/halfkay.c b/platforms/chibios/bootloaders/halfkay.c
index 168c2abc23..aa11e6c5f4 100644
--- a/platforms/chibios/bootloaders/halfkay.c
+++ b/platforms/chibios/bootloaders/halfkay.c
@@ -23,3 +23,5 @@ __attribute__((weak)) void bootloader_jump(void) {
wait_ms(100);
__BKPT(0);
}
+
+__attribute__((weak)) void mcu_reset(void) {}
diff --git a/platforms/chibios/bootloaders/kiibohd.c b/platforms/chibios/bootloaders/kiibohd.c
index 911e807092..09a4d49b78 100644
--- a/platforms/chibios/bootloaders/kiibohd.c
+++ b/platforms/chibios/bootloaders/kiibohd.c
@@ -30,3 +30,4 @@ __attribute__((weak)) void bootloader_jump(void) {
// request reset
SCB->AIRCR = SCB_AIRCR_VECTKEY_WRITEMAGIC | SCB_AIRCR_SYSRESETREQ_Msk;
}
+__attribute__((weak)) void mcu_reset(void) {}
diff --git a/platforms/chibios/bootloaders/stm32_dfu.c b/platforms/chibios/bootloaders/stm32_dfu.c
index 0e74111367..ff866bd2bc 100644
--- a/platforms/chibios/bootloaders/stm32_dfu.c
+++ b/platforms/chibios/bootloaders/stm32_dfu.c
@@ -61,6 +61,9 @@ __attribute__((weak)) void bootloader_jump(void) {
NVIC_SystemReset();
}
+__attribute__((weak)) void mcu_reset(void) {
+ NVIC_SystemReset();
+}
// not needed at all, but if anybody attempts to invoke it....
void enter_bootloader_mode_if_requested(void) {}
@@ -76,6 +79,10 @@ __attribute__((weak)) void bootloader_jump(void) {
NVIC_SystemReset();
}
+__attribute__((weak)) void mcu_reset(void) {
+ NVIC_SystemReset();
+}
+
void enter_bootloader_mode_if_requested(void) {
unsigned long *check = MAGIC_ADDR;
if (*check == BOOTLOADER_MAGIC) {
diff --git a/platforms/chibios/bootloaders/stm32duino.c b/platforms/chibios/bootloaders/stm32duino.c
index 53d3ba0adb..e2db7fa16c 100644
--- a/platforms/chibios/bootloaders/stm32duino.c
+++ b/platforms/chibios/bootloaders/stm32duino.c
@@ -21,3 +21,8 @@
__attribute__((weak)) void bootloader_jump(void) {
NVIC_SystemReset();
}
+
+__attribute__((weak)) void mcu_reset(void) {
+ BKP->DR10 = RTC_BOOTLOADER_JUST_UPLOADED;
+ NVIC_SystemReset();
+} \ No newline at end of file
diff --git a/platforms/chibios/bootloaders/tinyuf2.c b/platforms/chibios/bootloaders/tinyuf2.c
index 9ffca5dec8..e08855b6c4 100644
--- a/platforms/chibios/bootloaders/tinyuf2.c
+++ b/platforms/chibios/bootloaders/tinyuf2.c
@@ -25,6 +25,10 @@
extern uint32_t _board_dfu_dbl_tap[];
#define DBL_TAP_REG _board_dfu_dbl_tap[0]
+__attribute__((weak)) void mcu_reset(void) {
+ NVIC_SystemReset();
+}
+
__attribute__((weak)) void bootloader_jump(void) {
DBL_TAP_REG = DBL_TAP_MAGIC;
NVIC_SystemReset();
diff --git a/platforms/chibios/bootloaders/wb32_dfu.c b/platforms/chibios/bootloaders/wb32_dfu.c
new file mode 100644
index 0000000000..d021b0863b
--- /dev/null
+++ b/platforms/chibios/bootloaders/wb32_dfu.c
@@ -0,0 +1,53 @@
+/* Copyright 2021 QMK
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "bootloader.h"
+
+#include <ch.h>
+#include <hal.h>
+#include "wait.h"
+
+extern uint32_t __ram0_end__;
+
+/* This code should be checked whether it runs correctly on platforms */
+#define SYMVAL(sym) (uint32_t)(((uint8_t *)&(sym)) - ((uint8_t *)0))
+#define BOOTLOADER_MAGIC 0xDEADBEEF
+#define MAGIC_ADDR (unsigned long *)(SYMVAL(__ram0_end__) - 4)
+
+__attribute__((weak)) void bootloader_jump(void) {
+ *MAGIC_ADDR = BOOTLOADER_MAGIC; // set magic flag => reset handler will jump into boot loader
+ NVIC_SystemReset();
+}
+
+void enter_bootloader_mode_if_requested(void) {
+ unsigned long *check = MAGIC_ADDR;
+ if (*check == BOOTLOADER_MAGIC) {
+ *check = 0;
+ __set_CONTROL(0);
+ __set_MSP(*(__IO uint32_t *)WB32_BOOTLOADER_ADDRESS);
+ __enable_irq();
+
+ typedef void (*BootJump_t)(void);
+ BootJump_t boot_jump = *(BootJump_t *)(WB32_BOOTLOADER_ADDRESS + 4);
+ boot_jump();
+ while (1)
+ ;
+ }
+}
+
+__attribute__((weak)) void mcu_reset(void) {
+ NVIC_SystemReset();
+}