Electron Stopped Working After Enabling Backup RAM

We have been developing our electron product in two separate teams. One worked on reading and writing to pins while the other worked on communicating with our API. Today we tried to bring the code together and fried the electron on our proto board. Everything was working properly separately before today.

We are using a 12V battery as our main power source. This is regulated to 5V and then connected the Vin pin. We also had the USB connected.

The new code for what was running on the proto board is bracketed by commented ‘New Code’ and ‘End New Code’. There is multiple sections of new code intermixed with code that had been run successfully with the proto board before.

	//New Code
	STARTUP(runBeforeSetup());
	//End New Code
	// First, we're going to make some variables.
	// This is our "shorthand" that we'll use throughout the program:
	int led0 = D0;
	int led1 = D1;
	int led2 = D2;
	int led3 = D3;
	int button = D6;

	int bulkEnable = A1;
	int outputEnable = A2;
	int analogPin = A0;
	int currentADC = A3;

	double currentSenseVoltage;
	int val = 0;
	int counter = 0;
	int elapsedTime=0;
	double voltageOp = 6*3.35/4095;
	double voltageOp2 = 3.35/4095;
	double batteryVoltage = 12.5;
	double batteryVoltageSum = 0;
	double batteryVoltageAvg = 0;
	double currentSenseVoltageAvg;
	double loadCurrent;
	double ampGain = 21.4;
	double currentResistorValue = 0.01;
	double refVoltage = 3.35;
	double power = 0;
	double energy = 0;
	TCPClient client;
	String response = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
	byte server[] = {192, 1, 168, 1};
	retained long end = 0;



	void setup() {
		  //New Code
		  end = Time.now();
		  //End New Code

		  Serial.begin(9600);


		  pinMode(led0, OUTPUT);
		  pinMode(led1, OUTPUT);
		  pinMode(led2, OUTPUT);
		  pinMode(led3, OUTPUT);
		  pinMode(D7, OUTPUT);

		  pinMode(button, INPUT);

		  pinMode(bulkEnable, OUTPUT);
		  pinMode(outputEnable, OUTPUT);
		}


		void loop() {
		  val = digitalRead(button);
		  digitalWrite(led1, val);
		  if(val == 1){
		    activate();
		  }
		  if(end > Time.now()){
		    if (batteryVoltage>14.5)
		    {
		      digitalWrite(bulkEnable, HIGH);
		      digitalWrite(outputEnable, HIGH);
		    }
		    else if (batteryVoltage<13.5 && batteryVoltage > 12.2)
		    {
		      digitalWrite(bulkEnable, LOW);
		      digitalWrite(outputEnable, HIGH);
		    }
		    else if (batteryVoltage<11.5)
		    {
		      digitalWrite(bulkEnable, LOW);
		      digitalWrite(outputEnable, LOW);
		    }
		  }
		  //New Code
		  else{
		    if (batteryVoltage>14.5)
		    {
		      digitalWrite(bulkEnable, HIGH);
		      digitalWrite(outputEnable, LOW);
		    }
		    else if (batteryVoltage<13.5 && batteryVoltage > 12.2)
		    {
		      digitalWrite(bulkEnable, LOW);
		      digitalWrite(outputEnable, LOW);
		    }
		    else if (batteryVoltage<11.5)
		    {
		      digitalWrite(bulkEnable, LOW);
		      digitalWrite(outputEnable, LOW);
		    }
		  }
		  //End Code
		  val = analogRead(currentADC);
		  currentSenseVoltage = currentSenseVoltage+val*voltageOp2; // read votage to monitor current, running sum
		  delay(10);

		  val = analogRead(analogPin);
		    batteryVoltage = val*voltageOp;
		  batteryVoltageSum = batteryVoltageSum + batteryVoltage; // read voltage to monitor battery voltage, running sum
		  delay(90);

		  counter++;

		  if (counter == 20){
		    batteryVoltageAvg = batteryVoltageSum/counter;

		    currentSenseVoltageAvg  = currentSenseVoltage/counter;
		    loadCurrent = currentSenseVoltageAvg/ampGain/currentResistorValue;

		    power = batteryVoltageAvg*loadCurrent;
		    energy = energy + power*counter*0.1;

		    elapsedTime = elapsedTime+counter*0.1;

		    Serial.print("The load current is: ");
		    Serial.print(loadCurrent);
		    Serial.print(" A\n");

		    Serial.print("The Battery voltage is: ");
		    Serial.print(batteryVoltageAvg);
		    Serial.print(" V\n");

		    Serial.print("The power is: ");
		    Serial.print(power);
		    Serial.print(" W\n");

		    Serial.print("The energy since last reset: ");
		    Serial.print(energy);
		    Serial.print(" J\n");

		    Serial.print("The energy since last reset: ");
		    Serial.print(energy/3600);
		    Serial.print(" Wh\n");

		    Serial.print("The time since last reset: ");
		    Serial.print(elapsedTime);
		    Serial.print(" S\n\n");

		    batteryVoltageSum = 0;
		    currentSenseVoltage  = 0;
		    counter = 0;
		  }


		}
		//New Code
		void activate(){
		  int i = 0;
		  Serial.println("connecting....");
		  if(client.connect(server, 80)){
		    Serial.println("connected");
		    client.println("POST /abc/123456/abc");
		    client.println();
		    while(client.connected()){
		      if(client.available()){
		        char c = client.read();
		        response.setCharAt(i, c);
		        Serial.print(c);
		        i++;
		      }
		      else{

		      }
		    }
		    Serial.println();
		    Serial.print("response is: ");
		    Serial.println(response);
		    if(response.startsWith("{\"authorizedForMillis\":}")){
		      end = Time.now() + response.substring(23, i - 2).toInt();
		      Serial.print("Time when activation period ends is: ");
		      Serial.println(end);
		    }
		  }
		  else{
		    Serial.println("failed to connect.");
		  }
		}

		void runBeforeSetup(){
		  System.enableFeature(FEATURE_RETAINED_MEMORY);
		}

		void heartBeat(){
		  int i = 0;
		  Serial.println("connecting....");
		  if(client.connect(server, 80)){
		    Serial.println("connected");
		    client.println("POST /abc/123456/abc");
		    client.println();
		    client.println("data goes here");
		    while(client.connected()){
		      if(client.available()){
		        char c = client.read();
		        response.setCharAt(i, c);
		        Serial.print(c);
		        i++;
		      }
		    }
		    Serial.println();
		    Serial.print("response is: ");
		    Serial.println(response);
		  }
		  else{
		    Serial.println("failed to connect.");
		  }
		}
		//End New Code

Is there anywhere that we could have fried the Electron due to enabling the backup RAM and/or using STARTUP?

What do you mean with fried the Electron?
Doing that purely via software is rather unlikely?

What is the device doing in Safe Mode?
What is it (or rather not) doing with your code running?

A more specific issue description is a minimum requirement before looking at your code makes any sense.