Skip to main content
Visitor II
February 15, 2024
Question

STM32F030 hardfault only during debug mode

  • February 15, 2024
  • 3 replies
  • 886 views

Hi, I'm getting a hard fault on MX_TIM1_Init() but only during debug sessions. When I set a breakpoint after initialization, then I can step through and everything works. Why is this happening? 

    This topic has been closed for replies.

    3 replies

    Super User
    February 15, 2024

    > Why is this happening? 

    -> You do something wrong. 

    Super User
    February 15, 2024

    It's difficult to provide a useful response with such limited information.

    Stay objective. The first step would be to look at where the hard fault happens. Use a hard fault monitor to understand why it is happening.

    Avoid the temptation to think that if an error doesn't occur, then the program is correct. Or to somehow believe that because it sometimes runs, the problem must be with something other than the code. If something isn't working, the most common culprit is the code. The second most common is the hardware (bad power supply, bad schematic design, improper assembly/soldering, etc.). Everything else is much less likely.

    Graduate II
    February 15, 2024

    Have the Hard Fault Handler output actionable data. Dumping registers and state.

    Perhaps the IRQ Handler, or HAL, has expectations that the instance is fully initialized, via MSP, or wherever, prior to the IRQ firing?

    CM0(+) also more fussy about memory access alignments.