-
Notifications
You must be signed in to change notification settings - Fork 338
Description
Hey there, I'm working on getting BOOTRST and reset source detection working for entering bootloader on a qmk based keyboard qmk#5
In that process, I noticed that the example given here: http://www.fourwalledcubicle.com/files/LUFA/Doc/120730/html/_page__software_bootloader_start.html
and the check in BootloaderDFU.c seem to be opposit of each other:
lufa/Bootloaders/DFU/BootloaderDFU.c
Lines 136 to 154 in 6d90773
| if (!(BootloaderAPI_ReadFuse(GET_HIGH_FUSE_BITS) & ~FUSE_BOOTRST)) | |
| { | |
| /* If the reset source was not an external reset or the key is correct, clear it and jump to the application */ | |
| if (!(MCUSR & (1 << EXTRF)) || (MagicBootKey == MAGIC_BOOT_KEY)) | |
| JumpToApplication = true; | |
| /* Clear reset source */ | |
| MCUSR &= ~(1 << EXTRF); | |
| } | |
| else | |
| { | |
| /* If the reset source was the bootloader and the key is correct, clear it and jump to the application; | |
| * this can happen in the HWBE fuse is set, and the HBE pin is low during the watchdog reset */ | |
| if ((MCUSR & (1 << WDRF)) && (MagicBootKey == MAGIC_BOOT_KEY)) | |
| JumpToApplication = true; | |
| /* Clear reset source */ | |
| MCUSR &= ~(1 << WDRF); | |
| } |
It seems the example uses the magic key to enter the bootloader, while the bootloader uses it to exit the bootloader.
Additionally, it seems with this check, if using BOOTRST fuse, that the only way to enter bootloader is through an external reset, and not reachable via a watchdog timer reset.
Am I correct in assuming that this is not the intended behavior?
As I read the code DFU bootloader, the magic key is used to exit the code, which is fine, however in that case I think the mentioned check should be changed to:
if(MCUSR & (1 << PORF) || MCUSR & (1 << BORF) || (MagicBootKey == MAGIC_BOOT_KEY))
JumpToApplication = true;
MCUSR &= ~((1 << PORF) & (1 << BORF));I have opened a PR with a suggestion on this solution. Here: #151