Skip to content

Commit 6ca6537

Browse files
committed
Add example to perform OTA with Ethernet on OPTA and PORTENTA_H7
1 parent 3e609d3 commit 6ca6537

File tree

2 files changed

+136
-0
lines changed

2 files changed

+136
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
/*
2+
* This example demonstrates how to use to update the firmware of the Arduino Portenta H7 using
3+
* a firmware image stored on the QSPI.
4+
*
5+
* Steps:
6+
* 1) Create a sketch for the Portenta H7 and verify
7+
* that it both compiles and works on a board.
8+
* 2) In the IDE select: Sketch -> Export compiled Binary.
9+
* 3) Create an OTA update file utilising the tools 'lzss.py' and 'bin2ota.py' stored in
10+
* https://github.com/arduino-libraries/ArduinoIoTCloud/tree/master/extras/tools .
11+
* A) ./lzss.py --encode SKETCH.bin SKETCH.lzss
12+
* B) ./bin2ota.py PORTENTA_H7_M7 SKETCH.lzss SKETCH.ota
13+
* 4) Upload the OTA file to a network reachable location, e.g. OTA_Usage_Portenta.ino.PORTENTA_H7_M7.ota
14+
* has been uploaded to: http://downloads.arduino.cc/ota/OTA_Usage_Portenta.ino.PORTENTA_H7_M7.ota
15+
* 5) Perform an OTA update via steps outlined below.
16+
*/
17+
18+
/******************************************************************************
19+
* INCLUDE
20+
******************************************************************************/
21+
22+
#include <Arduino_Portenta_OTA.h>
23+
24+
#include <Ethernet.h>
25+
26+
#include "arduino_secrets.h"
27+
28+
/******************************************************************************
29+
* CONSTANT
30+
******************************************************************************/
31+
32+
/* Please enter your sensitive data in the Secret tab/arduino_secrets.h */
33+
static char const SSID[] = SECRET_SSID; /* your network SSID (name) */
34+
static char const PASS[] = SECRET_PASS; /* your network password (use for WPA, or use as key for WEP) */
35+
36+
static char const OTA_FILE_LOCATION[] = "http://downloads.arduino.cc/ota/OTA_Usage_Portenta.ino.OPTA.ota";
37+
38+
/******************************************************************************
39+
* SETUP/LOOP
40+
******************************************************************************/
41+
42+
void setup()
43+
{
44+
Serial.begin(115200);
45+
while (!Serial) {}
46+
47+
//if (WiFi.status() == WL_NO_SHIELD)
48+
//{
49+
// Serial.println("Communication with WiFi module failed!");
50+
// return;
51+
//}
52+
53+
//int status = WL_IDLE_STATUS;
54+
while (Ethernet.linkStatus() == LinkOFF)
55+
{
56+
Serial.println ("Attempting to connect to");
57+
//Serial.print (SSID);
58+
//Serial.println("'");
59+
Ethernet.begin(nullptr, 15000, 4000);
60+
delay(10000);
61+
}
62+
Serial.println ("You're connected to '");
63+
//Serial.print (WiFi.SSID());
64+
//Serial.println("'");
65+
66+
67+
68+
Arduino_Portenta_OTA_QSPI ota(QSPI_FLASH_FATFS_MBR, 2);
69+
Arduino_Portenta_OTA::Error ota_err = Arduino_Portenta_OTA::Error::None;
70+
71+
Serial.println ("Mounted");
72+
73+
if (!ota.isOtaCapable())
74+
{
75+
Serial.println("Higher version bootloader required to perform OTA.");
76+
Serial.println("Please update the bootloader.");
77+
Serial.println("File -> Examples -> Portenta_System -> PortentaH7_updateBootloader");
78+
return;
79+
}
80+
81+
Serial.println ("Capable");
82+
83+
Serial.println("Initializing OTA storage");
84+
if ((ota_err = ota.begin()) != Arduino_Portenta_OTA::Error::None)
85+
{
86+
Serial.print ("Arduino_Portenta_OTA::begin() failed with error code ");
87+
Serial.println((int)ota_err);
88+
return;
89+
}
90+
91+
Serial.println ("Begin");
92+
93+
Serial.println("Starting download to QSPI ...");
94+
int const ota_download = ota.download(OTA_FILE_LOCATION, false /* is_https */);
95+
if (ota_download <= 0)
96+
{
97+
Serial.print ("Arduino_Portenta_OTA_QSPI::download failed with error code ");
98+
Serial.println(ota_download);
99+
return;
100+
}
101+
Serial.print (ota_download);
102+
Serial.println(" bytes stored.");
103+
104+
105+
Serial.println("Decompressing LZSS compressed file ...");
106+
int const ota_decompress = ota.decompress();
107+
if (ota_decompress < 0)
108+
{
109+
Serial.print("Arduino_Portenta_OTA_QSPI::decompress() failed with error code");
110+
Serial.println(ota_decompress);
111+
return;
112+
}
113+
Serial.print(ota_decompress);
114+
Serial.println(" bytes decompressed.");
115+
116+
117+
Serial.println("Storing parameters for firmware update in bootloader accessible non-volatile memory ...");
118+
if ((ota_err = ota.update()) != Arduino_Portenta_OTA::Error::None)
119+
{
120+
Serial.print ("ota.update() failed with error code ");
121+
Serial.println((int)ota_err);
122+
return;
123+
}
124+
125+
Serial.println("Performing a reset after which the bootloader will update the firmware.");
126+
Serial.println("Hint: Portenta H7 LED will blink Red-Blue-Green.");
127+
delay(1000); /* Make sure the serial message gets out before the reset. */
128+
ota.reset();
129+
}
130+
131+
void loop()
132+
{
133+
134+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#define SECRET_SSID "0_0"
2+
#define SECRET_PASS "smea86861518"

0 commit comments

Comments
 (0)