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
+34-80Lines changed: 34 additions & 80 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -36,9 +36,39 @@ 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?
40
+
41
+
The M4 processor can access most of the peripherals that the M7 can access, with some exceptions.
42
+
43
+
The M4 supports:
44
+
- Wi-Fi®
45
+
- I2C
46
+
- SPI
47
+
- UART
48
+
- CAN
49
+
- DAC
50
+
- ADC
51
+
- Bluetooth® Low Energy (via [ArduinoBLE Library](https://www.arduino.cc/reference/en/libraries/arduinoble/))
52
+
53
+
The M4 does **not** support:
54
+
- Serial communication\*
55
+
- Arduino Cloud sketches.
56
+
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).***
58
+
39
59
## Programming M4/M7
40
60
41
-
Programming the cores is done via the Arduino IDE, in a special interface that appears only when you **select the Arduino GIGA R1 board** from the board menu.
61
+
When programming the GIGA R1 WiFi's M7 and M4, we **create a sketch for each core**, and program them like we would program two individual Arduino boards. As only a single serial port is available, we need to specify which core we want to target.
62
+
63
+
Some essential things to consider when programming the cores are:
64
+
- You need to [partition the memory](#partitioning-the-flash-memory), allocating flash memory to the M4 core.
65
+
- You need to select the [target core](#target-core), which is either **Main Core** or **M4 Co-processor**.
66
+
- The M4 has no serial communication enabled, here we need to use RPC (see [RPC Serial example](#rpc-serial)).
67
+
68
+
When writing multiple sketches, there are some things to consider to make your development experience easier:
69
+
- Name your sketches with either `_M4` or `_M7` suffix or prefix. This will make it easier if the code is intended to be shared with others.
70
+
- Consider having a starting sequence (e.g. the blue LED blinking 3 times), whenever a core is initialized.
71
+
- Always include `RPC.begin()` on your M7 core sketch.
42
72
43
73
### Partitioning The Flash Memory
44
74
@@ -84,73 +114,14 @@ void loop(){
84
114
85
115
Once the M4 is booted from the M7, both cores will run in parallel, much like two Arduinos sharing the same board.
86
116
117
+
87
118
### Writing Over Existing Sketch
88
119
89
120
Uploading new sketches works the same as a typical upload procedure. The new sketch will overwrite the current sketch running on the core you upload to.
90
121
91
-
## Limitations
92
-
93
-
The M7 and M4 cores are two separate cores, and when initialized, they will continue to execute their corresponding program.
94
-
95
-
In this section you will find some known limitations of using the two parallel cores.
96
-
97
-
### Booting M4
98
-
99
-
As mentioned in the previous section, the M4 requires to be booted from the M7, by using the `RPC.begin()` method. If this is not included, the M4 will not boot.
100
-
101
-
### Serial Communication
102
-
103
-
Serial communication is not available by default on the M4 core. A work around for this is by sending data using the `RPC` library, and printing it from the M7 core. To achieve this, see the following examples:
104
-
105
-
**M4 Sketch**
106
-
107
-
```arduino
108
-
#include <RPC.h>
109
-
110
-
void setup() {
111
-
RPC.begin();
112
-
}
113
-
114
-
void loop() {
115
-
// put your main code here, to run repeatedly:
116
-
RPC.println("Hello World!");
117
-
}
118
-
```
119
-
120
-
**M7 Sketch**
121
-
122
-
```arduino
123
-
#include <RPC.h>
124
-
125
-
void setup() {
126
-
// put your setup code here, to run once:
127
-
Serial.begin(9600);
128
-
RPC.begin();
129
-
}
130
-
131
-
void loop() {
132
-
String buffer = "";
133
-
while (RPC.available()) {
134
-
buffer += (char)RPC.read();
135
-
}
136
-
137
-
if (buffer.length() > 0) {
138
-
Serial.print(buffer);
139
-
}
140
-
}
141
-
```
142
-
143
-
***Note that both of these sketches needs to be uploaded to their corresponding cores.***
122
+
## Identify Core Used
144
123
145
-
## Methods of Programming
146
-
147
-
Programming the M4 and M7 cores is straightforward, but can be complicated to track. Having a strategy for how you want to build your dual core applications is key.
148
-
149
-
In this section we introduce the "single" and "multiple" sketch approach, and the pros and cons of each method.
150
-
151
-
### Single Sketch Approach
152
-
153
-
The single sketch approach means writing a single sketch that is **uploaded to both cores** each time a change is made. In the sketch, we can keep track of what each core does, simply by querying the core used with a simple function:
124
+
To identify which core is being used, we can utilize the `HAL_GetCurrentCPUID()` method. Below is a function that returns which core is used.
154
125
155
126
```arduino
156
127
String currentCPU() {
@@ -174,23 +145,6 @@ With this function, we check whether the M4 or M7 is running, and we can write c
174
145
}
175
146
```
176
147
177
-
The pros of using this approach is that you can write all code in a single file, therefore, revisioning code, as well as the provisioning is easier to manage.
178
-
179
-
The cons of using this approach is that you will run out of program memory faster. You will also upload code to the cores that will never execute (the M7 code will not execute on M4 and vice versa).
180
-
181
-
### Multiple Sketch Approach
182
-
183
-
The multiple sketch approach means developing two separate sketches, one for each core. This does not require the use of the `HAL_GetCurrentCPUID()` to retrieve the core you are using, you can instead just write sketches as you would normally do.
184
-
185
-
The pros of using this approach is that the code you write is optimized only for one core, and this saves a lot of program memory.
186
-
187
-
The cons is to manage the versions becomes harder, and while flashing the board, you'd need to keep track on which version is uploaded to which core. It is easier to upload to the wrong core by accident using this approach, but you have more optimized code.
188
-
189
-
When writing multiple sketches, there are some things to consider to make your development experience easier:
190
-
- Name your sketches with either `_M4` or `_M7` suffix or prefix. This will make it easier if the code is intended to be shared with others.
191
-
- Consider having a starting sequence (e.g. the blue LED blinking 3 times), whenever a core is initialized.
192
-
- Always include `RPC.begin()` on your M7 core sketch.
193
-
194
148
## Remote Call Procedures (RPC)
195
149
196
150
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