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:


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:

and or 

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

What could be the reason for this?

  • 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

  • Hi,

    Unknown function at 0x00000A60

    0x00000A60 is the hardfault exception handler inside the MBR. It's normally forwarded to the main application, but will get trapped if breakpoint on hardfault is enabled in SES.
    You can disable it like this: