Heavy math function (trig) - Core error 1 (halt)

I’m trying to get some positioning calculations done on my Core. I have a class method that does several trig function calls (math.h). I build locally and use DFU with the following output from the build:

text data bss dec
88168 1296 11976 101440

What I see is that after loading the flash, the core tries to connect (blinking cyan), and sometimes briefly goes breathing cyan, but shortly after does the SOS with error 1. Any ideas?

Specifically, if I introduce a call to asin() that seems to be the straw that breaks the camel’s back. Also, the core reboots shortly after the error and cycle continues.

Without seeing any code, I would recommend turning off WiFi and/or disable Spark Cloud to see if your code functions as needed. I have ran into issues with the Spark Core losing cloud connection or WiFi connection. I typically have resolved this by only connecting when I need to access the cloud then disconnecting. This worked for my requirements, but may not work for your specific needs.

Good luck,

Brent

Another reason for the hard fault might be “inappropriate” use of variables/pointers/…

I’d agree with @bpryer, seeing your code might help helping :wink:

Judgeing by the size of your build, it might be useful boil it down to the minimum that causes your issue.
For that you might want to add some traces (e.g. Serial.print, LED blinks, RGB codes, …) to give you a clue how far your code runs before it breaks.

Ok, thanks for the input. Here’s a basic pseudocode description:

main.ino:

TimeClass time;
NodeClass node;

void setup() {
}

void loop() {
    time.read();
    node.updatePosition(&time);
}

NodeClass.cpp:

#include <math.h>
...
bool NodeClass::updatePosition(TimeClass *time)  {
    ...
   _output = asin(...);
}

If I move the call to asin(…) to be outside the NodeClass method, e.g. in the main.ino loop(), it seems to run without the crash. It leads me to think that maybe there is a memory issue (stack size??). I am thinking about experimenting with the linker script to see if it changes behavior…