What does "hard fault" mean?

I’m seeing SOS, 1 red blink, SOS. Hard fault, right? So what does that mean? Can I debug further? Maybe there’s something written to the serial connection, but I’m not sure how to get at it, since this necessarily comes with a series of power cycles that reset the connection.

Hi @philo,

Usually that means there’s an error in your code, like referencing invalid memory, or calling something that isn’t there, etc. Can you share your code and we can help track it down?

Thanks,
David

Thanks, it did indeed indicate an error in my code. I called Spark.Function on a function that didn’t have the right signature. The fault happened early, must have been during the call to Spark.Function. I could be mistaken, but it seemed to cause the flash to fail and retry. Could that be the case? That flashing somehow fails if the first execution of the setup() method fails?

Curiosity aside, can I make a feature request? If the argument to Function were a lambda instead of a void*, this error could have been caught at compile time.

1 Like

Hi @philo,

Ahh, great, I’m glad you got it working!

I added your feature request to the issues on the core-firmware repo here:

Thanks,
David

Can you tell me what was the function signature when it was wrong? The function parameter to Spark.function() is type safe, so the compiler should complain when the function type is wrong.

void SparkClass::function(const char *funcKey, int (*pFunc)(String paramString))

E.g.

This code:

int brewCoffee() {}

void setup()
{
     Spark.function("brew", brewCoffee);
}

Gives a compiler error:

../src/application.cpp:73:39: error: invalid conversion from 'int (*)()' to 'int (*)(String)' [-fpermissive]

I’m no longer able to repro. I see the compile error as you describe. Guess too much time has passed since I ran into this, and I forgot exactly what was the problem. Thanks for your help, and sorry for the wild goose chase!

No worries @philo, it was a good suggestion and certainly worth following up.

1 Like