Hello,
How are are you?
I am having a problem configuring the RTWDOG, as described below:
Sometimes in rtwdog initialization the code become stuck in the function RTWDOG_Unlock() waiting for the ULK flag (when ULK is 1 rtwdog is unlocked) to change from 0 to 1 ( Code below). This happens in the call to RTWDOG_Unlock() inside RTWDOG_Init(). This problem dot not always happen. Sometimes the code works for days and then after a reset it becomes stuck.
//In RTWDOG_Unlock. Sometimes code becomes stuck here after reset.
while ((base->CS & RTWDOG_CS_ULK_MASK) == 0U)
{
}
From the RT1050 reference manual i know that the rtwdog need to be configured in 255 bus cycles after reset. I am also using some parts from the rtwdog sdk (v2.9.1) example. The code that i am using is show below. I call the wdog_Init() inside SystemInitHook() to init rwdog configs close to reset. This code is the first to run on my application after startup.
//In file wdog.c
#define BSP_WDOG_CLK_FREQ 32768U
#define BSP_WDOG_TIMER_PRESC 256
#define DELAY_TIME 100000U
void wdog_Init(void)
{
CLOCK_EnableClock(kCLOCK_Wdog3);
/* @brief : Recommendation delay from NXP. Without that,
* wdog can not be configured.
*
* @note Example note NXP:
* When system is boot up, WDOG32 is disabled.
* We must wait for at least 2.5
* periods of wdog32 clock to reconfigure wodg32.
* So Delay a while to wait for
* the previous configuration taking effect.
*
*/
for (uint32_t temp = 0; temp < DELAY_TIME; temp++)
{
__NOP();
}
static rtwdog_config_t wdogConfig;
RTWDOG_GetDefaultConfig(&wdogConfig);
wdogConfig.enableUpdate = true;
wdogConfig.workMode.enableDebug = false;
wdogConfig.prescaler = kRTWDOG_ClockPrescalerDivide256;
wdogConfig.timeoutValue = msec2WdogCount(WDOG_TIMEOUT_ms,
BSP_WDOG_CLK_FREQ,
BSP_WDOG_TIMER_PRESC);
RTWDOG_Init(BSP_WDOG_TIMER, &wdogConfig); //The stuck problem happens here.
}
//In file main.c
/**
*
* @brief This function is called in SystemInit()at system_MIMXRT1052.c
* and is to be used to init things close to reset.
*
*/
void SystemInitHook (void)
{
wdog_Init();
}
Probably i am doing something wrong, but was not able to figure it out. Can you help me?
Thanks,
João Paulo