-
-
Notifications
You must be signed in to change notification settings - Fork 441
Portenta X8: Upload sketch to the M4 [PC-803] #207
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e70fe3c
Add draft
marqdevx dfe609a
Ad How it works section and small content fixes
marqdevx 272bb82
Fix small content and formatting
marqdevx 31e505c
Fix title case
marqdevx a4956db
Fix title
marqdevx 39405de
Empty commit
marqdevx 4abbc5d
Fix description
marqdevx 195f934
Spelling fixes and some additional explanations
sebromero 5dfe4d1
Update content/hardware/04.pro/boards/portenta-x8/tutorials/uploading…
marqdevx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file added
BIN
+73.1 KB
.../boards/portenta-x8/tutorials/uploading-sketches-m4/assets/x8-board-manager.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+32.8 KB
...rds/portenta-x8/tutorials/uploading-sketches-m4/assets/x8-terminal-ADB-push.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
82 changes: 82 additions & 0 deletions
82
...t/hardware/04.pro/boards/portenta-x8/tutorials/uploading-sketches-m4/content.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
--- | ||
title: 'Uploading Sketches to the M4 Core on Arduino Portenta X8' | ||
description: 'This tutorial explains how to upload Arduino sketches to the M4 core.' | ||
difficulty: medium | ||
tags: | ||
- firmware | ||
- M4 | ||
author: 'Pablo Marquínez' | ||
hardware: | ||
- hardware/04.pro/boards/portenta-x8 | ||
software: | ||
- ide-v1 | ||
- ide-v2 | ||
- cli | ||
--- | ||
|
||
## Overview | ||
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. | ||
|
||
## Goals | ||
- Learn how to use the Arduino IDE to compile and upload a sketch. | ||
- Learn how to compile the sketch binaries with the Arduino IDE and upload it manually via ADB. | ||
|
||
### Required Hardware and Software | ||
- [Portenta X8](https://store.arduino.cc/products/portenta-x8) | ||
- USB C cable (either USB A to USB C or USB C to USB C) | ||
- Arduino IDE 1.8.10+ or Arduino-cli | ||
- Latest "Arduino Mbed OS Portenta Boards" Core > 3.0.1 | ||
|
||
## Instructions | ||
|
||
### Standard Arduino IDE Upload | ||
Open the Arduino IDE, make sure you have selected the Portenta X8 in the boards selector. | ||
|
||
 | ||
|
||
Create a custom sketch or open one of the example sketches e.g. the blink sketch: | ||
```arduino | ||
void setup(){ | ||
pinMode(LED_BUILTIN ,OUTPUT); | ||
} | ||
|
||
void loop(){ | ||
digitalWrite(LED_BUILTIN , HIGH); | ||
delay(1000); | ||
digitalWrite(LED_BUILTIN , LOW); | ||
delay(1000); | ||
} | ||
``` | ||
|
||
- Select the port of your device in the port selector menu. | ||
- Press the Compile and Upload button. | ||
|
||
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. | ||
|
||
### Upload Manually Using ADB | ||
|
||
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. | ||
|
||
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`. | ||
|
||
From that directory you can use the `adb` tool. To upload your compiled sketch you just need to type: | ||
``` | ||
adb push <sketchBinaryPath> /tmp/arduino/m4-user-sketch.elf | ||
``` | ||
|
||
 | ||
|
||
## How It Works? | ||
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. | ||
|
||
This work thanks to the following services: | ||
* **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. | ||
* **android-tools-adbd.service**: responsible of generating the needed interfaces for the different types of usb gadgets. | ||
* **create-docker-envfile.service**: Controls if the device has been plugged for example in some carrier and makes the info available at `/var/run/arduino_hw_info.env` and is meant to be used by the ´docker containers´. | ||
|
||
## Conclusion | ||
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. | ||
|
||
## Troubleshooting | ||
|
||
- 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. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.