Skip to main content
mh2
Associate III
November 15, 2021
Question

STM32F407 hang and watchdog doesn't reset

  • November 15, 2021
  • 6 replies
  • 4402 views

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

This topic has been closed for replies.

6 replies

TDK
November 15, 2021

> 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
mh2Author
Associate III
November 15, 2021

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.

TDK
November 15, 2021
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
mh2Author
Associate III
November 15, 2021

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.

MM..1
Chief III
November 15, 2021

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

mh2
mh2Author
Associate III
November 16, 2021

Thank you, I will try this today.

Tesla DeLorean
Guru
November 15, 2021

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

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
mh2
mh2Author
Associate III
November 16, 2021

Hi Tesla DeLorean, The NRST pin pulled high externally with 10K ohm resistor.

mh2
mh2Author
Associate III
November 16, 2021

Hello again,

I have one more question: Is it possible that the STM32F407 booted form system memory(which is used for programming by embedded bootloader) spontaneously because of the noise?

The big problem is that this situation is only happens occasionally, not always.

Thanks

waclawek.jan
Super User
November 16, 2021

How is BOOT0 pin connected?

JW

mh2
mh2Author
Associate III
November 17, 2021

BOOT0 is pulled down with a 10K ohm resistor.

After several days I didn't get any result. Board working normally in lab, in the factory, working for several hours and suddenly all the hangs.

I'm really confused.

MM..1
Chief III
November 17, 2021

Hang with moved code clear? How clock use your design HSI or HSE? When HSE maybe your crystal fails. Try use HSI.