2021-11-15 06:12 AM
Hi everybody,
I'm sorry for poor English.
I'm using STM32F407VET6 in my board and I set up watchdog timer. However sometimes microcontroller hangs . Here is the main loop of my code:
while(TRUE)
{
// ======================================
clearWatchDog();
// ======================================
if (bRunTimingTask)
{
runTimingTask();
bRunTimingTask = FALSE;
}
// ======================================
if (bRunFlashModeTask)
{
runFlashModeTask();
bRunFlashModeTask = FALSE;
}
// ======================================
if (bRunGuiTask)
{
runGuiTask();
bRunGuiTask = FALSE;
}
// ======================================
if (bReadAdc)
{
ReadADCData();
bReadAdc = FALSE;
}
// ======================================
if(bSystemLogic)
{
SystemLogic();
bSystemLogic = FALSE;
}
}
First question is: why the watchdog timer doesn't reset the uController?
The flag bRunTimingTask is set in Systick interrupt routine every 10ms and the other flags like bSystemLogic, bReadAdc, bRunGuiTask, .. are set inside the runTimingTask() function.
The second question is: Is it possible that the Systick Interrupt be disabled suddenly and unwanted because of noise or other reasons?
Thanks
2021-11-15 06:19 AM
> First question is: why the watchdog timer doesn't reset the uController?
Make sure it's enabled. Enable it, then set an infinite loop and ensure it resets. If it doesn't, examine the IWDG/WWDG registers to determine why it's not working.
> The second question is: Is it possible that the Systick Interrupt be disabled suddenly and unwanted because of noise or other reasons?
It's certainly possible to have bugs in your program that would cause systick to not be run, but it's not something that will happen spontaneously.
In general, debug your program, hit pause when you think something should happen but isn't, and see where the cpu is at, examine registers to see why things aren't working as expected.
2021-11-15 06:30 AM
Thank you for your attention TDK
I'm sure that the Watchdog is enabled and tested int before.
I think the Systick interrupt does not run and so the flag bRunTimingTask never becomes high and so do the other flags, because they are set inside the runTimingTask() function. I checked my program several times and I didn't find anything wrong. I'm really confused.
2021-11-15 07:02 AM
2021-11-15 07:14 AM
I think the while loop working, and so the watchdog timer reset each time clearWatchDog() executed, however because the systick interrupt doesn't run, none of the functions executed(bRunTimingTask never become high) and it seems like uController hangs.
2021-11-15 07:41 AM
2021-11-15 10:07 AM
Simply move
while(TRUE)
{
// ======================================
// ======================================
if (bRunTimingTask)
{
clearWatchDog();
runTimingTask();
bRunTimingTask = FALSE;
}
// ======================================
if (bRunFlashModeTask)
{
runFlashModeTask();
bRunFlashModeTask = FALSE;
}
// ======================================
if (bRunGuiTask)
{
runGuiTask();
bRunGuiTask = FALSE;
}
// ======================================
if (bReadAdc)
{
ReadADCData();
bReadAdc = FALSE;
}
// ======================================
if(bSystemLogic)
{
SystemLogic();
bSystemLogic = FALSE;
}
}
2021-11-15 10:40 AM
Does your board *drive* NRST High externally? A GPIO from another part, or tied to VCC ?
2021-11-15 10:32 PM
As I said before, the bRunTimingTask flag set in the systick interrupt routine and the other flags in the runTimingTask() function. So if the systick interrupt doesn't run, none of the functions are executed.
the flags are declared as volatile.
2021-11-15 10:32 PM
Thank you, I will try this today.