Search code examples
cembeddedeclipse-cdtstm32openocd

Eclipse/GDB: How to set an automatic breakpoint after hardware reset?


I am using a self-built embedded IDE with Eclipse and GDB - pretty much what this website describes: https://gnu-mcu-eclipse.github.io/

When I use OpenOCD or any other Debug Config (like SEGGER JLink) to flash my STM32F407 hardware, it breaks at the first line of my main.c. Nothing unusual.

// ----- main() ---------------------------------------------------------------
int main(void)
{

    //Initialization, if unsuccessful -> quit
    if (!INIT_bInit())
        return 0;

    //infinite Loop
    while (0x1337)
    {
        //Nothing
    }

    //Must not end here
    return 0;
}

//main() 

This might be due to the behaviour setup in the Eclipse OpenOCD debug console.

However, I'd like to have an automatic breakpoint mecahnism as well which halts the program in case there is a

  • hard fault or a
  • hardware reset

As my software generally bases on automatic tasks with void function pointers, I'd like to know when there is a hardfault occurring due to a problem with the function to be called,

But as of now, the only time I notice a HardFault is when I pause my program after a while and check if it ends up in my (custom) Default_FaultHandler (which implements the HardFault_Handler and others).

void Default_FaultHandler(void)
{
  while(0xDEAD){} 
}

Same thing with hardware reset. No indication, not even an automated (re-)break at main.c.

I know from eclipse-based IDEs like NXP's MCUXpresso or Atollic Studio that it is possible to automatically break the program when any fault handler or a hardware reset is called.

Any ideas on how to automate the debugging behaviour with my own-built OpenOCD/Eclipse solution?

Your help is warmly welcome

Cheers

-Henni


Solution

  • If you want to place breakpoint in the suspiciuus function or handler just use

    __BKPT();
    

    or if you do not use ARM CMSIS just

    #define __BKPT(value)                       __ASM volatile ("bkpt "#value)
    

    Example:

    void Default_FaultHandler(void)
    {
      __BKPT();
      while();
    }
    

    When this intrinsic is hit, your debugger will take the controll :)