Can't read MCUSR because bootloader resets it to 0
I know this issue stems from the original Caterina bootloader but this is the bootloader I'm using so I'm asking here. My application needs to see what caused a reset in order to properly interact with the USB host, but on line 146 of AnyKey.c, the MCUSR register is immediately reset to 0 after it's read. This renders it impossible to read the reset condition in the application. Can you move that line down to say line 163 or just remove it entirely (if possible) so people can read that register?
Just fork this repo and adjust as you need it to be for your specific application. I will not be changing any of this bootloader code as it was already battle tested to be really secure in all scenarios (like power glitching etc).
I understand. The way I initially proposed doesn't work anyway. After a lot of research, I found the ATmega32 series have a register that isn't used for anything and can be read/written to just like MCUSR. Just before setting MCUSR to 0, you can set GPIOR0 to the MCUSR value and read that in the application as if it was MCUSR. Not really ideal for the standard anykey-bootloader because users would have to know of its existence in the first place. Thanks though!