🛠 Exploiter le double cœur : M7 pour le PLC, M4 en coprocesseur
Objectives
Understand and leverage the dual-core architecture of the Opta's STM32H747XI: Cortex-M7 up to 480 MHz (the PLC sketch) and Cortex-M4 up to 240 MHz (available as a Zephyr coprocessor, documented for the arduino_opta board). Use cases: offload intensive processing from the M7 (FFT filtering, network management, display driving) to the M4, and exchange data via shared memory. This is the "bare metal / RTOS" level of the Opta.
Hardware
- Arduino Opta (any variant)
- Zephyr SDK (west workspace) with the arduino_opta board, m7 and m4 targets
- Probe/debugger or serial port to monitor both cores
- Knowledge of RTOS and shared memory
Complete Code
/* copro_m4.c — firmware Zephyr cote M4 (board arduino_opta@m4)
* Publie une table de mesures dans la RAM partagee ; le M7 la lit.
*/
#include <zephyr/kernel.h>
#include <zephyr/device.h>
/* Zone partagee conventionnee (adresse a adapter a votre layout memoire) */
struct partage {
uint32_t seq; /* numero de sequence, incremente par le M4 */
int32_t mesures[8]; /* 8 valeurs d'entrees 0-10 V converties */
};
volatile struct partage *shm = (volatile struct partage *)0x30060000;
void main(void) {
uint32_t n = 0;
while (1) {
for (int i = 0; i < 8; i++) shm->mesures[i] = (int32_t)(n * (i + 1));
shm->seq = ++n; /* ecriture de fin : le M7 teste seq */
k_msleep(10);
}
}
// cote_m7.ino — lecture cote sketch Arduino (core mbed_opta)
struct Partage { uint32_t seq; int32_t mesures[8]; };
volatile Partage* shm = (volatile Partage*)0x30060000; // meme zone
void loop {
uint32_t s = shm->seq;
Serial.printf("seq=%u m0=%d\n", s, shm->mesures[0]);
delay(100);
}
Expected Verification
The M4 increments the sequence every 10 ms; the M7 displays increasing sequence numbers and consistent measurements. > one.
Common Errors
- Overwriting the other core's memory zone: without a validated memory layout, the two firmwares can interfere with each other (the Zephyr core loads sketches in LLEXT, already sensitive to the documented "undefined symbol" and OOM issues).
- Race condition: reading seq before the measurements corrupts the read; re-read seq afterwards and discard if changed (seqlock pattern).
- Confusing the cores: the Arduino sketch runs on the M7; the M4 is only usable with a dedicated Zephyr firmware, not from the standard Arduino IDE.
- Wrong compilation target: arduino_opta has distinct m7 and m4 targets; flashing the wrong ELF leaves one core silent.
Other tutorials for this board
- Premier sketch : faire clignoter une LED sur Arduino Opta
- Lire une entrée numérique 24 V (capteur de proximité)
- Commander une charge 230 V avec un relais de sortie
- Server Modbus TCP : exposer les relais sur Ethernet
- Lire un capteur analogique 0–10 V sur les entrées Opta
- Remonter des données machine en MQTT via Ethernet
Code examples for this board
relais_securise.inoArduinoentrees_numeriques.inoArduinoanalogique_0_10v.inoArduinomodbus_tcp_esclave.inoArduinomodbus_rtu_maitre.inoArduinomqtt_telemetrie.inoArduino