To Detect whether the System Reset due to Hard fault

Hi,

I am currently using the nRF52832 MCU and have implemented hard fault handling as follows:
I use the macro APP_ERROR_CHECK(err_code), which, in case of an error, calls the app_error_fault_handler(). Inside this handler, I invoke NVIC_SystemReset() to reset the application.

Now, I need a mechanism to identify if the system reset is due to a Hard fault. My idea is to write a specific flag to internal flash memory within the app_error_fault_handler() to indicate the occurrence of a Hard Fault. Upon startup, the firmware would check this flag to determine if the reset was due to a Hard Fault and alter the code flow accordingly.

Is this a good approach, or are there any recommended alternatives or best practices for implementing such a mechanism on the nRF52832?

Any guidance would be greatly appreciated!

 

Regards,

Meghana

Related