Raspberry Pi Pico - Multi Core

Hello,

I am attempting to use both cores of a Raspberry Pi Pico W:

Core 0 - WiFi and MQTT

Core 1 - Serial1 to read a serial data stream and decode it, then making it available for publication by MQTT on Core 0.

However, I end up with the Pico crashing when I attempt to pause Core 0 from Core 1.

I have simplified my attempt to date in the following test code (which excludes any of the WiFi/MQTT/actual Serial1 stuff):

  1. When I simply run the risk of having Core 0 and Core 1 clash over the "stringCore1" variable (Core 1 writes to this variable; Core 0 reads it and nulls it) I have yet to have any crashes.

  2. When I uncommenting out the "//rp2040.idleOtherCore();" and "//rp2040.resumeOtherCore();" code, the Pico regularly crashes (in minutes, sometimes seconds).

Any ideas? Is it 'safe' to simply not worry about pausing Core 1 from Core 0?!?

#define DEBUG       // DEBUG allows for debugging information to be printed

#ifdef DEBUG
  #define VERBOSE   // If VERBOSE, DEBUG information includes 'Starting function()' and 'function() completed'
#endif


// heartBeat flashes onboard LED to show Pico W is operating
unsigned long heartBeatTime = millis(); // Time to make onboard LED flash when running
bool heartBeatState = true; // Onboard LED state


#ifdef DEBUG
  int countCore0 = 0;
  int countCore1 = 0;
  String stringCore0;
  String stringCore1;
#endif


void setup()
{
  #ifdef DEBUG
    Serial.begin(115200); // For communications to PC
    rp2040.idleOtherCore(); // Allow delay to affect both cores, to ensure stable synchronisation from start
    delay(10000);
    rp2040.resumeOtherCore();
  #endif
  
  #ifdef VERBOSE
    stringCore0 += "\n\r*** setup() started!";
  #endif

  pinMode(LED_BUILTIN, OUTPUT); // for heartBeat

  #ifdef VERBOSE
    stringCore0 += "\n\r*** setup() completed!";
  #endif
}

void setup1()
{
  #ifdef VERBOSE
    stringCore1 += "\n\r*** setup1() started!";
  #endif

  #ifdef VERBOSE
    stringCore1 += "\n\r*** setup1() completed!";
  #endif
}

void loop()
{
  #ifdef VERBOSE
    stringCore0 += "\n\rStarting loop()";
    countCore0++;
    stringCore0 += "\n\r   loop() count = " + String(countCore0);
  #endif

  heartBeat();

  #ifdef DEBUG
    printData();
  #endif

  #ifdef VERBOSE
    stringCore0 += "\n\rloop() completed!\n\r";
  #endif
}

void loop1()
{
  #ifdef VERBOSE
    stringCore1 += "\n\rStarting loop1()";
  #endif
  
  countCore1++;
  stringCore1 += "\n\r   loop1() count = " + String(countCore1);

  #ifdef VERBOSE
    stringCore1 += "\n\rloop1() completed!\n\r";
  #endif
}

void heartBeat()
{
  digitalWrite(LED_BUILTIN, heartBeatState);
  if (heartBeatTime < millis())
  {
    heartBeatState = !heartBeatState; // Change state
    heartBeatTime = millis() + 1000; // Update to 1 second from now
  }
}


void printData() // Called from Core0
{
  // Pause the other core (Core 1), copy stringCore1, clear stringCore1, then resume other core (Core 1)
  //rp2040.idleOtherCore();
  String copyOfstringCore1 = stringCore1;
  stringCore1 = "";
  //rp2040.resumeOtherCore();

  Serial.print(stringCore0);
  stringCore0 = "";
  Serial.print(copyOfstringCore1);
  copyOfstringCore1 = "";
}

I can not find the Raspberry Pi Pico W in the boards in the Arduino IDE. Are you using the 'earlephilhower' ? Is that without Mbed ?

Arduino IDE 2.2.1

Raspberry Pi RP2040 Boards(2.5.2)

--> Raspberry Pi Pico W

Can you just say which build environment you use ?

This is the Raspberry Pi Pico by Arduino:
afbeelding

That is a Arduino layer on top of Mbed.
The Raspberry Pi Pico W is not supported.

I'm am also using the newest Arduino IDE, version 2.2.1.

I'm using Arduino Mbed OS RP2040.

At present, my sketch isn't currently using any wireless functionality (I plan to build that in later, once (if) I get the dual-core operation working properly.

So you don't have a board with version 2.5.2 and you have not selected a Raspberry Pi Pico W ? I'm very confused.

If each core has one variable only it can write, Core 1 writes a value to the Core 1 variable and Core 0 writes the inverse to its' variable.

But with each having a status word, the status of data ready or not can keep clashes from happening. On a PICO. 32 bits is atomic.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.