Hi All,
I am developing on a CM0+ with functional safety support. The safety manual requires to test some features before activating safety functions; many of these are straightforward while others are "convoluted".
One of the requirements is access to an unimplemented space ad expect the abort to occur. This of course leads to an (expected) Hard Fault exception. My routine in the hard fault handler is able to detect if it is a testor not, and in case of test just set a flag and then exits from the hard fault handler.
As expected, the unstacking of the registers leads to the instruction that triggered the fault, entering in a faulty instruction- hardfault handler- faulty instruction loop.
Now, my idea is to modify the stacked program counter in order to return to the next instruction and going on with the regular program flow.
Many questions here:
Any Hint would be gladly appreciated;
Thanks and best regards,
Hello Trampas,
thanks for your reply. Your approach seems suitable to my use case, using naked functions. Nevertheless, based onthe suggestions of the community, I decided for a slightly different approach: since the hard fault is generated on purpose (I KNOW when and why it happens) I provide the stack pointer value just before launching the fault instruction. Then in the hard fault handler I retrieve this information, subtract the value from the current stack pointer and I am then able to understand the offset value toa dd to the current stack pointer to retrieve the PC: SP + offset +0x18.
What happens when/if the processor gets a real Hard Fault, ie not one generated by test code?