Implement a hard fault handler that reports the stacked registers. The PC register will indicate the execution address at which the exception occurred.
An example can be found here, though the use of printf
in the example is probably ill-advised; you'd want something that wrote unbuffered direct to the UART I'd suggest - the system is already broken - the less code needed to get the diagnostic out the better. The similar solution here simply copies the values to variables and requires you to set a breakpoint in your debugger to inspect them.
To see the code at the reported PC address, either consult your compiler's map and or list output files, or enter the address directly into the PC register in your debugger.