Detect Watchdog Restarted App

Here is my old .NETMF STM32 code for detecting the watchdog fired and restarted the App. I use it to detect whether the watchdog restarted the App or the user power cycled the device. Is there any chance you could add it to TinyCLR’s Watchdog class or give us a Register class so we can do it ourselves?

private const UInt32 PERIPH_BASE = 0x40000000;
private const UInt32 RCC_BASE = PERIPH_BASE + 0x23800;  // 
private static Register RCC_CSR = new Register(RCC_BASE + 0x74);
private static UInt32 IWDGRSTF = 1 << 29; // bit 29
private static UInt32 RMVF = 1 << 24; // bit 24


UInt32 RccCsr = RCC_CSR.Read();

if ((RccCsr & IWDGRSTF) != 0)
{
	RCC_CSR.SetBits(RMVF); // Clear reset flags
	return true; // watchdog fired
}
else
	return false;

What about using RLP?

I see watchdog is allowed in Register class (IWDG1), so it should work. Just try it quickly, if it doesn’t as you wanted, then let us know

Note that register address, bit define maybe different. Assessing Register requires you to check datasheet.

I don’t see a Register class in TinyCLR. Am I missing something?

GHI already provides the reason for the last reset:

using GHIElectronics.TinyCLR.Native;
...
if (GetResetSource() == ResetSource.WatchdogReset){
// your code
}

Is there any need to come up with anything else?

1 Like

Perfect, exactly what I need. Thanks.