From fd7b3de4ab567e707c31fdc086b2e2cb8db5c3b9 Mon Sep 17 00:00:00 2001 From: Florian Didron Date: Mon, 26 Jan 2026 16:30:49 +0700 Subject: [PATCH] fix(moonlander-revb) fix soft reset to bootloader --- keyboards/zsa/moonlander/moonlander.c | 31 +++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/keyboards/zsa/moonlander/moonlander.c b/keyboards/zsa/moonlander/moonlander.c index 783a42d51a..d0f1741730 100644 --- a/keyboards/zsa/moonlander/moonlander.c +++ b/keyboards/zsa/moonlander/moonlander.c @@ -469,3 +469,34 @@ void eeconfig_init_kb(void) { // EEPROM is getting reset! eeconfig_update_kb(keyboard_config.raw); eeconfig_init_user(); } + +#ifdef BOOTLOADER_CUSTOM +#define APP_ADDRESS 0x08002000 +__attribute__((weak)) void bootloader_jump(void) { + // The ignition bootloader is checking for a high signal on A8 for 100ms when powering on the board. + // Setting both A8 and A9 high will charge the capacitor quickly. + // Setting A9 low before reset will cause the capacitor to discharge + // thus making the bootloder unlikely to trigger twice between power cycles. + setPinOutputPushPull(A9); + setPinOutputPushPull(A8); + writePinHigh(A9); + writePinHigh(A8); + wait_ms(500); + writePinLow(A9); + + NVIC_SystemReset(); +} + +__attribute__((weak)) void mcu_reset(void) { + // When resetting the MCU, we want to jump to the application. + SCB->AIRCR = APP_ADDRESS & 0xFFFF; + + // Set the stack pointer to the applications stack pointer + __asm__ volatile("msr msp, %0" ::"g"(*(volatile uint32_t *)APP_ADDRESS)); + + // Jump to the application + (*(void (**)())(APP_ADDRESS + 4))(); + while (1) + ; +} +#endif