1
1
/*
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.
5
16
*/
6
17
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
+ ******************************************************************************/
8
41
9
42
void setup ()
10
43
{
11
44
Serial.begin (115200 );
12
45
while (!Serial) {}
13
46
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 );
16
68
Arduino_Portenta_OTA::Error ota_err = Arduino_Portenta_OTA::Error::None;
17
69
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
+
18
78
Serial.println (" Initializing OTA storage" );
19
79
if ((ota_err = ota.begin ()) != Arduino_Portenta_OTA::Error::None)
20
80
{
21
- Serial.print (" ota. begin() failed with error code " );
81
+ Serial.print (" Arduino_Portenta_OTA:: begin() failed with error code " );
22
82
Serial.println ((int )ota_err);
23
83
return ;
24
84
}
25
85
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
+
28
110
29
111
Serial.println (" Storing parameters for firmware update in bootloader accessible non-volatile memory" );
30
112
if ((ota_err = ota.update ()) != Arduino_Portenta_OTA::Error::None)
31
113
{
32
- Serial.print (" ota. update() failed with error code " );
114
+ Serial.print (" Arduino_Portenta_OTA:: update() failed with error code " );
33
115
Serial.println ((int )ota_err);
34
116
return ;
35
117
}
36
118
37
119
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 );
38
122
ota.reset ();
39
123
}
40
124
41
125
void loop ()
42
126
{
43
127
44
- }
128
+ }
0 commit comments