Skip to content

Commit fa1d1a3

Browse files
authored
Merge pull request #207 from arduino/marqdevx/portenta-X8/upload-sketches
Portenta X8: Upload sketch to the M4 [PC-803]
2 parents fb5112e + 5dfe4d1 commit fa1d1a3

File tree

3 files changed

+80
-0
lines changed

3 files changed

+80
-0
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
---
2+
title: 'Uploading Sketches to the M4 Core on Arduino Portenta X8'
3+
description: 'This tutorial explains how to upload Arduino sketches to the M4 core.'
4+
difficulty: medium
5+
tags:
6+
- firmware
7+
- M4
8+
author: 'Pablo Marquínez'
9+
hardware:
10+
- hardware/04.pro/boards/portenta-x8
11+
software:
12+
- ide-v1
13+
- ide-v2
14+
- cli
15+
---
16+
17+
## Overview
18+
In this tutorial we will go through the process of uploading sketches to the M4 core on the STM32H747XI MCU. For the user the process is the same as usual but it differs quite a bit in regards to what happens behind the scenes compared to other Arduino boards.
19+
20+
## Goals
21+
- Learn how to use the Arduino IDE to compile and upload a sketch.
22+
- Learn how to compile the sketch binaries with the Arduino IDE and upload it manually via ADB.
23+
24+
### Required Hardware and Software
25+
- [Portenta X8](https://store.arduino.cc/products/portenta-x8)
26+
- USB C cable (either USB A to USB C or USB C to USB C)
27+
- Arduino IDE 1.8.10+ or Arduino-cli
28+
- Latest "Arduino Mbed OS Portenta Boards" Core > 3.0.1
29+
30+
## Instructions
31+
32+
### Standard Arduino IDE Upload
33+
Open the Arduino IDE, make sure you have selected the Portenta X8 in the boards selector.
34+
35+
![IDE board selector](assets/x8-board-manager.png)
36+
37+
Create a custom sketch or open one of the example sketches e.g. the blink sketch:
38+
```arduino
39+
void setup(){
40+
pinMode(LED_BUILTIN ,OUTPUT);
41+
}
42+
43+
void loop(){
44+
digitalWrite(LED_BUILTIN , HIGH);
45+
delay(1000);
46+
digitalWrite(LED_BUILTIN , LOW);
47+
delay(1000);
48+
}
49+
```
50+
51+
- Select the port of your device in the port selector menu.
52+
- Press the Compile and Upload button.
53+
54+
Behind the curtains, the sketch gets compiled into a binary. That binary file is then uploaded to the Linux side of the Portenta X8 via an `adb` SSH connection. The flashing itself is done on the board itself by a service running on Linux. When the sketch has bee uploaded successfully, check if the onboard LED is blinking at an interval of one second.
55+
56+
### Upload Manually Using ADB
57+
58+
To upload a firmware manually, you first need to compile the sketch. In the Arduino IDE select "Export compiled binary" from the Sketch menu. It will compile the sketch and save the binary file in the sketch folder. Alternatively you can use the [Arduino CLI](https://arduino.github.io/arduino-cli/) to create an elf file.
59+
60+
To upload the firmware you can use the ADB tool that has been installed as part of the Portenta X8 core. It can be found at `Arduino15\packages\arduino\tools\adb\32.0.0`.
61+
62+
From that directory you can use the `adb` tool. To upload your compiled sketch you just need to type:
63+
```
64+
adb push <sketchBinaryPath> /tmp/arduino/m4-user-sketch.elf
65+
```
66+
67+
![ADB upload with a terminal](assets/x8-terminal-ADB-push.png)
68+
69+
## How It Works?
70+
The Portenta X8 has a service that waits for a sketch to be uploaded to a folder. If it detects changes the device will flash the M4 with the uploaded firmware.
71+
72+
This work thanks to the following services:
73+
* **monitor-m4-elf-file.service**: this service monitors the directory `/tmp/arduino/m4-user-sketch.elf` and each time it detects a new file it will proceed to flash the M4 using `openOCD` with the sketch that has been pushed.
74+
75+
## Conclusion
76+
In this tutorial you have learned how to upload a sketch to the M4 core. Now for example you are able to connect an I<sup>2</sup>C sensor and interact with it.
77+
78+
## Troubleshooting
79+
80+
- If you cannot use the `ADB` tool and the folder `Arduino15\packages\arduino\tools\adb\32.0.0` is empty Remove the Mbed Portenta Core and install it again.

0 commit comments

Comments
 (0)