cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F407 hang and watchdog doesn't reset

mh2
Associate III

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

17 REPLIES 17
TDK
Guru

> 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.

If you feel a post has answered your question, please click "Accept as Solution".
mh2
Associate III

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.

The IWDG is unlikely to have a hardware flaw, so I would focus on why you think it’s not being reset and verifying the assumptions made that got you there. There isn’t much presented in this post that would prove it isn’t working.
If you feel a post has answered your question, please click "Accept as Solution".
mh2
Associate III

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.

Why do you think systick isn’t running? If you set a breakpoint there, does it get hit?
Are flags modified in the ISR declared as volatile?
If you feel a post has answered your question, please click "Accept as Solution".
MM..1
Chief III

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;
	      }
	      
     }

Does your board *drive* NRST High externally? A GPIO from another part, or tied to VCC ?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
mh2
Associate III

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.

mh2
Associate III

Thank you, I will try this today.