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

HardFault on nrf52832 when passing floating point value to C++ ostream and can't get backtrace.

Hello, I'm trying to run C++ code on the nrf52832 but I'm getting an Hard Fault when sending a floating point to an ostream, like in "std::cout << 13.5f;". The FPU is enabled.

Printing the backtrace from the handler I get the following:

(gdb) bt
#0 HardFault_Handler () at /toolchain-deps/sdk/components/libraries/hardfault/nrf52/handler/hardfault_handler_gcc.c:51
#1 <signal handler called>
#2 nrf_drv_saadc_init (p_config=0x0 <nrf_drv_saadc_init>, event_handler=0x0 <nrf_drv_saadc_init>)
at /contiki-uwb/platform/dwm1001/dev/battery_read.c:68
Backtrace stopped: previous frame identical to this frame (corrupt stack?)

which points to a file location totally unrelated.

By using the Hard Fault handling library from the SDK I got the following message:

<error> hardfault: Stack violation: stack pointer outside stack area.
<error> hardfault: Cause: Data bus error (return address in the stack frame is not related to the instruction that caused the error).
<error> hardfault: Cause: Stacking for an exception entry has caused one or more BusFaults.

I tried to follow a guide on how to debug HardFaults ( https://interrupt.memfault.com/blog/cortex-m-fault-debug ) and I found the UsageFault Status register set to zeros, the BusFault Status register with the IMPRECISERR and STKERR bits set to one, and MemManage Status Register set to zeros.

As exampled in the guide I tried to find the error location by enabling precise errors setting DISDEFWBUF to 1, obtaining this time in the BusFault Status register the bits PRECISERR, STKERR and BFARVALID set to 1. Then the Bus Fault Address Register hold the value 0xffffffe0 which I don't thinks makes sense. Also the handling library this time logs:

<error> hardfault: Stack violation: stack pointer outside stack area.
<error> hardfault: Cause: Data bus error (PC value stacked for the exception return points to the instruction that caused the fault).
<error> hardfault: Cause: Stacking for an exception entry has caused one or more BusFaults.
<error> hardfault: Bus Fault Address: 0xFFFFFFE0

I don't know how to proceed from here to find what is the problem or a solution. Any suggestion?

Parents Reply Children
No Data
Related