rpc-coeur-m4.ino
The Portenta signature feature: the M7 calls a function exported by the M4 with local-call syntax. Two Arduino brains in one module, talking over RPC — the minimal M4 sketch is in the comments.
Hardware
An Arduino Portenta H7 (ST STM32H747 dual-core module Cortex-M7 @ 480 MHz + M4 @ 240 MHz, 8 MB SDRAM, high-density connector), powered by USB-C or 5 V. No external component.
Wiring
Nothing to wire. The two sketches upload separately (M7/M4 selector in DFU mode).
How it works
RPC.exportFunction publishes the symbol on the M4 side; RPC.call serializes arguments and awaits the result. The try/catch covers a missing M4 firmware.
Running it
Arduino IDE with the « Arduino Mbed OS Portenta Boards » core: pick « Portenta H7 » (M7 core), the USB-C port, then Upload. The DFU mode M7/M4 selector also loads the M4 core.
Variants
Delegate real-time tasks (motion) to the M4 while the M7 handles USB/display, or share a buffer in common RAM.
rpc-coeur-m4.ino
// RPC Portenta : le M7 (ce croquis) appelle une fonction du M4.
// Cote M4 : un second croquis Arduino expose additionner().
#include "RPC.h"
unsigned long t0 = 0;
void setup() {
Serial.begin(9600);
while (!Serial && millis() < 3000);
Serial.println("M7 : appel du M4 via RPC");
}
void loop() {
if (millis() - t0 < 2000) return;
t0 = millis();
// L'appel est distant mais s'ecrit comme un appel local.
int a = (int)(millis() / 1000);
int b = 41;
int resultat;
try {
resultat = (int)RPC.call("additionner", a, b);
Serial.printf("M4 a calcule %d + %d = %d\n", a, b, resultat);
} catch (...) {
Serial.println("M4 absent : televerser le croquis M4 (bouton M4 du DFU)");
}
}
// Croquis M4 minimal :
// #include "RPC.h"
// int additionner(int x, int y) { return x + y; }
// void setup() { RPC.exportFunction("additionner", additionner); }
// void loop() {}