Skip to content

Commit 2075ad0

Browse files
authored
Merge pull request #34 from pennam/opta
Add support for opta board
2 parents 730ba6f + f842b37 commit 2075ad0

File tree

4 files changed

+128
-1
lines changed

4 files changed

+128
-1
lines changed

.github/workflows/compile-examples.yml

+9
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,15 @@ jobs:
4949
sketch-paths: |
5050
- examples/OTA_Qspi_Flash
5151
- examples/OTA_Usage_Portenta
52+
- fqbn: arduino:mbed_opta:opta
53+
platforms: |
54+
- name: arduino:mbed_opta
55+
libraries: |
56+
- name: Arduino_DebugUtils
57+
sketch-paths: |
58+
- examples/OTA_Qspi_Flash
59+
- examples/OTA_Qspi_Flash_Ethernet
60+
- examples/OTA_Usage_Portenta
5261
5362
steps:
5463
- name: Checkout
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+
}

library.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ sentence=Firmware update for the Portenta H7.
66
paragraph=This library allows performing a firmware update on the Arduino Portenta H7. The firmware can be stored in various different locations such as within the microcontroller's flash, on an external SD card or on the QSPI flash chip.
77
category=Communication
88
url=https://github.com/arduino-libraries/Arduino_Portenta_OTA
9-
architectures=mbed,mbed_portenta,mbed_nicla
9+
architectures=mbed,mbed_portenta,mbed_nicla,mbed_opta
1010
includes=Arduino_Portenta_OTA.h

src/Arduino_Portenta_OTA_Config.h

+5
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,9 @@
3535
#define ARDUINO_PORTENTA_OTA_QSPI_SUPPORT
3636
#endif
3737

38+
#if defined(ARDUINO_OPTA)
39+
#define ARDUINO_PORTENTA_OTA_MAGIC 0x23410064
40+
#define ARDUINO_PORTENTA_OTA_QSPI_SUPPORT
41+
#endif
42+
3843
#endif /* ARDUINO_PORTENTA_OTA_CONFIG_H_ */

0 commit comments

Comments
 (0)