cancel
Showing results for 
Search instead for 
Did you mean: 

WFI in run mode causing Hard Fault

alok472
Associate II
Posted on May 18, 2012 at 04:03

hi all,

I want to save power in run mode of mcu (STM32L151)

My timer is running and giving periodic interrupts. My plan is to go to sleep mode when all main loop work is done and then wake up when timer interrupt comes.

strangely, when WFI is called, the mcu goes into hard fault. It does not happen always but quite frequenctly. I see the hardfault when my debugger (Jlink in SWD mode) is connected.

Can this hardfault be because of debugger ?

i have used Sleep mode in other conditions, i dont see any issue...only when doing in main loop...Hardfault comes.Has anyone used entry into SLEEP mode in while(1) loop ?

Thanks for you help 

3 REPLIES 3
John F.
Senior
Posted on May 18, 2012 at 13:10

Have you tried     DBGMCU_Config(DBGMCU_SLEEP, ENABLE);    //Keep debugger connection during SLEEP mode?

DBGMCU_Config() has a long list of possible arguments - check the library documentation.

alok472
Associate II
Posted on May 18, 2012 at 13:38

Hi John ..yes, i have enabled the DBGMCU_Config(DBGMCU_SLEEP, ENABLE); 

Also the RCC for PWR is enabled

RCC_APB1PeriphClockCmd (RCC_APB1Periph_PWR, ENABLE); 

John F.
Senior
Posted on May 21, 2012 at 09:37

You may already know Joseph Yiu's hard fault handler. More info at

http://blog.frankvh.com/2011/12/07/cortex-m3-m4-hard-fault-handler/

Maybe that will help you track down the problem?