cancel
Showing results for 
Search instead for 
Did you mean: 

HardFault Handler not being executed

PaoloValentino
Associate II

When a HardFault occurs, the program jump to HardFault_Handler function but it is not being executed.

I'm usen STM32CubeIde, when I'm in debugging session, the arrow is stuck in the name of the function but nothing more happens: checkFault(); is not executed.

void HardFault_Handler(void)
{
  /* USER CODE BEGIN HardFault_IRQn 0 */
  checkFault();
  /* USER CODE END HardFault_IRQn 0 */
  while (1)
  {
    /* USER CODE BEGIN W1_HardFault_IRQn 0 */
    /* USER CODE END W1_HardFault_IRQn 0 */
  }
}

Something wrong in de startup file? Any idea of what I'm missing?

Thanks.

2 REPLIES 2
SBEN .2
Senior II

Hello @PaoloValentino​ ,

checkFault() could've been optimized by the compiler if it has no side-effect. Try setting the optimization level to 0 and do another test.

Best regards,

@SBEN .2​ 

TDK
Guru

Check the disassembly to see what's actually going on.

Reduce optimization settings, or make things in checkFault volatile if it's being optimized out.

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