Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to use hardfault exception library ?

Hi,

I'm using nrf52832 and sdk14.2 and need to handle hardfaults in my code. From what I've found on the forums and infocenter, I need to modify the "void HardFault_process(HardFault_stack_t * p_stack);" function in hardfault_implementation.c file. By default it resets the chip. So to test this function I enabled the hardfault_handler_enabled macro in sdk_config.h and generated a hard fault using following code.

int* ff = 0x80000000;
*ff = 3;

Now i get the error, but the system doesn't reset as it should acc. to the default implementation.

To further debug, i put a breakpoint inside "void HardFault_c_handler(uint32_t * p_stack_address)" function in hardfault_implementation.c file, but this function never gets called. So the hardfault library is not working properly. Is there anything that I'm missing here ?

Also, I tried to use following functions in my main.c, to generate hardfaults for testing, but i get "undefined reference" errors while compiling ?

hardfault_genhf_invalid_fp

hardfault_genhf_undefined_instr

hardfault_genhf_ldm_align

So, what am i doing wrong here ?

Parents Reply
  • Hi,

    I've replicated the behavior you saw with hardfault_genhf_invalid_fp(). The softdevice should forward hardfault exceptions to the application, which it's not working in this particular case. The forwarding mechanism triggers another hardfault inside the fault handler that leads to a CPU lockup reset. This has been reported as a bug internally.  Note that lockup reset is disabled while the device is in debug interface mode, that is why the program hangs inside the softdevice when you try to debug it (lockup reset). 

    "Also, how did you know the program is stuck in soft device's handle"

    It was based on the CPU registers from your screenshot: 

    Here's the example I used for test:

    ble_app_hrs_hf_test.zip

Children
Related