Skip to main content
SimonF
Senior
November 3, 2020
Question

STM32 MCU stucks after power cut-off

  • November 3, 2020
  • 5 replies
  • 2077 views

Here is my process :

  • I supply my board with an USB cable.
  • Then I flash my stm32L4 with a segger / st-link.
  • My firmware goes in shutdown mode.
  • I unplug the USB cable. Thus the power is suddently off.
  • After that, I wire a battery to my device. Thus the MCU is powered.

In most of the case (90%), the device wakes up once the battery is wired (normal behaviour). However in some cases, the device does not wake up at all (Voltage is OK).

I'm using IWDG, thus MCU should restart if stuck. But in this case device seems totally stuck in the Reset_Handler (quite sure it is here). I need to pull down the NRST to GROUND to unstuck the device.

Is this because of the power cut-off ?

Can I add some firmware feature to avoid this behaviour ?

Note : quite similar problem but closed without reply : https://community.st.com/s/question/0D50X00009XkXkoSAF/stm32f410-freeze-after-power-supply-failure-of-70-ms-watch-dog-doesnt-reset-

This topic has been closed for replies.

5 replies

TDK
November 3, 2020

If the code is getting into Reset_Handler (how do you know?), you need to find out why it's getting there and correct the issue. It could be prior to the IWDG being enabled. It could be your voltage/wait state setting is causing issues. You can attach a debugger without resetting the device to inspect the chip.

Disabling power suddenly should not cause this problem, especially if BOR is enabled.

"If you feel a post has answered your question, please click ""Accept as Solution""."
SimonF
SimonFAuthor
Senior
November 3, 2020

Thank you for your reply @TDK​ .

I did attach a segger (and a st-link) on 2 devices with this issue (without resetting ofc) . When attached, the code was paused in the startup file in the Reset_Handler :

.section	.text.Reset_Handler
	.weak	Reset_Handler
	.type	Reset_Handler, %function
Reset_Handler:
 ldr sp, =_estack /* Atollic update: set stack pointer */
 
/* Copy the data segment initializers from flash to SRAM */
 movs	r1, #0
 b	LoopCopyDataInit
 
CopyDataInit:
	ldr	r3, =_sidata
	ldr	r3, [r3, r1]
	str	r3, [r0, r1]
	adds	r1, r1, #4
 
LoopCopyDataInit:
	ldr	r0, =_sdata
	ldr	r3, =_edata
	adds	r2, r0, r1
	cmp	r2, r3
	bcc	CopyDataInit
	ldr	r2, =_sbss
	b	LoopFillZerobss
/* Zero fill the bss segment. */

Then I moved in the firmware step by step. The code went in the Loop here above. Thus, I clicked on resume and my device woke up "alone".

(By the way, when I was attached, IDE said that I had no Hard Fault error)

What do you mean by "it could be prior to the IWDG being enabled" ?

MM..1
Chief III
November 3, 2020

Maybe on flashing you use lock MCU to LEVEL 1 . You write about unplug USB, but is unpluged too STLINK?

After set RDP full power down is required. But maybe you dont use RDP, then ...

Is guaranteed full power down before attach bat?

SimonF
SimonFAuthor
Senior
November 25, 2020

Hello @MM..1​ , sorry to reply that late, I did not have the time to test further.

  • I'm not using (yet) RDP or any locking feature for the MCU.
  • STLINK is unpluged long before USB is unpluged.
  • There is no power system when the battery is wired.
Sdvfg.1
Visitor II
January 20, 2021

you can see some of these solution here on braces there are so many solution about these problems that you are also facing i got it when received the problem in my device my friend recommends this website you can see on the above side.