Hi Renan
If the watchdog is enabled it should cause a reset on the hardware.
1. Check that the watchdog is really being enabled by stepping through the configuration code. It must do
CWCR = CONFIGURE_WATCHDOG;
which, when expanded, is
CWCR = (CWE | WATCHDOG_2_SEC | CWTA | CWTAVA | CWTIF);
fnSetIntHandler(SW_WD_VECTOR, (unsigned char *)_sw_wdog_timeout);
IC_ICR_0_8 = (INTERRUPT_LEVEL_7 | INTERRUPT_PRIORITY_7);
IC_IMRL_0 &= ~(SW_WDG_PIF_INT_L | MASK_ALL_INT);
By connecting a certain input (defined in WATCHDOG_DISABLE()) to ground, the watchdog can be disabled. When debugging it is practical to disable the watchdog.
2. Note that the watchdog in the M5223X is not fool-proof. It relies on an interrupt to actually perform the reset. If for some reason the interrupt doesn't work it will also not reset.
Where are you putting the while(1) {} ?
Is it before the watchdog has been set up?
Is it possible that it is before main interriupts have been activated (although I would expect the NMI to always work)
3. Check that the interrupt (_sw_wdog_timeout()) is arriving, this will perform the reset by using the command:
RESET_RCR = SOFT_RST;
Simple delays can of course be created using loops - the following generates approx. 25ms delay.
volatile unsigned long ulDelay = ((BUS_CLOCK/12000) * 25);
if (iChipSelect == 0) {
while (ulDelay--) {}; // start up delay to ensure SPI FLASH ready {17}
}
However timers are of course much more practical sincne several can operate in parallel and teh code doesn't have to wait in the loop before it can do something else.
Regards
Mark