You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/hardware/10.mega/boards/giga-r1-wifi/tutorials/giga-dual-core/giga-dual-core.md
+46-20Lines changed: 46 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -36,7 +36,7 @@ In this guide you will discover:
36
36
37
37
***\*For instructions on how to install the GIGA Core, follow the [Getting Started with GIGA R1 guide](/tutorials/giga-r1-wifi/giga-getting-started).***
38
38
39
-
## What is Supported on M4?
39
+
## M4 Support
40
40
41
41
The M4 processor can access most of the peripherals that the M7 can access, with some exceptions.
***\*Serial Communication from the M4 can be enabled by setting up an RPC that allows the M4 & M7 cores to communicate. Using `RPC.print()` (M4) and `RPC.read()` (M7) helps achieve this. See [RPC Serial Examle](#rpc-serial).***
57
+
***\*Serial Communication from the M4 can be enabled by setting up an RPC that allows the M4 & M7 cores to communicate. Using `RPC.print()` (M4) and `RPC.read()` (M7) helps achieve this. See [RPC Serial Example](#rpc-serial).***
58
58
59
59
### Boot / Disable M4
60
60
61
-
The M4 core is by manufacturing default, disabled when booting the board. The M4 core can however be booted by using the `RPC.begin()` command, which includes also boots the M4 core. See the [RPC.cpp source file](https://github.com/arduino/ArduinoCore-mbed/blob/main/libraries/RPC/src/RPC.cpp#L122-L140) for more details.
61
+
The M4 core is by manufacturing default, disabled when booting the board. The M4 core can however be booted by using the `RPC.begin()` command, which includes the necessary functions to boot the M4 core. See the [RPC.cpp source file](https://github.com/arduino/ArduinoCore-mbed/blob/main/libraries/RPC/src/RPC.cpp#L122-L140) for more details.
62
62
63
63
### Boot / Disable M7
64
64
@@ -96,13 +96,15 @@ When writing multiple sketches, there are some things to consider to make your d
96
96
97
97
### Partitioning The Flash Memory
98
98
99
-
To allocate memory for the M4, the flash memory can be partitioned. This is done by navigating to **Tools > Flash Split** in the IDE.
99
+
To allocate the flash memory for the M4, the flash memory can be partitioned. This is done by navigating to **Tools > Flash Split** in the IDE.
100
+
101
+
***Note that the flash memory is the space where the application code (your sketch) is stored. It is not the RAM memory (which is significantly lower).***
100
102
101
103

102
104
103
-
-**2MB M7 + M4 in SDRAM (default)** - this option is the default configuration, which is for programming the M7 only. This allocates no memory to the M4.
104
-
-**1.5MB M7 + 0.5MB M4** - useful when larger amount of memory is required on the M7.
105
-
-**1MB M7 + 1MB M4** - useful when you need to balance the memory equally between the M4 and M7 cores.
105
+
-**2MB M7 + M4 in SDRAM (default)** - this option is the default configuration, which is for programming the M7 only. This allocates no flash memory to the M4.
106
+
-**1.5MB M7 + 0.5MB M4** - useful when larger amount of flash memory is required on the M7.
107
+
-**1MB M7 + 1MB M4** - useful when you need to balance the flash memory equally between the M4 and M7 cores.
106
108
107
109
***It is required to use option 2 or 3 if you intend to program the M4 via the IDE, as the default option provides no memory allocation for the M4.***
108
110
@@ -144,30 +146,54 @@ Uploading new sketches works the same as a typical upload procedure. The new ske
144
146
145
147
## Identify Core Used
146
148
147
-
To identify which core is being used, we can utilize the `HAL_GetCurrentCPUID()` method. Below is a function that returns which core is used.
149
+
To identify which core is being used, use the `HAL_GetCurrentCPUID()` method. Below is a function that returns which core is currently being used. This can be useful to identify that your program is running on the right core.
148
150
149
151
```arduino
150
-
String currentCPU() {
152
+
/*
153
+
GIGA R1 WiFi - Core identify sketch.
154
+
155
+
This simple sketch blinks an LED on boot.
156
+
You will need to upload it to both the M7 and M4 core.
157
+
158
+
It checks whether current CPU is M7 or M4, and blinks either
159
+
the blue LED or the green LED, 10 times.
160
+
161
+
As the M4 is booted when invoking RPC.begin() on the M7,
162
+
the M4 sketch will run as soon as the blink() function
163
+
finishes on the M7.
164
+
*/
165
+
166
+
#include <RPC.h>
167
+
168
+
void setup() {
169
+
pinMode(LEDB, OUTPUT);
170
+
pinMode(LEDG, OUTPUT);
171
+
151
172
if (HAL_GetCurrentCPUID() == CM7_CPUID) {
152
-
return "M7";
173
+
blink(LEDB, 100); //blink blue LED (M7 core)
153
174
} else {
154
-
return "M4";
175
+
blink(LEDG, 100); //blink green LED (M4 core)
155
176
}
156
177
}
157
-
```
158
-
159
-
With this function, we check whether the M4 or M7 is running, and we can write code for each of the core like this:
160
178
161
-
```arduino
162
-
if (currentCPU() == "M4") {
163
-
//run M4 code
164
-
}
179
+
void loop() {
180
+
}
165
181
166
-
if (currentCPU() == "M7") {
167
-
//run M7 code
182
+
void blink(int led, int delaySeconds) {
183
+
for (int i; i < 10; i++) {
184
+
digitalWrite(led, LOW);
185
+
delay(delaySeconds);
186
+
digitalWrite(led, HIGH);
187
+
delay(delaySeconds);
168
188
}
189
+
RPC.begin();
190
+
}
169
191
```
170
192
193
+
- The `HAL_GetCurrentCPUID()` is a method that checks the CPU ID, and returns the value in a `uint32_t` format.
194
+
- The `CM7_CPUID` flag that we compare with holds the value `0x00000003` (hexadecimal), or `3` (decimal).
195
+
- It is also possible to use `CM4_CPUID` flag which holds the value `0x00000003`, or `1` (decimal).
196
+
171
197
## Remote Call Procedures (RPC)
172
198
173
199
RPC is a method that allows programs to make requests to programs located elsewhere. It is based on the client-server model (also referred to as caller/callee), where the client makes a request to the server.
0 commit comments