From 19350e3ee55c701e886e4376b0892bc74595b66f Mon Sep 17 00:00:00 2001 From: tmk Date: Mon, 16 Sep 2019 17:49:38 +0900 Subject: [PATCH] core: Add bootkey of Caterina bootloader The bootkey set in bootloader_jump() works with Pro Micro and Leonardo. This fix doesn't seem to prevent other bootloaders, however, it can be disabled by defining NO_BOOTLOADER_CATERINA_BOOTKEY. --- tmk_core/common/avr/bootloader.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tmk_core/common/avr/bootloader.c b/tmk_core/common/avr/bootloader.c index 7c744e8c..8d6de1a0 100644 --- a/tmk_core/common/avr/bootloader.c +++ b/tmk_core/common/avr/bootloader.c @@ -87,6 +87,14 @@ void bootloader_jump(void) { _delay_ms(5); #endif +#ifndef NO_BOOTLOADER_CATERINA_BOOTKEY + // Set bootkey for Arduino Leonardo and Pro Micro bootloader + // Watchdog reset with bootkey causes the bootloader to enter program mode instead of starting application. + // https://github.com/arduino/ArduinoCore-avr/blob/master/bootloaders/caterina/Caterina.c#L68-L69 + // https://github.com/sparkfun/SF32u4_boards/blob/master/sparkfun/avr/bootloaders/caterina/Caterina.c#L88-L89 + *(volatile uint16_t *)0x0800 = 0x7777; +#endif + // watchdog reset reset_key = BOOTLOADER_RESET_KEY; wdt_enable(WDTO_250MS); @@ -108,6 +116,13 @@ void bootloader_jump_after_watchdog_reset(void) MCUSR &= ~(1<