Sqrt() function not working on RAK5205

Hello fellow Users,

I have been trying to implement a Haversine formula to calculate the distance between 2 GPS coordinates. Unfortunately the processor locks up every time. I have narrowed it down to the sqrt() function. The RAK online compiler happily builds the code with the sqrt() function in, but the RAK 5205 module just enters a reset boot loop when executing the code. If I comment out the 1 line of code that only has a sqrt() call in it, then the code runs fine.

Has anyone else found issues with the sqrt() function? If so, do you have any work arounds?

Cheers,
Martin

Unless it is a bug in your program triggering something like a hardfault, that sounds like bad compiler target settings. I don’t believe the STM32L1 has an FPU, so it should be using software emulation and passing arguments in integer registers. But it’s quite possible the wrong build flags to a compiler could result in illegal floating point instructions or function call arguments being misplaced in non-existent FPU registers.

You might want to consider building your code offline where you can directly control the compiler and linker flags. You could also consider trying to hook up a debugger (I’m not sure if you can get at the SWD pins, if you can’t you could run the code on an STM32L1 nucleo)

Hi Chris, thanks for you reply.

I managed to work around the issues by changing to fixed point calculations and using my own fixed point square root function. It’s a little hard to debug the system with an online compiler, but easier to avoid the problem.

Cheers,
Martin