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.
This commit is contained in:
parent
f5e487bc38
commit
19350e3ee5
1 changed files with 15 additions and 0 deletions
|
|
@ -87,6 +87,14 @@ void bootloader_jump(void) {
|
||||||
_delay_ms(5);
|
_delay_ms(5);
|
||||||
#endif
|
#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
|
// watchdog reset
|
||||||
reset_key = BOOTLOADER_RESET_KEY;
|
reset_key = BOOTLOADER_RESET_KEY;
|
||||||
wdt_enable(WDTO_250MS);
|
wdt_enable(WDTO_250MS);
|
||||||
|
|
@ -108,6 +116,13 @@ void bootloader_jump_after_watchdog_reset(void)
|
||||||
MCUSR &= ~(1<<WDRF);
|
MCUSR &= ~(1<<WDRF);
|
||||||
wdt_disable();
|
wdt_disable();
|
||||||
|
|
||||||
|
#ifndef NO_BOOTLOADER_CATERINA_BOOTKEY
|
||||||
|
// Clear bootkey of Caterina bootloader for other bootloaders
|
||||||
|
// Leonardo and Pro Micro with Arduino default fuse setting don't reach here
|
||||||
|
// because bootloader section are executed before application everytime.
|
||||||
|
*(volatile uint16_t *)0x0800 = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
// This is compled into 'icall', address should be in word unit, not byte.
|
// This is compled into 'icall', address should be in word unit, not byte.
|
||||||
((void (*)(void))(BOOTLOADER_START/2))();
|
((void (*)(void))(BOOTLOADER_START/2))();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue