Skip to content

Commit 7fcd057

Browse files
committed
Add installation step by step
1 parent 7e99c8f commit 7fcd057

File tree

4 files changed

+107
-22
lines changed

4 files changed

+107
-22
lines changed
Loading
Loading
Loading

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

Lines changed: 107 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,22 @@ tags: [Dual Core, RPC, MicroPython]
77

88
The GIGA R1's microcontroller, the **STM32H747XI** has two processor cores, the **M7** and **M4**, clocking in at 480MHz and 240Mhz respectively.
99

10-
Having two cores in a microcontroller brings a significant advantage, to run two main applications simultaneuously, and communicate with them through something called **Remote Procedure Call (RPC)**.
11-
10+
Having two cores in a microcontroller brings a significant advantage, to run two main applications simultaneuously, and communicate with them through something called **Remote Procedure Call (RPC)**.
1211

1312
## Goals
1413

1514
In this tutorial, we will take a closer look at how to make use of the dual core, by:
16-
- Running MicroPython on the M7 core.
17-
- Running Arduino code on the M4 core.
18-
- Set up a communication line between the two cores through RPC.
15+
- Set up and run MicroPython on the M7 core.
16+
- Set up and run Arduino code on the M4 core.
17+
- Link, or bind, the two cores through RPC, using a specific serial protocol.
18+
- Control a servo motor by requesting the service from the M7 to the M4.
1919

2020
## Hardware & Software Needed
2121

22-
Hardware needed:
22+
The hardware needed for this project:
2323

24-
- [GIGA R1]() / [GIGA R1 WiFi]()
24+
- [GIGA R1](/hardware/giga-r1) / [GIGA R1 WiFi](/hardware/giga-r1-wifi)
25+
- Servo motor.
2526

2627
For programming the M4 core (C++):
2728

@@ -32,6 +33,10 @@ For programming the M7 core (MicroPython):
3233
- [dfu-util](https://dfu-util.sourceforge.net/)
3334
- [firmware.dfu](linktofw)
3435

36+
You will also need a MicroPython supported editor, such as:
37+
- [Arduino Lab for MicroPython](https://labs.arduino.cc/en/labs/micropython)
38+
- [Thonny](https://thonny.org/)
39+
3540
***The installation for `dfu-util` varies between operation systems. For installation using [brew.sh](https://formulae.brew.sh/formula/dfu-util) simply use `brew install dfu-util`.***
3641

3742
## Remote Procedure Call (RPC)
@@ -40,15 +45,15 @@ RPC is a method that allows programs to make requests to programs located elsewh
4045

4146
An RPC is a synchronous operation, and while a request is being made (client/caller) to another system, the operation is suspended. On return of the results, the operation is resumed. On the other side, (server/callee) performs the subroutine on request, and suspends any other operation as well. After it sends the result to the client, it resumes its operation, while waiting for another request.
4247

43-
![Request routine.]()
48+
![Request routine.](assets/rpc-basics.png)
4449

4550
### RPCs in the Arduino Environment
4651

4752
As some microcontrollers, including the STM32H747XI, has two processors, it is possible to program them both to perform individual tasks, and enable communication between them via an RPC.
4853

49-
The advantage of this is great, as you essentially have "two" Arduino boards running (on the some board). For example, you can run a machine learning module on one of the core, while another core is connected to a network system such as the [Arduino IoT Cloud](). Running these applications in parallel increases performance, as you split the work load and allow them to run with less blocking code for example.
54+
The advantage of this is great, as you essentially have "two" Arduino boards running (on the some board). For example, you can run a machine learning module on one of the core, while another core is connected to a network system such as the [Arduino IoT Cloud](https://create.arduino.cc/iot/). Running these applications in parallel increases performance, as you split the work load and allow them to run with less blocking code for example.
5055

51-
![Communication between cores]()
56+
![Communication between M7 and M4 core.](assets/rpc-m7-m4.png)
5257

5358
### RPC vs Multi-Threading
5459

@@ -72,15 +77,64 @@ The GIGA R1's STM32H747XI microcontroller includes the M7 and M4 core. In this e
7277
- Upload a sketch to the **M4 that sets it up as a client/caller**.
7378
- Make a request from the M4 to the M7.
7479

75-
### Installing MicroPython
80+
### 1. Upload Sketch to M4 Core
81+
82+
We will start by uploading a sketch to the M4 core, which will be running Arduino code. This requires the [Arduino IDE](https://www.arduino.cc/en/software) to be installed, as well as the **Arduino MbedOS OS GIGA Boards** core installed.
83+
84+
**1.1.** Open the Arduino IDE, and the board manager (in the menu to the left). Install the **Arduino MbedOS OS GIGA Boards** package.
85+
86+
**1.2.** Now we need to select the right board. This is **not** the GIGA R1, as the default is H7. We instead need to select the **STM32H747 M4 coprocessor**. This is the M4 on the GIGA R1.
87+
88+
**1.3.** With the board selected, you will now have the option to select **Flash Split** and **Target Board**. These are manual options available in the **Tools** section of the IDE. Here, we need to select the **1.5MB M7 + 0.5MB M4** configuration for the Flash Split, and **Giga** for Target Board.
89+
90+
![Select Flash Split + Target board.](assets/flash-split.png)
91+
92+
**1.4.** Upload the following sketch to the board:
93+
94+
```arduino
95+
#include "RPC.h"
96+
#include <Servo.h>
97+
98+
uint32_t servo_new(uint32_t id) {
99+
Servo* servo = new Servo();
100+
return (uint32_t)servo;
101+
}
102+
103+
void servo_attach(uint32_t id, int pin) {
104+
Servo* servo = (Servo*)id;
105+
servo->attach(pin);
106+
}
107+
108+
void servo_write(uint32_t id, float angle) {
109+
Servo* servo = (Servo*)id;
110+
servo->write(angle);
111+
}
112+
113+
void setup() {
114+
RPC.begin();
115+
RPC.bind("servo_new", servo_new);
116+
RPC.bind("servo_attach", servo_attach);
117+
RPC.bind("servo_write", servo_write);
118+
}
119+
120+
void loop() {
121+
delay(1000);
122+
}
123+
```
124+
125+
### 2. Installing MicroPython
126+
127+
To install MicroPython on the GIGA R1, you will need to flash a specific MicroPython firmware to the **M7 processor.** This requires the [dfu-util](https://dfu-util.sourceforge.net/) tool.
76128

77-
To install MicroPython on the GIGA R1, you will need to flash a specific MicroPython firmware to the **M7 processor.** This requires the [dfu-util]() tool.
129+
**2.1.** Download the [MicroPython firmware for GIGA R1]().
78130

79-
1. Download the [MicroPython firmware for GIGA R1]().
80-
2. Download [dfu-util]() (also available via [brew.sh](https://formulae.brew.sh/formula/dfu-util)). Make sure the tool is added to your PATH on your machine.
81-
3. Open a terminal, and navigate to the directory where you saved the downloaded MicroPython firmware.
82-
4. Double tap the reset button on the GIGA R1 (while it is powered). This will enter bootloader mode.
83-
5. Finally, load the MicroPython firmware, by using the following command:
131+
**2.2.** Download [dfu-util](https://dfu-util.sourceforge.net/) (also available via [brew.sh](https://formulae.brew.sh/formula/dfu-util)). Make sure the tool is added to PATH on your machine.
132+
133+
**2.3.** Open a terminal, and navigate to the directory where you saved the downloaded MicroPython firmware.
134+
135+
**2.4.** Double tap the reset button on the GIGA R1 (while it is powered). This will enter bootloader mode.
136+
137+
**2.5.** Finally, load the MicroPython firmware, by using the following command:
84138

85139
```sh
86140
dfu-util -w -a 0 -d 2341:0366 -D <firmware>.dfu
@@ -90,15 +144,46 @@ This will start an uploading process that can be tracked in the terminal. Once i
90144

91145
Make sure to reset the board before continuing (tap the reset button).
92146

93-
### Flash M4
147+
### 3. MessagePack
94148

95-
### Load MicroPython Script
149+
***[MessagePack]() is a serialization protocol made by Peter Hinch that we are using in this implementation to communicate between the cores.***
96150

151+
In order to implement an RPC between the M4 and M7 cores, we use MessagePack, or the `umsg` module. This module needs to be present on your board, so that we can use it a MicroPython script (it is not part of the MicroPython installation).
97152

98-
###
153+
When we install MicroPython on the M7 core, we create a mass storage device that we can simply drag and drop files to.
99154

155+
**3.1.** First, download the [umsg module]() and unpack it.
100156

101-
## Conclusion
157+
**3.2.** Open the mass storage device (available in e.g. finder), and drag only the `umsg` folder to the root of the mass storage device.
158+
159+
![Drag and drop the umsg folder.]()
160+
161+
You now have the `umsg` module available on your board, and can be called from a MicroPython script.
162+
163+
### 4. Load MicroPython Script
164+
165+
The final step is to load a MicroPython script to the M7 that will interact with the M4 core, essentially using the "server-client" protocol.
166+
167+
**4.1.** Open the MicroPython editor (such as [Arduino Lab for MicroPython](https://labs.arduino.cc/en/labs/micropython)).
102168

103-
Add a conclusion to what this tutorial has gone through. Connect back to what you wrote in the "Goals" section.
169+
**4.2.** Select/connect your board. You can test out if it is connected properly to your computer by running a simple `print ("test")`. If it shows in the REPL, it works.
170+
171+
**4.3.** Paste the script below to the editor, and press the play/run button.
172+
173+
```python
174+
import arduino
175+
arduino.init()
176+
servo = arduino.Servo()
177+
servo.attach(6)
178+
servo.write(64)
179+
```
180+
181+
This basic script includes the API for controlling a servo motor. But, the main difference here, is that the servo motor is controlled on the M4 core.
182+
183+
When for example `servo.attach(6)` is run, this action is not executed on the M7 core, but instead requested to run on the M4.
184+
185+
You can revisit [the code in the first step](#1-upload-sketch-to-m4-core), to understand how the link is made between the MicroPython script, and the Arduino sketch.
186+
187+
## Conclusion
104188

189+
At the end of this tutorial, we have achieved the communication between the M4 and the M7 core, via something called **RPC**. The example used in this tutorial is a servo motor, but there are of course many more alternatives that you can choose from.

0 commit comments

Comments
 (0)