-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmy02h-rpc-from-m4.ino
97 lines (71 loc) · 2.66 KB
/
my02h-rpc-from-m4.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
* for the Portenta H7
*
* The PortentaH7 M4 core can not print to the serial monitor
* On the M4 core if you do a Serial.Println it goes to the TX RX UART output pins
* This program uses RPC to redirect Serial.println to the M7 core
* so that regular sketches still work with serial monitor output from the M4 core
*
*
* updated August 2nd, 2020
* by Jeremy Ellis
* Twitter @rocksetta
* Website https://www.rocksetta.com
*
*I have re-written this to make larger programs easier
*by seperating the M7 and M4 code completely.
*
*/
#ifdef CORE_CM7 // Start M7 programming
#include "RPC_internal.h" // comes with the mbed board installation
unsigned long previousMillis = 0; // will store last time
unsigned long interval = 2000;
void setup() {
bootM4();
Serial.begin(115200);
RPC1.begin();
}
void loop() {
while (RPC1.available()) {
Serial.write(RPC1.read());
}
unsigned long currentMillis = millis();
if(currentMillis - previousMillis > interval) { //wait 5 seconds to run
// save the last time you blinked the LED
previousMillis = currentMillis;
int myRand1 = rand() % 100; // from 0 to 99
int myRand2 = rand() % 100; // from 0 to 99
RPC1.call("setVar", (int)myRand1, (int)myRand2); //.as<int>();
Serial.println("From M7 core setting M4 variable to: " + String(myRand1) +", "+ String(myRand2));
Serial.println("Hello from M7 regular Serial");
}
}
#endif // End all M7 core programming
/////////////////////////////////////////////////////////////////////////////////////////////
#ifdef CORE_CM4 // Start M4 programming
#include "RPC_internal.h" // comes with the mbed board installation
#define Serial RPC1 // So the M4 regular serial prints to RPC
// Set an M4 core global variable
int myIntGlobal1 = 1234;
int myIntGlobal2 = 1234;
void setVar(int a, int b) {
myIntGlobal1 = (int)a;
myIntGlobal2 = (int)b;
// return String(a) +", "+ String(b);
}
unsigned long previousMillis = 0; // will store last time
unsigned long interval = 5000;
void setup() {
Serial.begin(); // RPC begin does not take an integer
RPC1.bind("setVar", setVar); // do these have to be the same?
}
void loop() {
unsigned long currentMillis = millis();
if(currentMillis - previousMillis > interval) { //wait 5 seconds to run
previousMillis = currentMillis;
Serial.println("---------------------------------");
Serial.println("From M4 showing global variable: "+ String(myIntGlobal1)+ ", "+ String(myIntGlobal2));
Serial.println("Hello from M4 using regular serial piped through RPC");
}
}
#endif // End all M4 core programming