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

Stack violation: stack pointer outside stack area.

Hi,

i get hardfault for some reason. This is RTT output:

<error> hardfault: Stack violation: stack pointer outside stack area.
<error> hardfault: Cause: The processor has attempted to execute an instruction that makes illegal use of the EPSR.

and this is the output of GDB:

Program received signal SIGTRAP, Trace/breakpoint trap.
0x0003e3c2 in HardFault_c_handler (p_stack_address=0x0) at ../../../../submodules/firmware_nrf52_sdk_15_2/src/nRF5_SDK_15.2.0_9412b96/components/libraries/hardfault/hardfault_implementation.c:148
148         NRF_BREAKPOINT_COND;

and backtrace gives this:

#0  0x0003e3c2 in HardFault_c_handler (p_stack_address=0x0) at ../../../../submodules/firmware_nrf52_sdk_15_2/src/nRF5_SDK_15.2.0_9412b96/components/libraries/hardfault/hardfault_implementation.c:148
#1  <signal handler called>
#2  0x00000000 in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)

is there a nice way to find out where the hardfault happend and what could cause it?

I am using nrf52840 and SDK 15.2

Thanks

  • Hello,

    p_stack_address = 0 which might be due to the __StackTop and __StackLimit definitions.
    Take a look at hardfault_handler_gcc.c which calls 
    HardFault_c_handler. The parameter to HardFault_c_handler is set to 0 if the SP is not located into the Stack limit. 
    I would advise setting __STACK_SIZE in your Makefile (or increasing to the max possible value it if already defined) to "allocate" a larger size than the default one which is 2048. 

    Then, you'll be able to get the PC where the hardfault occured in HardFault_c_handler using ((HardFault_stack_t *)p_stack_address)->pc.

    Good luck

Related