|
| 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 | + delay(10000); |
| 51 | + } |
| 52 | + Serial.println("Connected"); |
| 53 | + |
| 54 | + Arduino_Portenta_OTA_QSPI ota(QSPI_FLASH_FATFS_MBR, 2); |
| 55 | + Arduino_Portenta_OTA::Error ota_err = Arduino_Portenta_OTA::Error::None; |
| 56 | + |
| 57 | + if (!ota.isOtaCapable()) |
| 58 | + { |
| 59 | + Serial.println("Higher version bootloader required to perform OTA."); |
| 60 | + Serial.println("Please update the bootloader."); |
| 61 | + Serial.println("File -> Examples -> STM32H747_System -> STM32H747_manageBootloader"); |
| 62 | + return; |
| 63 | + } |
| 64 | + |
| 65 | + Serial.println("Initializing OTA storage"); |
| 66 | + if ((ota_err = ota.begin()) != Arduino_Portenta_OTA::Error::None) |
| 67 | + { |
| 68 | + Serial.print ("Arduino_Portenta_OTA::begin() failed with error code "); |
| 69 | + Serial.println((int)ota_err); |
| 70 | + return; |
| 71 | + } |
| 72 | + |
| 73 | + Serial.println("Starting download to QSPI ..."); |
| 74 | + int const ota_download = ota.download(OTA_FILE_LOCATION, false /* is_https */); |
| 75 | + if (ota_download <= 0) |
| 76 | + { |
| 77 | + Serial.print ("Arduino_Portenta_OTA_QSPI::download failed with error code "); |
| 78 | + Serial.println(ota_download); |
| 79 | + return; |
| 80 | + } |
| 81 | + Serial.print (ota_download); |
| 82 | + Serial.println(" bytes stored."); |
| 83 | + |
| 84 | + |
| 85 | + Serial.println("Decompressing LZSS compressed file ..."); |
| 86 | + int const ota_decompress = ota.decompress(); |
| 87 | + if (ota_decompress < 0) |
| 88 | + { |
| 89 | + Serial.print("Arduino_Portenta_OTA_QSPI::decompress() failed with error code"); |
| 90 | + Serial.println(ota_decompress); |
| 91 | + return; |
| 92 | + } |
| 93 | + Serial.print(ota_decompress); |
| 94 | + Serial.println(" bytes decompressed."); |
| 95 | + |
| 96 | + |
| 97 | + Serial.println("Storing parameters for firmware update in bootloader accessible non-volatile memory ..."); |
| 98 | + if ((ota_err = ota.update()) != Arduino_Portenta_OTA::Error::None) |
| 99 | + { |
| 100 | + Serial.print ("ota.update() failed with error code "); |
| 101 | + Serial.println((int)ota_err); |
| 102 | + return; |
| 103 | + } |
| 104 | + |
| 105 | + Serial.println("Performing a reset after which the bootloader will update the firmware."); |
| 106 | + Serial.println("Hint: Board LED will blink Red-Blue-Green."); |
| 107 | + delay(1000); /* Make sure the serial message gets out before the reset. */ |
| 108 | + ota.reset(); |
| 109 | +} |
| 110 | + |
| 111 | +void loop() |
| 112 | +{ |
| 113 | + |
| 114 | +} |
0 commit comments