Firmware crashes on Particle Core

Hello all,

I am using Blynk on Particle core. This core acts as a gate way, sends and receives signals from different arduino boards in my home over RF24 network.

I made sample program for testing everything went well during initial testing. But while testing the failure case I am facing serious problems. When one of the arduino boards (RF24 node) is removed from the network and if Core tries to send a command to this node then most of the times the firmware on the Core crashes (SOS with 1 red blink --> Hard Fault --> Memory violation error)

Initially I assumed it could be some error in RF24 and RF24Network library that I am using. With this assumption, I tried to debug my code. During failure case m_rfNetwork.write() function takes almost 1.44 sec. So I replaced this write function with a blocking delay of 1500 sec to just check if this huge time is causing some error. Still the error continued. This gave me an impression that problem is not in RFlibraries.

Second assumption Connection to Particle Cloud and Blynk Cloud at same time. So disconnected from Particle cloud. Still problem exists.

Next assumption possible error with Blynk or with my code. I introduced some Serial.Print() statements to check which is last statement being executed before crashing. My code is below

#include <application.h>
#include <SparkCorePolledTimer.h>
#include <BlynkSimpleParticle.h>
#include <RF24Network.h>
#include <RF24.h>


/*Blynk Authentication */
char auth[] = "my authentication";
WidgetTerminal Debug_Terminal(V2);
WidgetLED LED_ConnectionStatus(V1);

RF24 m_radio(D6, A2);
RF24Network m_rfNetwork(m_radio);

SparkCorePolledTimer  every50ms(50);
SparkCorePolledTimer  every1sec(1000);

void CyclicEvery50ms( void );
void CyclicEvery1s( void );

void notifyBlynkConnecStatus( void );
void updateRelayStatustoPhone( void );

uint8_t reqReceived = 0;

void setup(void)
{
  pinMode(D7, OUTPUT);
  Serial.begin(57600);
  m_radio.begin();
  m_rfNetwork.begin(/*channel*/ 40, /*node address*/ 00);

  //Radio Parameters
  // delay is in 250us increments (4ms max), retries is 15 max.
  m_radio.setRetries(15,15);
  m_radio.printDetails();

  /* Cyclic timer settings */
  every50ms.SetCallback(CyclicEvery50ms);
  every1sec.SetCallback(CyclicEvery1s);

  Particle.disconnect();
  delay(1000);
  Blynk.begin(auth);
}

void loop(void)
{
  /*Blynk Cyclic handling */
  Blynk.run();

  /* RF Network Cyclic Handling */
	m_rfNetwork.update();

	/* Read any available messages */
  while ( m_rfNetwork.available() )
  {
    // If so, grab it and print it out
    RF24NetworkHeader header;
    m_rfNetwork.peek(header);

    if(header.type == 1)
    {
    //  handleStatusMsg();
    }
  }

  /* For Cyclic Handling */
  every50ms.Update();
  Serial.println("FInished 50 ms cyclic run");
  every1sec.Update();
  Serial.println("FInished 1 s cyclic run");
}

/*****************
* cyclic functions
******************/
/****************************************************************************
* Cyclic 50 ms function,
* Send command if any
******************************************************************************/
void CyclicEvery50ms( void )
{
  if( reqReceived == 1)
  {
	uint16_t command = 5555;

	blynkPrint("Sending command ...");

	RF24NetworkHeader header(/*toNode*/ 1, /*message type */ 1);
	bool ok = m_rfNetwork.write(header, &command, sizeof(command));
	if (ok)
	{
		blynkPrint("ok");
	}
	else
	{
		blynkPrint("failed");
	}
  }
}


/*******
* Blynk
********/
/****************************************************************************
* Cyclic 1s function, Update HW connection status to Blynk
******************************************************************************/
void CyclicEvery1s( void )
{
    if(LED_ConnectionStatus.getValue())
    {
      LED_ConnectionStatus.off();
    }
    else
    {
      LED_ConnectionStatus.on();
    }
}
/******************************************************************************
* Blynk switch pressed
*******************************************************************************/
BLYNK_WRITE(V0)
{
  int pinData = param.asInt();
  if(pinData == 1)
  {
    reqReceived = 1;
  }
  else
  {
    reqReceived = 0;
  }
}

/******************************************************************************
* Blynk print to Terminal
*******************************************************************************/
void blynkPrint( char *string )
{
  Debug_Terminal.println(string);
  Debug_Terminal.flush();
}

I always found the last statement seried out is “FInished 50 ms cyclic run”. So I assume, it crashes in 1 sec cyclic function. In this function I only toggle a Blynk LED. I am not sure if some problem exists here.

Blynk team, could you please guide to solve this issue. ?

Link to the same issue discussion in Particle community:
https://community.particle.io/t/problem-using-rf24-library-with-particle-core/17288

Thank you.

Hi,

I am added few more print statements to debug further

void CyclicEvery1s( void )
{
  Serial.println("Starting LED COntrol");
    if(LED_ConnectionStatus.getValue())
    {
      Serial.println("Starting LED Turning ON");
      LED_ConnectionStatus.off();
    }
    else
    {
      Serial.println("Starting LED Turning Off");
      LED_ConnectionStatus.on();
    }
}

It seems the crash happens after printing “Starting LED Turning ON”.

I am really not able to understand why and where is crash is happening :frowning:

Hello all,

Any inputs to debug further ?

Sorry can’t check with your HW. Maybe someone from the community can help.

@vhymanskyy, Finally fixed it by removing the Widget Terminal.

As I explained earlier, this error was not occurring regularly, it happens only sometimes. So I tried different ways to reproduce the issue.
–> I could easily reproduce it when two buttons are pressed very quickly (each button press sends a request to arduino board over RF24 network also prints few characters to Terminal Widget)).
–> Later I introduced a ZERGBA widget over a virtual pin and every time the data is received it is sent to arduino over RF24 network and prints few characters to Terminal widget. If the color is changed slowly everything looks to be okay, but when I change the color too quickly firmware crashes very quickly.

I did the following things to improve the situation
–> Optimized the time taken by RF network to send data. Particularly the time taken when the Arduino board is Offline. >> No success
–> Optimized code at couple of places in my project. >> No success.
(My project is spread over multiple files, above code I mentioned here, I have created to test the problem and explain it to community where I could reproduce the issue).
–> I removed Terminal Widget, and everything seems to be working very smooth. Even if I change the colors too quickly, there is no crash and data is sent on RF network successfully.

With these test I could assume the following possible issues
–> Bug in Terminal Widget
–> If requests are sent too quickly and if the SW is busy (blocked somewhere in delay or while loops) then also I could see a similar issue. Some timing issue.