From befe93187098ec4969063e67b9aed2ce0a1355f9 Mon Sep 17 00:00:00 2001 From: Sebastian Romero Date: Mon, 4 Sep 2023 15:17:11 +0200 Subject: [PATCH 1/2] Use unsigned types for comparison --- examples/PortentaH7Logger/PortentaH7Logger.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/PortentaH7Logger/PortentaH7Logger.ino b/examples/PortentaH7Logger/PortentaH7Logger.ino index a7241bd..fd0976b 100644 --- a/examples/PortentaH7Logger/PortentaH7Logger.ino +++ b/examples/PortentaH7Logger/PortentaH7Logger.ino @@ -81,7 +81,7 @@ void performUpdate() { UFile lastUpdateFile = usbRoot.createFile("diff.txt", FileMode::READ); // Create or open the last update file backingUP = true; - int lastUpdateBytes = lastUpdateFile.readAsString().toInt(); // Read the last update size from the file + unsigned lastUpdateBytes = lastUpdateFile.readAsString().toInt(); // Read the last update size from the file Serial.print("Last update bytes: "); Serial.println(lastUpdateBytes); From ccaa7b8ca56ed6c5ef2afe053db781c6b8556a54 Mon Sep 17 00:00:00 2001 From: Sebastian Romero Date: Mon, 4 Sep 2023 16:13:04 +0200 Subject: [PATCH 2/2] Allocate buffer on heap --- examples/PortentaH7Logger/PortentaH7Logger.ino | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/PortentaH7Logger/PortentaH7Logger.ino b/examples/PortentaH7Logger/PortentaH7Logger.ino index fd0976b..06c63ba 100644 --- a/examples/PortentaH7Logger/PortentaH7Logger.ino +++ b/examples/PortentaH7Logger/PortentaH7Logger.ino @@ -97,7 +97,8 @@ void performUpdate() { unsigned long totalBytesToMove = bytesWritten - lastUpdateBytes; Serial.print("New update bytes: "); Serial.println(totalBytesToMove); - uint8_t buffer[totalBytesToMove]; + uint8_t* buffer = new uint8_t[totalBytesToMove]; + size_t bytesRead = logFile.read(buffer, totalBytesToMove); size_t bytesMoved = backupFile.write(buffer, bytesRead); // Only write the bytes that haven't been backed up yet @@ -115,6 +116,7 @@ void performUpdate() { digitalWrite(USB_MOUNTED_LED, HIGH); backingUP = false; + delete[] buffer; }