Hard fault -- recovery?

So…I tweaked some Losant code I had working (added some Serial.println() statements) and all of a sudden, I’m seeing a hard fault (SOS + 1 blink + SOS) and then it tries to reboot and repeats the process.

I can see where to get into DFU mode, but don’t see the steps to “fix” my issue, which I assume involves reflashing the factory firmware. Any guidance would be greatly appreciated!


Quick question. Are you on Mac, Linux, or Windows?

On a Mac and I think I finally got out of trouble by putting into DFU mode and then

particle flash --usb tinker

(edit) so it must have been in my application code

That’s good to hear.

If you want to post your code here, I can have a quick look at it to see why you got a Hard Fault.

Edit: Are you using a Photon or an Electron?

1 Like

On a Photon or Electron, you probably only needed to enter Safe Mode and re-flash the older (working) version of your code. Hold down RESET and SETUP, then release RESET, wait until the LED blinks magenta, then release SETUP. You should then be able to do a normal over-the-air code flash. Safe mode basically prevents your application code from running, just for this situation.

Thanks @nrobinson2000. The code did not seem to be running as before–it’s been a couple weeks since I ran it. Losant wasn’t getting any updates. It’s basically the Losant sample Photon code and all I did was add

Serial.println("I'm in setup");

That being said, I may have also selected to compile with 0.4.9 to see if that would “fix” the issue.

You have


in your setup() right?

Then I don’t see why your addition would cause a hard fault.

Edit: Are you using the latest firmware on your device and compiling for the latest release?

1 Like

Yep. I do have the begin in setup. I believe the “original” compile from a few weeks ago was with 0.4.9. I then noticed it wasn’t updating Losant as often as I thought it should (which I now believe was simply impatience on my part) and compiled it with the print statement added with 0.5.1 (the default). I then tried to recompile with 0.4.9 and wonder if going back and forth might have caused the problem.

I do think the troubleshooting tips should include the following as a means to cleanse the device of problematic application code:

particle flash --usb tinker
1 Like

I just made a pull request with this:

Just added a new Photon without issue and the Tinker app worked as expected.

I then tried to flash the following program, but every time I do, I get an SOS with 5 blinks – usage fault.


// This #include statement was automatically added by the Particle IDE.
#include "NCD2Relay/NCD2Relay.h"

NCD2Relay relayController;

int RSSI;
int leftDoor = 1;
int rightDoor = 2;

int pRightDoor(String command);
int pLeftDoor(String command);
int pReset(String command);

void setup() {
    Serial.println("Program has started");
    //Turn the relays off and indicate so on their respective status variables

void loop() {
  RSSI = WiFi.RSSI();

int pRightDoor(String command) {
  return 1;

int pLeftDoor(String command) {
  return 1;

int pReset(String command) {
  //function to call to remotely reset Photon
  return 1;

Can you narrow down the timeframe or even code line where it happens?
I’d also add a delay in loop() there is no need to hammer the WiFi every few milliseconds for the RSSI reading :wink:

OK. I put in a 5 second delay at the beginning of setup() and it went into the weeds immediately after that delay. I found my error in not setting the address for the relay controller. Duh…

I also, as you suggested, put in a delay in the loop().

Thanks for helping get my brain working (I need this too often!).

I might offer some feedback to the NCD (ControlEverything.com) folks to tweak their code to protect it from trashing the Photon for this situation.