This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

NRF52840 app - random hard fault

Hi,

My application has hard faults sometimes, and I'm trying to figure out the reason.

When it occurs - I have a hard fault log, but p_stack->pc is 0. I can't understand what is the problematic code line.

Do I have another ways to catch the issue?

Thanks!

Parents Reply
  • Roei said:
    In addition - the hard fault occurs in a specific function

     Is this a function from a Nordic solution? Which function is it?

     

    Roei said:
    When testing performance of this function - I've noticed that CPU usage of one of the services if very high (about 800%).

    the percentage of CPU usage should not be the reason for the hardfault. It might be the memory usage by that function. But if you know the function that causes this hardfault, then you can step in and debug to see which line exactly causes this. If this function is from the the Nordic solution (SDK) then i might be able to help you debug it if you help me reproduce it at my desk.

Children
  • It's not a function from the SDK of Nordic solution - it's a new function which make a lot of job - writing and erasing a lot of pages from an external flash (using SPI protocol).

    Already tried to debug and didn't find any specific line. It is also occurs not very often.

  • Roei said:
    It's not a function from the SDK of Nordic solution - it's a new function which make a lot of job - writing and erasing a lot of pages from an external flash (using SPI protocol).

     In that case, this memory corruption is hard to track from our side as these seems to be introduced with your changes. And with the minimal information given and no way to reproduce on our end, it is very hard for me to narrow down the problem for you.

  • Hi,

    Can you please tell me where can I increase beffurs size in sdk_config.h?

    Thanks!

  • Maybe the issue is with an interrupt allocating too much stack space by using (say) a print buffer inside the interrupt, so the interrupt generates the hard fault in "random" foreground code locations since the buffer is allocated on the stack in the interrupt before the interrupt code executes, which generates another hard fault interrupt. This probably only happens under worst-case stack usage scenarios, so rare. This is what Susheel is driving at, I think.

    "Pointer to the stack bottom. This pointer might be NULL if the HardFault was called when the main stack was the active stack and a stack overrun is detected. In such a situation, the stack pointer is reinitialized to the default position, and the stack content is lost."

    In such a case, examine all interrupt (event) handlers and remove any buffers and instead set a flag and process in (say) the main loop.

    A second (classic) scenario is that a function allocates a local buffer on the stack using a variable parameter as the size of the stack; IAR would warn against that but SES does not. If the is an error in that parameter then the stack blows up. No good checking the parameters since the stack blows up before the parameters can be checked. Some of the TWI example code has this "feature" (or used to).

  • Hi,

    Thanks for your help!

    The hard fault occurs in a function which has a lot of external flash write and erase actions (via SPI interface). Hence - I think it may be the reason.

    Do you have any ideas?

    Thanks!

Related