Skip to content

Commit 53cac12

Browse files
committed
Adding example on how to perform OTA with the QSPI as storage method.
1 parent fbd1df9 commit 53cac12

File tree

3 files changed

+85
-9
lines changed

3 files changed

+85
-9
lines changed

examples/OTA_Qspi_Flash/OTA_Qspi_Flash.ino

Lines changed: 83 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,105 @@
11
/*
2-
This example demonstrates how to use to update
3-
the firmware of the Arduino Portenta H7 using
4-
a firmware image stored on the QSPI.
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 verifiy
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://www.107-systems.org/ota/OTA_Usage_Portenta.ino.PORTENTA_H7_M7.ota
15+
* 5) Perform an OTA update via steps outlined below.
516
*/
6-
#include "Arduino_Portenta_OTA.h"
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+
static char const OTA_FILE_LOCATION[] = "http://www.107-systems.org/ota/OTA_Usage_Portenta.ino.PORTENTA_H7_M7.ota";
37+
38+
/******************************************************************************
39+
* SETUP/LOOP
40+
******************************************************************************/
741

842
void setup()
943
{
1044
Serial.begin(115200);
1145
while (!Serial) {}
1246

13-
Serial.println("*****OTA from QSPI Flash*****");
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 (status != WL_CONNECTED)
55+
{
56+
Serial.print ("Attempting to connect to '");
57+
Serial.print (SSID);
58+
Serial.println("'");
59+
status = WiFi.begin(SSID, PASS);
60+
delay(10000);
61+
}
62+
Serial.print ("You're connected to '");
63+
Serial.print (WiFi.SSID());
64+
Serial.println("'");
1465

1566
Arduino_Portenta_OTA_QSPI ota(QSPI_FLASH_FATFS_MBR, 2);
1667
Arduino_Portenta_OTA::Error ota_err = Arduino_Portenta_OTA::Error::None;
1768

1869
Serial.println("Initializing OTA storage");
1970
if ((ota_err = ota.begin()) != Arduino_Portenta_OTA::Error::None)
2071
{
21-
Serial.print ("ota.begin() failed with error code ");
72+
Serial.print ("Arduino_Portenta_OTA::begin() failed with error code ");
2273
Serial.println((int)ota_err);
2374
return;
2475
}
2576

26-
/* This function sets the precise length of update binary, in this case of OTA_Usage_Portenta.ino.PORTENTA_H7_M7.bin */
27-
ota.setUpdateLen(131728);
2877

29-
Serial.println("Storing parameters for firmware update in bootloader accessible non-volatile memory");
78+
Serial.println("Starting download to QSPI ...");
79+
int const ota_download = ota.download(OTA_FILE_LOCATION);
80+
if (ota_download <= 0)
81+
{
82+
Serial.print ("Arduino_Portenta_OTA_QSPI::download failed with error code ");
83+
Serial.println(ota_download);
84+
return;
85+
}
86+
Serial.print (ota_download);
87+
Serial.println(" bytes stored.");
88+
89+
90+
Serial.println("Decompressing LZSS compressed file ...");
91+
int const ota_decompress = ota.decompress();
92+
if (ota_decompress < 0)
93+
{
94+
Serial.print("Arduino_Portenta_OTA_QSPI::decompress() failed with error code");
95+
Serial.println(ota_decompress);
96+
return;
97+
}
98+
Serial.print(ota_decompress);
99+
Serial.println(" bytes decompressed.");
100+
101+
102+
Serial.println("Storing parameters for firmware update in bootloader accessible non-volatile memory ...");
30103
if ((ota_err = ota.update()) != Arduino_Portenta_OTA::Error::None)
31104
{
32105
Serial.print ("ota.update() failed with error code ");
@@ -35,6 +108,7 @@ void setup()
35108
}
36109

37110
Serial.println("Performing a reset after which the bootloader will update the firmware.");
111+
Serial.println("Hint: Portenta H7 LED will blink Red-Blue-Green.");
38112
ota.reset();
39113
}
40114

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 ""
Binary file not shown.

0 commit comments

Comments
 (0)