cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L1 HardFault when returning from WFI only when debugger attached

Glenn Ergeerts
Associate
Posted on June 16, 2017 at 13:33

Hi,

I have the following issue on an stm32l152 (nucleo-l152re):

I want to enter sleep mode and be woken up by the user button interrupt. In the interrupt handler i toggle the LED.

This works as expected when i run the MCU without a debugger attached, the LED toggles.

This does not work when running with a debugger attached (either st-link or JLink): after pressing the button i'm getting a HardFault.

It does work with the debugger attached however when i lower the clock speed.

I tried with HAL_DBGMCU_EnableDBGSleepMode() and looked into flash latency and prefetch but this does not seem to fix this. I'm puzzled by this and don't understand how the debugger can influence the behavior of the MCU in this case.

This can be reproduced by:

- generating a new project for nucleo-152re in CubeMX and setting PC13 to GPIO_EXTI13, all the rest default

- add HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI); before endless loop in main.c

- toggle LED in EXTI15_10 IRQHandler

- running with and without debugger

Thanks for any thoughts/hints!

#sleep-mode #hard-fault #debugger
0 REPLIES 0