Skip to content

Portenta C33 SFU #116

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/compile-examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ jobs:
- libraries/Arduino_CAN/examples/CAN1Write
- libraries/RTC/examples/RTC_NTPSync
- libraries/RTC/examples/RTC_Alarm
- libraries/SFU
- board:
fqbn: "arduino-git:renesas:portenta_c33"
additional-sketch-paths: |
Expand All @@ -82,6 +83,7 @@ jobs:
- libraries/Arduino_CAN/examples/CAN1Write
- libraries/RTC/examples/RTC_NTPSync
- libraries/RTC/examples/RTC_Alarm
- libraries/SFU
- board:
fqbn: "arduino:renesas_uno:unor4wifi"
additional-sketch-paths: |
Expand Down
Empty file added libraries/SFU/.portenta_only
Empty file.
55 changes: 55 additions & 0 deletions libraries/SFU/examples/OTAUsage/OTAUsage.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
This sketch can be used to generate an example binary that can be uploaded to Portenta C33 via OTA.
It needs to be used together with UpdateFromFile.ino

Steps to test OTA on Portenta C33:
1) Upload this sketch or any other sketch (this one lights up the RGB LED with different colours).
2) In the IDE select: Sketch -> Export compiled Binary
3) Upload the exported binary to a server
4) Open the related OTA_*_Portenta.ino sketch, eventually update the OTA_FILE_LOCATION
5) Upload the sketch UpdateFromFile.ino to perform OTA
*/
#include "SFU.h"

void setLed(int blue, int gree, int red) {
if (blue == 1) {
digitalWrite(LEDB, LOW);
}
else {
digitalWrite(LEDB, HIGH);
}

if (gree == 1) {
digitalWrite(LEDG, LOW);
}
else {
digitalWrite(LEDG, HIGH);
}

if (red == 1) {
digitalWrite(LEDR, LOW);
}
else {
digitalWrite(LEDR, HIGH);
}
}


void setup()
{
pinMode(LEDB, OUTPUT);
pinMode(LEDG, OUTPUT);
pinMode(LEDR, OUTPUT);
}

void loop()
{ // Blue LED on
setLed(1, 0, 0);
delay(1000);
// Green LED on
setLed(0, 1, 0);
delay(1000);
// Red LED on
setLed(0, 0, 1);
delay(1000);
}
95 changes: 95 additions & 0 deletions libraries/SFU/examples/UpdateFromFile/UpdateFromFile.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
* This example demonstrates how to use the SFU to update the firmware of the
* Arduino Portenta C33 using a compressed firmware image stored in the QSPI flash.
* In real applications, you will get the file from the internet and not include it
* in a header file like we do here for simplicity.
*
* Steps:
* 1) Create a sketch for the Portenta C33 and verify
* that it both compiles and works on a board.
* 2) In the IDE select: Sketch -> Export compiled Binary.
* 3) Create an OTA update file utilising the tools 'lzss.py' and 'bin2ota.py' stored in
* https://github.com/arduino-libraries/ArduinoIoTCloud/tree/master/extras/tools .
* A) ./lzss.py --encode SKETCH.bin SKETCH.lzss
* B) ./bin2ota.py PORTENTA_C33 SKETCH.lzss SKETCH.ota
* 4) Create the header file to be included in this Sketch
* xxd -i SKETCH.ota > update.h
* 5) Upload this Sketch to perform the update
*/

/******************************************************************************
* INCLUDE
******************************************************************************/

#include <SFU.h>
#include <BlockDevice.h>
#include <MBRBlockDevice.h>
#include <FATFileSystem.h>
#include <Arduino_DebugUtils.h>
#include "update.h"

BlockDevice* block_device = BlockDevice::get_default_instance();
MBRBlockDevice mbr(block_device, 1);
FATFileSystem fs("ota");


/******************************************************************************
* SETUP/LOOP
******************************************************************************/

void setup()
{
Serial.begin(115200);
while (!Serial) {}

Debug.setDebugLevel(DBG_VERBOSE);

int err = -1;
if ((err = fs.reformat(&mbr)) != 0)
{
DEBUG_ERROR("%s: fs.reformat() failed with %d", __FUNCTION__, err);
return;
}

FILE * file = fopen("/ota/UPDATE.BIN.OTA", "wb");
if (!file)
{
DEBUG_ERROR("%s: fopen() failed", __FUNCTION__);
fclose(file);
return;
}

DEBUG_INFO("Start copy update file on QSPI flash.");
for(int i = 0; i < OTAUsage_ino_PORTENTA_C33_ota_len; i++)
{
char const c = OTAUsage_ino_PORTENTA_C33_ota[i];

if (fwrite(&c, 1, sizeof(c), file) != sizeof(c))
{
DEBUG_ERROR("%s: Writing of firmware image to flash failed", __FUNCTION__);
fclose(file);
return;
}
}

fclose(file);

/* Unmount the filesystem. */
if ((err = fs.unmount()) != 0)
{
DEBUG_ERROR("%s: fs.unmount() failed with %d", __FUNCTION__, err);
return;
}

delay(1000);

DEBUG_INFO("Board reset to trigger the update.");
DEBUG_INFO("Do not reset or disconnect the board.");
DEBUG_INFO("Wait until the RGB LED lights up with different colours.");
NVIC_SystemReset();
}

void loop()
{

}
Loading