Skip to content

Commit a7eae5b

Browse files
committed
Update SD example
1 parent 8dd7596 commit a7eae5b

File tree

2 files changed

+97
-11
lines changed

2 files changed

+97
-11
lines changed
+95-11
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,128 @@
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 a SD card.
2+
* This example demonstrates how to use to update the firmware of the Arduino Portenta H7 using
3+
* a firmware image stored on the SD.
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 PORTENTA_H7_M7.lzss
12+
* B) ./bin2ota.py PORTENTA_H7_M7.lzss PORTENTA_H7_M7.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.
516
*/
617

7-
#include "Arduino_Portenta_OTA.h"
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://downloads.arduino.cc/ota/OTA_Usage_Portenta.ino.PORTENTA_H7_M7.ota";
37+
38+
/******************************************************************************
39+
* SETUP/LOOP
40+
******************************************************************************/
841

942
void setup()
1043
{
1144
Serial.begin(115200);
1245
while (!Serial) {}
1346

14-
Serial.println("*****OTA from SD*****");
15-
Arduino_Portenta_OTA_SD ota(SD_OFFSET, 10240);
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("'");
65+
66+
//Arduino_Portenta_OTA_SD ota(SD_FATFS, 0);
67+
Arduino_Portenta_OTA_SD ota(SD_FATFS_MBR, 1);
1668
Arduino_Portenta_OTA::Error ota_err = Arduino_Portenta_OTA::Error::None;
1769

70+
if (!ota.isOtaCapable())
71+
{
72+
Serial.println("Higher version bootloader required to perform OTA.");
73+
Serial.println("Please update the bootloader.");
74+
Serial.println("File -> Examples -> Portenta_System -> PortentaH7_updateBootloader");
75+
return;
76+
}
77+
1878
Serial.println("Initializing OTA storage");
1979
if ((ota_err = ota.begin()) != Arduino_Portenta_OTA::Error::None)
2080
{
21-
Serial.print ("ota.begin() failed with error code ");
81+
Serial.print ("Arduino_Portenta_OTA::begin() failed with error code ");
2282
Serial.println((int)ota_err);
2383
return;
2484
}
2585

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);
86+
87+
Serial.println("Starting download to SD ...");
88+
int const ota_download = ota.download(OTA_FILE_LOCATION, false /* is_https */);
89+
if (ota_download <= 0)
90+
{
91+
Serial.print ("Arduino_Portenta_OTA_SD::download failed with error code ");
92+
Serial.println(ota_download);
93+
return;
94+
}
95+
Serial.print (ota_download);
96+
Serial.println(" bytes stored.");
97+
98+
99+
Serial.println("Decompressing LZSS compressed file ...");
100+
int const ota_decompress = ota.decompress();
101+
if (ota_decompress < 0)
102+
{
103+
Serial.print("Arduino_Portenta_OTA_SD::decompress() failed with error code");
104+
Serial.println(ota_decompress);
105+
return;
106+
}
107+
Serial.print(ota_decompress);
108+
Serial.println(" bytes decompressed.");
109+
28110

29111
Serial.println("Storing parameters for firmware update in bootloader accessible non-volatile memory");
30112
if ((ota_err = ota.update()) != Arduino_Portenta_OTA::Error::None)
31113
{
32-
Serial.print ("ota.update() failed with error code ");
114+
Serial.print ("Arduino_Portenta_OTA::update() failed with error code ");
33115
Serial.println((int)ota_err);
34116
return;
35117
}
36118

37119
Serial.println("Performing a reset after which the bootloader will update the firmware.");
120+
Serial.println("Hint: Portenta H7 LED will blink Red-Blue-Green.");
121+
delay(1000);
38122
ota.reset();
39123
}
40124

41125
void loop()
42126
{
43127

44-
}
128+
}
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)