RPC.available() is always false

Portenta H7 M7 core
VSCode + PlatformIO

I posted this on the Arduino forum but thought I’d try here as well.

I’m trying to write simple dual-core sketches to learn RPC between the M7 and M4 cores (simpler that the add/subtract example).

The RPC never becomes available. Looking at the setup() function below, the message “M7-Waiting for RPC to become available…” just continuously prints to the serial monitor.

Here is my platformio.ini file:

[env:portenta_h7_m7]
platform = ststm32
board = portenta_h7_m7
framework = arduino
lib_deps =
   RPC
monitor_filters =
  default
  time
  log2file
  monitor_speed = 115200

Below is my setup() method. Obviously I’m missing something and after several days of reading forums and looking for other Portenta H7 RPC documentation I’m at a loss. Are there any specific docs that address the Portenta H7 RPC API? Any help is greatly appreciated.

String currentCPU() {
  return HAL_GetCurrentCPUID() == CM7_CPUID ? "M7" : "M4";
}

void setup() {

  pinMode(LEDB, OUTPUT);

  Serial.begin(115200);
  while (!Serial) {}

  // Initialize RPC library; this also boots the M4 core
  Serial.println(currentCPU() + "-Before RPC.begin()");
  int retc = RPC.begin();
  if (retc != 0) {
    Serial.println("Failed to initialize RPC library");
    while (1) {}
  }
  Serial.println(currentCPU() + "-After RPC.begin()");

  Serial.println(currentCPU() + "-RPC initializing...");
  while(!RPC.available()) { 
      Serial.println(currentCPU() + "-Waiting for RPC to become available...");
      delay(1); 
  }
  Serial.println(currentCPU() + "-RPC initialized");
}

And here is the output:

16:07:54.409 > M7-Before RPC.begin()

16:07:55.444 > M7-After RPC.begin()

16:07:55.444 > M7-RPC initializing...

16:07:55.444 > M7-Waiting for RPC to become available...

16:07:55.444 > M7-Waiting for RPC to become available...

16:07:55.444 > M7-Waiting for RPC to become available...

16:07:55.444 > M7-Waiting for RPC to become available...

16:07:55.444 > M7-Waiting for RPC to become available...
.
.
.

Forever and ever…

BTW: Compiling and uploading my sketch with the Arduino IDE has the same results. Running the Portenta H7 RPC examples in the Arduino IDE has the same results (M7-Waiting for RPC to become available…).

Is this the only board and sketch you use? This will only upload to the m7 core, not the m4 core. If you don’t upload a firmware into the M4 core, the sketch on the M7 core won’t have anyone to talk to. The portenta_h7_m4 board exists for that.

Maybe you have a fundamental misunderstanding. RPC.available() will return the number of bytes that are readable from the RPC stream, i.e., the number of bytes that the other core has sent via RPC.write() or similiar. If you don’t load a sketch into the M4 that does an RPC.write(), then it is absolutely correct that RPC.available() is always 0 (bytes).

I’ve uploaded an empty sketch to the M4 core.

Aha! I believe you are correct. I thought I had to wait for the RPC mechanism to become available before I could use it.

Does the M4 code need to have an RPC.call() for the RPC communication between cores to be initialized (don’t even know if I asked that correctly)? In any case, I will return to the add/sub examples and try to get that working.

My goal is to have the individual cores code separated. I have a difficult time making sense of thousands of lines of code that have a bunch of #ifdef’s sprinkled throughout.

Can you point me towards the Portenta H7 API documentation (I’ll be darned if I can find any)?

Thank you!