cortex-mfault

Hardfault on Cortex M0 cannot be tracked down


I am having really hard time trying to track down an hardfault happening randomly on my nrf51822 board.

I am able to pin a breakpoint on the hardfault handler, but the stack info is not much useful. I can step debug around the instruction causing the hardfault and there's absolutely nothing there that could trigger such fault. In the example below, PRstrcpy is just a copy between two absolutely legit addresses. Other symptoms:

Any ideas for the debug?

Here follows a stack trace:

Thread #1 <main> (Suspended : Breakpoint)   
    HardFault_Handler() at 0x34976  
    <signal handler called>() at 0xfffffff9 
    PRstrcpy() at kcs_stdlibs.c:94 0x1aa66  
    PrintConfigInfo() at Startup.c:36 0x15256   
    0xfffffffe  

Solution

  • I found the problem in my case, it was something different and difficult to debug. I had some flash write instructions around, which would overwrite upper flash areas. Only when using low optimization values, these flash area hosted legit instructions. So my code was modified on the fly, while running.