This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

HardFault after calling math function

Hi all,

I use µVision 4.73 evaluation version. My target device is LPC4357 (cortex M4).
All works fine, except when I use floating poit math.

volatile float F;

#include <math.h>

int main(void)
{
  SystemInit();
  F = 16.0;
  F = sqrt(F);
}

above is only a snippet of the program.
As soon I call the sqrt() I get a HardFault exception. The compiler uses microlib and no FPU is used. (defining F as double or calling sqrtf() same error).

When I enable the FPU, I get the same error before I reach main...
stack- and heap size are both 0x4000.

Any idea ?

Parents
  • I wouldn't exit the main() function.

    What instruction (assembler / registers) is faulting here? If you understand exactly what's going pear shaped you'll be in a better position to fix it.

    Typically in the CMSIS model the SystemInit() function is called prior to __main and your main() via startup_arch.s

    Are there any memory, or peripheral setup functions there?

Reply
  • I wouldn't exit the main() function.

    What instruction (assembler / registers) is faulting here? If you understand exactly what's going pear shaped you'll be in a better position to fix it.

    Typically in the CMSIS model the SystemInit() function is called prior to __main and your main() via startup_arch.s

    Are there any memory, or peripheral setup functions there?

Children