Skip to content

Commit 5457939

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

File tree

1 file changed

+113
-0
lines changed

1 file changed

+113
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
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+
/******************************************************************************
27+
* CONSTANT
28+
******************************************************************************/
29+
#if defined(ARDUINO_OPTA)
30+
static char const OTA_FILE_LOCATION[] = "http://downloads.arduino.cc/ota/OTA_Usage_Portenta.ino.OPTA.ota";
31+
#elif defined(ARDUINO_PORTENTA_H7_M7)
32+
static char const OTA_FILE_LOCATION[] = "http://downloads.arduino.cc/ota/OTA_Usage_Portenta.ino.PORTENTA_H7_M7.ota";
33+
#else
34+
#error "Board not supported"
35+
#endif
36+
37+
/******************************************************************************
38+
* SETUP/LOOP
39+
******************************************************************************/
40+
41+
void setup()
42+
{
43+
Serial.begin(115200);
44+
while (!Serial) {}
45+
46+
while (Ethernet.linkStatus() == LinkOFF)
47+
{
48+
Serial.println("Attempting to connect to the network ...");
49+
Ethernet.begin();
50+
}
51+
Serial.println("Connected");
52+
53+
Arduino_Portenta_OTA_QSPI ota(QSPI_FLASH_FATFS_MBR, 2);
54+
Arduino_Portenta_OTA::Error ota_err = Arduino_Portenta_OTA::Error::None;
55+
56+
if (!ota.isOtaCapable())
57+
{
58+
Serial.println("Higher version bootloader required to perform OTA.");
59+
Serial.println("Please update the bootloader.");
60+
Serial.println("File -> Examples -> STM32H747_System -> STM32H747_manageBootloader");
61+
return;
62+
}
63+
64+
Serial.println("Initializing OTA storage");
65+
if ((ota_err = ota.begin()) != Arduino_Portenta_OTA::Error::None)
66+
{
67+
Serial.print ("Arduino_Portenta_OTA::begin() failed with error code ");
68+
Serial.println((int)ota_err);
69+
return;
70+
}
71+
72+
Serial.println("Starting download to QSPI ...");
73+
int const ota_download = ota.download(OTA_FILE_LOCATION, false /* is_https */);
74+
if (ota_download <= 0)
75+
{
76+
Serial.print ("Arduino_Portenta_OTA_QSPI::download failed with error code ");
77+
Serial.println(ota_download);
78+
return;
79+
}
80+
Serial.print (ota_download);
81+
Serial.println(" bytes stored.");
82+
83+
84+
Serial.println("Decompressing LZSS compressed file ...");
85+
int const ota_decompress = ota.decompress();
86+
if (ota_decompress < 0)
87+
{
88+
Serial.print("Arduino_Portenta_OTA_QSPI::decompress() failed with error code");
89+
Serial.println(ota_decompress);
90+
return;
91+
}
92+
Serial.print(ota_decompress);
93+
Serial.println(" bytes decompressed.");
94+
95+
96+
Serial.println("Storing parameters for firmware update in bootloader accessible non-volatile memory ...");
97+
if ((ota_err = ota.update()) != Arduino_Portenta_OTA::Error::None)
98+
{
99+
Serial.print ("ota.update() failed with error code ");
100+
Serial.println((int)ota_err);
101+
return;
102+
}
103+
104+
Serial.println("Performing a reset after which the bootloader will update the firmware.");
105+
Serial.println("Hint: Board LED will blink Red-Blue-Green.");
106+
delay(1000); /* Make sure the serial message gets out before the reset. */
107+
ota.reset();
108+
}
109+
110+
void loop()
111+
{
112+
113+
}

0 commit comments

Comments
 (0)