How do I enable the WatchDog/COP? MKL27Z256

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How do I enable the WatchDog/COP? MKL27Z256

Jump to solution
1,245 Views
ericbergstedt
Contributor II

I am using MKL27Z256, 32 pin.

cop_config_t cop_config;

COP_HAL_Init( SIM );
cop_config.copClockSource = kCopLpoClock;
cop_config.copDebugModeEnable = false;
cop_config.copStopModeEnable = false;
cop_config.copTimeout = kCopTimeout_short_2to10_or_long_2to18;
cop_config.copTimeoutMode = kCopShortTimeoutMode;
cop_config.copWindowModeEnable = false;
COP_HAL_SetConfig( SIM, &cop_config );
COP_HAL_Enable();
COP_HAL_Refresh( SIM );

I have this code starting up late after I initialized my entire program. For some reason, I cannot get the COPC register in the SIM module to reflect the changes made above. When I'm in the debug mode and monitoring the SIM module, COPC registers are never changed and stay at 0. I cannot manually change these values within the debugger either, they instantly snap back to zero.

When I'm out of debug mode and lock the main() application, the COP never resets the system.

Is there a special sequence that I must do to modify these values? Any help would be appreciated. I am using KSDK1.3 and using the HAL layer only.

Labels (1)
1 Solution
803 Views
ericbergstedt
Contributor II

To enable the watchdog I had to add the follow type define to my Preprocessor Symbols

DISABLE_WDOG=0

Inside of SystemInit() there is a define that will automatically disable the watch dog by default.

Inside of "system_MKL27Z4.h"

There exists this little bit of code

#ifndef DISABLE_WDOG
#define DISABLE_WDOG 1
#endif

Then inside of "startup_MKL27Z4.h"

void SystemInit (void) {

#if (DISABLE_WDOG)
/* SIM->COPC: ?=0,COPCLKSEL=0,COPDBGEN=0,COPSTPEN=0,COPT=0,COPCLKS=0,COPW=0 */
SIM->COPC = (uint32_t)0x00u;
#endif /* (DISABLE_WDOG) */

}

Writing to the Watchdog/COP is a write once register from start up, the above code will take up that one time write far before your application will have a chance to write to it.

This function is called by the Reset_Handler inside of "startup_MKL27Z4.s", which is called before the program even reaches main().

View solution in original post

2 Replies
804 Views
ericbergstedt
Contributor II

To enable the watchdog I had to add the follow type define to my Preprocessor Symbols

DISABLE_WDOG=0

Inside of SystemInit() there is a define that will automatically disable the watch dog by default.

Inside of "system_MKL27Z4.h"

There exists this little bit of code

#ifndef DISABLE_WDOG
#define DISABLE_WDOG 1
#endif

Then inside of "startup_MKL27Z4.h"

void SystemInit (void) {

#if (DISABLE_WDOG)
/* SIM->COPC: ?=0,COPCLKSEL=0,COPDBGEN=0,COPSTPEN=0,COPT=0,COPCLKS=0,COPW=0 */
SIM->COPC = (uint32_t)0x00u;
#endif /* (DISABLE_WDOG) */

}

Writing to the Watchdog/COP is a write once register from start up, the above code will take up that one time write far before your application will have a chance to write to it.

This function is called by the Reset_Handler inside of "startup_MKL27Z4.s", which is called before the program even reaches main().

803 Views
albert_zhou
Contributor III

Yes very helpful, The code line DISABLE_WDOG=0 will get warning message. I add a line in the file system_MKL27Z644.H right below #include <stdint>:

#include <stdint.h>


#define DISABLE_WDOG   0  //added  for use watchdog timer

#ifndef DISABLE_WDOG
#define DISABLE_WDOG 1
#endif

0 Kudos