Skip to content

Commit 5c2ad83

Browse files
committed
Update giga-dual-core.md
1 parent 03de29e commit 5c2ad83

File tree

1 file changed

+46
-20
lines changed
  • content/hardware/10.mega/boards/giga-r1-wifi/tutorials/giga-dual-core

1 file changed

+46
-20
lines changed

content/hardware/10.mega/boards/giga-r1-wifi/tutorials/giga-dual-core/giga-dual-core.md

Lines changed: 46 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ In this guide you will discover:
3636

3737
***\*For instructions on how to install the GIGA Core, follow the [Getting Started with GIGA R1 guide](/tutorials/giga-r1-wifi/giga-getting-started).***
3838

39-
## What is Supported on M4?
39+
## M4 Support
4040

4141
The M4 processor can access most of the peripherals that the M7 can access, with some exceptions.
4242

@@ -54,11 +54,11 @@ The M4 does **not** support:
5454
- Serial communication\*
5555
- [Arduino Cloud](https://app.arduino.cc) sketches.
5656

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 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).***
5858

5959
### Boot / Disable M4
6060

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.
6262

6363
### Boot / Disable M7
6464

@@ -96,13 +96,15 @@ When writing multiple sketches, there are some things to consider to make your d
9696

9797
### Partitioning The Flash Memory
9898

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).***
100102

101103
![Flash partitioning in the IDE.](assets/flash-split.png)
102104

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.
106108

107109
***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.***
108110

@@ -144,30 +146,54 @@ Uploading new sketches works the same as a typical upload procedure. The new ske
144146

145147
## Identify Core Used
146148

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.
148150

149151
```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+
151172
if (HAL_GetCurrentCPUID() == CM7_CPUID) {
152-
return "M7";
173+
blink(LEDB, 100); //blink blue LED (M7 core)
153174
} else {
154-
return "M4";
175+
blink(LEDG, 100); //blink green LED (M4 core)
155176
}
156177
}
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:
160178
161-
```arduino
162-
if (currentCPU() == "M4") {
163-
//run M4 code
164-
}
179+
void loop() {
180+
}
165181
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);
168188
}
189+
RPC.begin();
190+
}
169191
```
170192

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+
171197
## Remote Call Procedures (RPC)
172198

173199
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

Comments
 (0)