Catch HardFault

I am using the Nordik SDK 17 and want to capture all soft and hardware faults.

In the sdk_config.h I set:

#define HARDFAULT_HANDLER_ENABLED 1

I was able to implement (override) the app_error_handler and app_error_fault_handler. But adding HardFault_process and HardFault_Handler to the same app_error_handler_gcc.c file seems not to work.

When creating a test function like:

uint16_t stackcnt = 0;
void simulate_stack_crash(void)
{
    stackcnt++;
    simulate_stack_crash();
}

and or 

int illegal_instruction_execution(void) 
{
  int (*bad_instruction)(void) = (void *)0xE0000000;
  return bad_instruction();
}

will stop the attached Segger studio debugger, but neither one of the routines is ever called.

What could be the reason for this?

Parents
  • Hi,

    When adding the HardFault handling library to your project

    Add these to your projects:

    $(SDK_ROOT)/components/libraries/hardfault/hardfault_implementation.c 
    $(SDK_ROOT)/components/libraries/hardfault/nrf52/handler/hardfault_handler_gcc.c  (variant here depends on your toolchain)

    And set HARDFAULT_HANDLER_ENABLED to 1 in sdk_config.h, and add DEBUG_NRF in your preprocessor definitions

  • Hi Sigurd,

    I had the lib already added to the project, the HARDFAULT_HANDLER_ENABLED is set in skf_config.h and app_config.h. The preprocessor define DEBUG_NRF was set. Running the program in Segger studio (debug mode) resulted in Unknown function at 0x00000A60

    I am unable to set a breakpoint in the HardFault_process (looks like no code is generated here, optimization is set to off). HardFault_Handler is not called.
    Is there anything else I forgot to set?

    Regard,
    Bob

Reply
  • Hi Sigurd,

    I had the lib already added to the project, the HARDFAULT_HANDLER_ENABLED is set in skf_config.h and app_config.h. The preprocessor define DEBUG_NRF was set. Running the program in Segger studio (debug mode) resulted in Unknown function at 0x00000A60

    I am unable to set a breakpoint in the HardFault_process (looks like no code is generated here, optimization is set to off). HardFault_Handler is not called.
    Is there anything else I forgot to set?

    Regard,
    Bob

Children
Related