Skip to content

Commit 23b820f

Browse files
added example for download and decompress for ota images
1 parent 20855e8 commit 23b820f

File tree

2 files changed

+139
-0
lines changed

2 files changed

+139
-0
lines changed
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
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 <WiFi.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+
#if defined(ARDUINO_NICLA_VISION)
37+
static char const OTA_FILE_LOCATION[] = "https://downloads.arduino.cc/ota/OTA_Usage_Portenta.ino.NICLA_VISION.ota";
38+
#elif defined(ARDUINO_PORTENTA_H7_M7)
39+
static char const OTA_FILE_LOCATION[] = "https://downloads.arduino.cc/ota/OTA_Usage_Portenta.ino.PORTENTA_H7_M7.ota";
40+
#elif defined(ARDUINO_OPTA)
41+
static char const OTA_FILE_LOCATION[] = "https://downloads.arduino.cc/ota/OTA_Usage_Portenta.ino.OPTA.ota";
42+
#elif defined(ARDUINO_GIGA)
43+
static char const OTA_FILE_LOCATION[] = "https://downloads.arduino.cc/ota/OTA_Usage_Portenta.ino.GIGA.ota";
44+
#else
45+
#error "Board not supported"
46+
#endif
47+
48+
/******************************************************************************
49+
* SETUP/LOOP
50+
******************************************************************************/
51+
52+
void setup()
53+
{
54+
Serial.begin(115200);
55+
while (!Serial) {}
56+
57+
if (WiFi.status() == WL_NO_SHIELD)
58+
{
59+
Serial.println("Communication with WiFi module failed!");
60+
return;
61+
}
62+
63+
int status = WL_IDLE_STATUS;
64+
while (status != WL_CONNECTED)
65+
{
66+
Serial.print ("Attempting to connect to '");
67+
Serial.print (SSID);
68+
Serial.println("'");
69+
status = WiFi.begin(SSID, PASS);
70+
if(status != WL_CONNECTED) {
71+
delay(10000);
72+
}
73+
}
74+
Serial.print ("You're connected to '");
75+
Serial.print (WiFi.SSID());
76+
Serial.println("'");
77+
78+
Arduino_Portenta_OTA_QSPI ota(QSPI_FLASH_FATFS_MBR, 2);
79+
Arduino_Portenta_OTA::Error ota_err = Arduino_Portenta_OTA::Error::None;
80+
81+
if (!ota.isOtaCapable())
82+
{
83+
Serial.println("Higher version bootloader required to perform OTA.");
84+
Serial.println("Please update the bootloader.");
85+
Serial.println("File -> Examples -> Portenta_System -> PortentaH7_updateBootloader");
86+
return;
87+
}
88+
89+
Serial.println("Initializing OTA storage");
90+
if ((ota_err = ota.begin()) != Arduino_Portenta_OTA::Error::None)
91+
{
92+
Serial.print ("Arduino_Portenta_OTA::begin() failed with error code ");
93+
Serial.println((int)ota_err);
94+
return;
95+
}
96+
97+
uint32_t start = millis();
98+
float elapsed, speed;
99+
100+
Serial.println("Starting download to QSPI ...");
101+
int const ota_download = ota.downloadAndDecompress(OTA_FILE_LOCATION, true /* is_https */);
102+
if (ota_download <= 0)
103+
{
104+
Serial.print ("Arduino_Portenta_OTA_QSPI::download failed with error code ");
105+
Serial.println(ota_download);
106+
return;
107+
}
108+
Serial.print (ota_download);
109+
Serial.println(" bytes stored.");
110+
111+
elapsed = (millis()-start)/1000.0; // elapsed expressed in seconds
112+
speed = (ota_download/elapsed)/1024;
113+
114+
Serial.print("download elapsed ");
115+
Serial.print(elapsed);
116+
Serial.print("s speed: ");
117+
Serial.print(speed);
118+
Serial.println("KBps");
119+
120+
Serial.println("Storing parameters for firmware update in bootloader accessible non-volatile memory ...");
121+
if ((ota_err = ota.update()) != Arduino_Portenta_OTA::Error::None)
122+
{
123+
Serial.print ("ota.update() failed with error code ");
124+
Serial.println((int)ota_err);
125+
return;
126+
}
127+
128+
Serial.println("Performing a reset after which the bootloader will update the firmware.");
129+
Serial.println("Hint: Portenta H7 LED will blink Red-Blue-Green.");
130+
delay(1000); /* Make sure the serial message gets out before the reset. */
131+
ota.reset();
132+
}
133+
134+
void loop()
135+
{
136+
137+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#define SECRET_SSID ""
2+
#define SECRET_PASS ""

0 commit comments

Comments
 (0)