I'm trying to use gpreg for state across toggles of nRESET. I thought it was working, but when I tested it on hardware without jtag connected it seemed that gpreg was getting reset as well.
Before I go down the path of trying something else, should GPREGRET survive an external reset?
My hardware doesn't have any physical buttons and is glued shut. I'm concerned that during testing firmware builds on production hardware that I might push a some broken application firmware. Without working application firmware, you can't enter dfu mode. The one thing we do have is a reset button (wired to nRESET), so I'm using a range of gpreg values as a 'reboot counter'. Each time the bootloader starts (and the gpreg is <10) I add 1 to the gpreg. If the gpreg is < 10 && > 5, I automatically enter DFU mode. On the app side each time the watchdog timer is updated (from the main loop) I decrement the gpreg. So if you reset the device 6 times in a row (waiting few seconds between resets) it will automatically enter DFU mode.
On a possible related topic, it seems like RESETREAS often doesn't indicate that the WDT triggered the reset. My WDT_IRQHandler either triggers a breakpoint or just spins for the reset to occur. Sometimes when I reset back into the bootloader, POWER_RESETREAS_DOG is set and othertimes it isn't.