Hello,
I'm using a Kinetis KM33Z128A5 serie Microcontroller, Codewarrior 10.6 and Baremetal drivers.
However, I can't enable in proper way the watchdog.
I just copied the example, in the baremetal drivers:
/* enable clocks to all on chip peripherals | */ | |
SIM_Init (SIM_MODULE_ALL_PERIPH_ON_CONFIG); |
// Watchdog Init | ||
/* Watchdog timeout is of 1.5 sec approximately | */ | |
WDOG_Init(WDOG_MODULE_NORMAL_STOP_DI_DBG_DI_CONFIG(WDOG_LPO_CLK,WDOG_DIV1,1500)); |
But the watchdog doesn't start, neither in debug mode, nor in normal mode. I can see that it is working only if I put a breakpoint on the WDOG_Init instruction, when I see that the successive instruction is a reset.
I tried to watch the register, and what I see is that the WDOG_STCTRLH is kept at the value of 0x0152 no matter what I put in the WDOG_Init arguments. Also, after the reset this value is 0x0153.
Any ideas?
The watchdog register COP is a Write-Once register.
Check in the early startup files to see if it is being disabled there.
Sadly almost all startup's I've looked at do this. :-(
See how I handle this in my vectors.c below.
Until watchdog_init() is defined in some other file the watchdog will be disabled.
When I'm ready to turn the watchdog on I add a watchdog.c/.h that does The Right Stuff in watchdog_init().
In vectors.c (the first file run, gcc compiler):
void watchdog_init( void ) __attribute__ ((weak, alias("watchdog_turn_off")));
static void watchdog_turn_off( void ); /* The watchdog register may only be written to a single time after reset. Default to turning it off */
static void watchdog_turn_off( void ) /* Make sure to override this in a real shipping product. Also account for Bootloader, in MKL43/MKL27 etc, turned it off so need to from Flash */
{
SIM_COPC = 0U; /* Disable the watchdog timer */
}
void _reset_init(void)
{
irq_disable(); /* Did bootloader leave IRQs on perhaps? */
SCB_VTOR = (uint32_t) interrupt_vector_table;
sync_barrier_data();
/*
* The watchdog and power mode registers may only be written to a single time after
* reset. Default to turning it off. Override these function in a
* shipping product if needed:
*/
watchdog_init();
...
}
Hi Mattia,
I'd highly recommend that you can refer to the WDOG driver demo which be included in the KSDK 1.3 and the demo is reside in ~\KSDK_1.3.0\examples\twrkm34z75m\driver_examples\wdog\iar.Please go to download the KSDK 1.3 through the link as below.
Hope it helps.
Have a great day,
Ping
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------