I want to reconfigure the watchdog of the S32K144 after it has been disabled in the startup script. In the startup script there is following section that disables the watchdog:
/**************************************************************************/
/* WDOG DISABLE*/
/**************************************************************************/
#if (DISABLE_WDOG)
/* Write of the WDOG unlock key to CNT register, must be done in order to allow any modifications*/
WDOG->CNT = (uint32_t ) FEATURE_WDOG_UNLOCK_VALUE;
/* The dummy read is used in order to make sure that the WDOG registers will be configured only
* after the write of the unlock value was completed. */
(void)WDOG->CNT;
/* Initial write of WDOG configuration register:
* enables support for 32-bit refresh/unlock command write words,
* clock select from LPO, update enable, watchdog disabled */
WDOG->CS = (uint32_t ) ( (1UL << WDOG_CS_CMD32EN_SHIFT) |
(FEATURE_WDOG_CLK_FROM_LPO << WDOG_CS_CLK_SHIFT) |
(0U << WDOG_CS_EN_SHIFT) |
(1U << WDOG_CS_UPDATE_SHIFT) );
/* Configure timeout */
WDOG->TOVAL = (uint32_t )0xFFFF;
#endif /* (DISABLE_WDOG) */
If later on i try to reconfigure the watchdog which should be possible because the Allow Updates field of the Watchdog Control and Status Register is set, the watchdog configuration does not change. I use the following code:
DISABLE_INTERRUPTS()
WDOG->CNT = 0xD928C520U; // Unlock watchdog
while (!(WDOG->CS & WDOG_CS_ULK_MASK) != 0u)
; // Wait for wdog to be unlocked
WDOG->WIN = 0x0000;
WDOG->TOVAL = 50;
WDOG->CS |= (WDOG_CS_CLK_MASK & (1 << WDOG_CS_CLK_SHIFT));
WDOG->CS |= WDOG_CS_INT_MASK;
WDOG->CS |= WDOG_CS_EN_MASK;
while (!((WDOG->CS & WDOG_CS_RCS_MASK) != 0u))
; // Wait for config to be changed
ENABLE_INTERRUPTS()
If I enable the watchdog on startup with this code:
/* Write of the WDOG unlock key to CNT register, must be done in order to allow any modifications*/
WDOG->CNT = (uint32_t ) FEATURE_WDOG_UNLOCK_VALUE;
/* The dummy read is used in order to make sure that the WDOG registers will be configured only
* after the write of the unlock value was completed. */
(void)WDOG->CNT;
/* Initial write of WDOG configuration register:
* enables support for 32-bit refresh/unlock command write words,
* clock select from LPO, update enable, watchdog disabled */
WDOG->CS = (uint32_t ) ( (1UL << WDOG_CS_CMD32EN_SHIFT) |
(FEATURE_WDOG_CLK_FROM_LPO << WDOG_CS_CLK_SHIFT) |
(1U << WDOG_CS_EN_SHIFT) |
(1U << WDOG_CS_UPDATE_SHIFT) );
/* Configure timeout */
WDOG->TOVAL = (uint32_t )0xFFFF;
I can reconfigure it later with the same reconfiguration code above. Is reconfiguration only possible when the watchdog is enabled?
The WDOG stays unlock for just 128 BUS_CLK cycles.
You need to make sure the CS register gets written within the window.
Regards,
Daniel