Skip to content

Commit 65f003a

Browse files
authored
Merge pull request #116 from pennam/sfu-file
Portenta C33 SFU
2 parents 80c9238 + 59d3697 commit 65f003a

File tree

15 files changed

+34186
-0
lines changed

15 files changed

+34186
-0
lines changed

.github/workflows/compile-examples.yml

+2
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ jobs:
6868
- libraries/Arduino_CAN/examples/CAN1Write
6969
- libraries/RTC/examples/RTC_NTPSync
7070
- libraries/RTC/examples/RTC_Alarm
71+
- libraries/SFU
7172
- board:
7273
fqbn: "arduino-git:renesas:portenta_c33"
7374
additional-sketch-paths: |
@@ -82,6 +83,7 @@ jobs:
8283
- libraries/Arduino_CAN/examples/CAN1Write
8384
- libraries/RTC/examples/RTC_NTPSync
8485
- libraries/RTC/examples/RTC_Alarm
86+
- libraries/SFU
8587
- board:
8688
fqbn: "arduino:renesas_uno:unor4wifi"
8789
additional-sketch-paths: |

libraries/SFU/.portenta_only

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
This sketch can be used to generate an example binary that can be uploaded to Portenta C33 via OTA.
3+
It needs to be used together with UpdateFromFile.ino
4+
5+
Steps to test OTA on Portenta C33:
6+
1) Upload this sketch or any other sketch (this one lights up the RGB LED with different colours).
7+
2) In the IDE select: Sketch -> Export compiled Binary
8+
3) Upload the exported binary to a server
9+
4) Open the related OTA_*_Portenta.ino sketch, eventually update the OTA_FILE_LOCATION
10+
5) Upload the sketch UpdateFromFile.ino to perform OTA
11+
*/
12+
#include "SFU.h"
13+
14+
void setLed(int blue, int gree, int red) {
15+
if (blue == 1) {
16+
digitalWrite(LEDB, LOW);
17+
}
18+
else {
19+
digitalWrite(LEDB, HIGH);
20+
}
21+
22+
if (gree == 1) {
23+
digitalWrite(LEDG, LOW);
24+
}
25+
else {
26+
digitalWrite(LEDG, HIGH);
27+
}
28+
29+
if (red == 1) {
30+
digitalWrite(LEDR, LOW);
31+
}
32+
else {
33+
digitalWrite(LEDR, HIGH);
34+
}
35+
}
36+
37+
38+
void setup()
39+
{
40+
pinMode(LEDB, OUTPUT);
41+
pinMode(LEDG, OUTPUT);
42+
pinMode(LEDR, OUTPUT);
43+
}
44+
45+
void loop()
46+
{ // Blue LED on
47+
setLed(1, 0, 0);
48+
delay(1000);
49+
// Green LED on
50+
setLed(0, 1, 0);
51+
delay(1000);
52+
// Red LED on
53+
setLed(0, 0, 1);
54+
delay(1000);
55+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*
2+
* This example demonstrates how to use the SFU to update the firmware of the
3+
* Arduino Portenta C33 using a compressed firmware image stored in the QSPI flash.
4+
* In real applications, you will get the file from the internet and not include it
5+
* in a header file like we do here for simplicity.
6+
*
7+
* Steps:
8+
* 1) Create a sketch for the Portenta C33 and verify
9+
* that it both compiles and works on a board.
10+
* 2) In the IDE select: Sketch -> Export compiled Binary.
11+
* 3) Create an OTA update file utilising the tools 'lzss.py' and 'bin2ota.py' stored in
12+
* https://github.com/arduino-libraries/ArduinoIoTCloud/tree/master/extras/tools .
13+
* A) ./lzss.py --encode SKETCH.bin SKETCH.lzss
14+
* B) ./bin2ota.py PORTENTA_C33 SKETCH.lzss SKETCH.ota
15+
* 4) Create the header file to be included in this Sketch
16+
* xxd -i SKETCH.ota > update.h
17+
* 5) Upload this Sketch to perform the update
18+
*/
19+
20+
/******************************************************************************
21+
* INCLUDE
22+
******************************************************************************/
23+
24+
#include <SFU.h>
25+
#include <BlockDevice.h>
26+
#include <MBRBlockDevice.h>
27+
#include <FATFileSystem.h>
28+
#include <Arduino_DebugUtils.h>
29+
#include "update.h"
30+
31+
BlockDevice* block_device = BlockDevice::get_default_instance();
32+
MBRBlockDevice mbr(block_device, 1);
33+
FATFileSystem fs("ota");
34+
35+
36+
/******************************************************************************
37+
* SETUP/LOOP
38+
******************************************************************************/
39+
40+
void setup()
41+
{
42+
Serial.begin(115200);
43+
while (!Serial) {}
44+
45+
Debug.setDebugLevel(DBG_VERBOSE);
46+
47+
int err = -1;
48+
if ((err = fs.reformat(&mbr)) != 0)
49+
{
50+
DEBUG_ERROR("%s: fs.reformat() failed with %d", __FUNCTION__, err);
51+
return;
52+
}
53+
54+
FILE * file = fopen("/ota/UPDATE.BIN.OTA", "wb");
55+
if (!file)
56+
{
57+
DEBUG_ERROR("%s: fopen() failed", __FUNCTION__);
58+
fclose(file);
59+
return;
60+
}
61+
62+
DEBUG_INFO("Start copy update file on QSPI flash.");
63+
for(int i = 0; i < OTAUsage_ino_PORTENTA_C33_ota_len; i++)
64+
{
65+
char const c = OTAUsage_ino_PORTENTA_C33_ota[i];
66+
67+
if (fwrite(&c, 1, sizeof(c), file) != sizeof(c))
68+
{
69+
DEBUG_ERROR("%s: Writing of firmware image to flash failed", __FUNCTION__);
70+
fclose(file);
71+
return;
72+
}
73+
}
74+
75+
fclose(file);
76+
77+
/* Unmount the filesystem. */
78+
if ((err = fs.unmount()) != 0)
79+
{
80+
DEBUG_ERROR("%s: fs.unmount() failed with %d", __FUNCTION__, err);
81+
return;
82+
}
83+
84+
delay(1000);
85+
86+
DEBUG_INFO("Board reset to trigger the update.");
87+
DEBUG_INFO("Do not reset or disconnect the board.");
88+
DEBUG_INFO("Wait until the RGB LED lights up with different colours.");
89+
NVIC_SystemReset();
90+
}
91+
92+
void loop()
93+
{
94+
95+
}

0 commit comments

Comments
 (0)