Skip to content

Commit f8717bc

Browse files
all examples compile, update for logger on opta and c33
1 parent 772fa4d commit f8717bc

File tree

11 files changed

+71
-93
lines changed

11 files changed

+71
-93
lines changed

examples/logger/logger.ino

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,9 @@ void setup() {
173173
}
174174

175175
void loop() {
176-
usbStorage.checkConnection();
176+
#if defined(ARDUINO_PORTENTA_H7_M7)
177+
usbStorage.checkConnection();
178+
#endif
177179
runPeriodically(logDataToRAM, 100, &lastLog);
178180
runPeriodically(moveDataToQSPI, 1000, &lastMove);
179181
runPeriodically(backupToUSB, 10000, &lastBackup);

examples/opta_logger/opta_logger.ino

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ The "performUpdate" function performs the update process by:
1212
INSTRUCTIONS
1313
* Make sure the QSPI storage of your board is properly partitioned.
1414
* You can do that by flashing the QSPIFormat example that can be found in the STM32H747_System folder
15-
* Open the serial monitor and select answer with "Y" when this appears "Do you want to use partition scheme 1? Y/[n]"
15+
* Open the //Serial monitor and select answer with "Y" when this appears "Do you want to use partition scheme 1? Y/[n]"
1616
* Reboot the board
1717
* Connect a RS485-enabled device to see the debugging output.
1818
* This sketch will log data, and check if there is any USB MSD Device connected to the USB Port of the Opta.
@@ -24,14 +24,8 @@ INSTRUCTIONS
2424
#include "Arduino_UnifiedStorage.h"
2525
#include <vector>
2626

27-
#if defined(ARDUINO_PORTENTA_H7_M7)
28-
#define USB_MOUNTED_LED LED_BLUE
29-
#elif defined(ARDUINO_PORTENTA_C33)
30-
#define USB_MOUNTED LED LEDB
31-
#endif
32-
constexpr auto baudrate { 115200 };
33-
3427

28+
constexpr auto baudrate { 115200 };
3529

3630

3731
InternalStorage internalStorage = InternalStorage();
@@ -86,10 +80,10 @@ void performUpdate() {
8680
backingUP = true;
8781
int lastUpdateBytes = lastUpdateFile.readAsString().toInt(); // Read the last update size from the file
8882

89-
Serial.print("Last update bytes: "); Serial.println(lastUpdateBytes);
83+
//Serial.print("Last update bytes: "); //Serial.println(lastUpdateBytes);
9084

9185
if (lastUpdateBytes >= bytesWritten) {
92-
Serial.println("No new data to copy.");
86+
//Serial.println("No new data to copy.");
9387
backupFile.close();
9488
lastUpdateFile.close();
9589
backingUP = false;
@@ -98,13 +92,13 @@ void performUpdate() {
9892

9993
logFile.seek(lastUpdateBytes); // Move the file pointer to the last update position
10094
unsigned long totalBytesToMove = bytesWritten - lastUpdateBytes;
101-
Serial.print("New update bytes: "); Serial.println(totalBytesToMove);
95+
//Serial.print("New update bytes: "); //Serial.println(totalBytesToMove);
10296

10397
uint8_t buffer[totalBytesToMove];
10498
size_t bytesRead = logFile.read(buffer, totalBytesToMove);
10599
size_t bytesMoved = backupFile.write(buffer, bytesRead); // Only write the bytes that haven't been backed up yet
106100

107-
Serial.println("Successfully copied " + String(bytesMoved) + " new bytes.");
101+
//Serial.println("Successfully copied " + String(bytesMoved) + " new bytes.");
108102

109103
lastUpdateFile.changeMode(FileMode::WRITE); // Open the last update file in write mode
110104
lastUpdateFile.write(String(lastUpdateBytes + bytesMoved)); // Update the last update size
@@ -113,10 +107,10 @@ void performUpdate() {
113107
logFile.close();
114108
lastUpdateFile.close();
115109

116-
Serial.println();
110+
//Serial.println();
117111
usbStorage.unmount(); // Unmount the USB storage
118112

119-
digitalWrite(USB_MOUNTED_LED, HIGH);
113+
digitalWrite(LED_D0, HIGH);
120114
backingUP = false;
121115
}
122116

@@ -127,47 +121,46 @@ void disconnect(){
127121
// Function to backup data to USB storage
128122
void backupToUSB() {
129123
if (usbStorage.isAvailable()) {
130-
Serial.println("USB Mass storage is available");
124+
//Serial.println("USB Mass storage is available");
131125
delay(100);
132126
if (!usbStorage.isConnected()) {
133127

134-
Serial.println("Mounting USB Mass Storage");
135-
digitalWrite(USB_MOUNTED_LED, LOW);
128+
//Serial.println("Mounting USB Mass Storage");
129+
digitalWrite(LED_D0, LOW);
136130
if(usbStorage.begin()){
137131
performUpdate();
138132
}
139133

140134

141135

142136
} else if (usbStorage.isConnected()) {
143-
Serial.println("USB Mass storage is connected, performing update");
137+
//Serial.println("USB Mass storage is connected, performing update");
144138
performUpdate();
145139

146140
}
147141
} else {
148-
Serial.println("USB Mass storage is not available");
142+
//Serial.println("USB Mass storage is not available");
149143
}
150144

151145

152146
}
153147

154148

155149
void setup() {
156-
Serial.begin(115200);
157-
while (!Serial);
158-
pinMode(USB_MOUNTED_LED, OUTPUT);
159-
Serial.println("Formatting internal storage...");
150+
//Serial.begin(115200);
151+
pinMode(LED_D0, OUTPUT);
152+
//Serial.println("Formatting internal storage...");
160153
int formatted = internalStorage.format();
161-
Serial.print("QSPI Format status: "); Serial.println(formatted);
154+
//Serial.print("QSPI Format status: "); //Serial.println(formatted);
162155

163156
//configureRS485(baudrate);
164-
//Serial.println("RS485 goes brrr...");
157+
////Serial.println("RS485 goes brrr...");
165158

166159
if (!internalStorage.begin() == 0) {
167-
Serial.println("Failed to initialize internal storage");
160+
//Serial.println("Failed to initialize internal storage");
168161
return;
169162
} else {
170-
Serial.println("Initialized storage");
163+
//Serial.println("Initialized storage");
171164
}
172165

173166
}

src/Arduino_UnifiedStorage.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717

1818

19-
2019
#if defined(ARDUINO_PORTENTA_C33)
2120
#include "QSPIFlashBlockDevice.h"
2221
#include <BlockDevice.h>

src/InternalStorage.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
InternalStorage::InternalStorage(){
44
#if defined(ARDUINO_PORTENTA_C33)
55
this -> blockDevice = BlockDevice::get_default_instance();
6-
this -> userData = new MBRBlockDevice(this->blockDevice, 2);
6+
this -> userData = new MBRBlockDevice(this->blockDevice, this->partitionNumber);
77
this -> userDataFileSystem = new FATFileSystem(this->partitionName);
88
#elif defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_OPTA)
99
this -> blockDevice = QSPIFBlockDevice::get_default_instance();

src/Types.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ static bool copyFolder(const char* source, const char* destination) {
7575
closedir(dir);
7676
return true;
7777
}
78+
7879
static std::string replaceLastPathComponent(const std::string& path, const std::string& newComponent) {
7980
size_t lastSlashIndex = path.find_last_of('/');
8081
if (lastSlashIndex != std::string::npos) {

src/UFile.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ bool UFile::open(String filename, FileMode mode) {
5454
void UFile::close() {
5555
// Close the file
5656
if (fp != nullptr) {
57-
fflush(fp);
57+
fflush(fp); // ?!?
5858
fclose(fp);
5959
fp = nullptr;
6060
}
@@ -162,17 +162,17 @@ size_t UFile::write(const uint8_t* buffer, size_t size) {
162162

163163
bool UFile::remove() {
164164
// Remove the file;
165-
if (!path.empty()) {
166-
int result = ::remove(path.c_str());
167-
if (result == 0) {
168-
return true;
165+
if(this->exists() && !path.empty()){
166+
int result = ::remove(path.c_str());
167+
if (result == 0) {
168+
return true;
169+
} else {
170+
// Error occurred while removing the file
171+
return false;
172+
}
169173
} else {
170-
// Error occurred while removing the file
171-
return false;
174+
return false; // Handle the case when the path is not valid
172175
}
173-
} else {
174-
return false; // Handle the case when the path is not valid
175-
}
176176
}
177177

178178
bool UFile::rename(const char* newFilename) {

src/USBStorage.cpp

Lines changed: 10 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,18 @@
77
#define MAX_TRIES 10
88

99
USBStorage::USBStorage(){
10+
#if defined(ARDUINO_PORTENTA_C33)
11+
register_hotplug_callback(DEV_USB, [](){
12+
Serial.println("caalllback");
13+
available = !available;
1014

11-
}
12-
13-
void USBStorage::usbCallback(){
14-
/*
15-
if(this-> available){
16-
this -> available = false;
17-
} else {
18-
this -> available = true;
19-
}
20-
*/
15+
});
16+
#endif
2117
}
2218

2319
int USBStorage::begin(){
2420

25-
#if defined(ARDUINO_PORTENTA_C33)
26-
register_hotplug_callback(DEV_USB, this->usbCallback);
27-
#endif
21+
2822

2923
int attempts = 0;
3024
int err = mount(DEV_USB, FS_FAT, MNT_DEFAULT);
@@ -64,22 +58,13 @@ Folder USBStorage::getRootFolder(){
6458

6559

6660
bool USBStorage::isAvailable(){
67-
return this -> available;
61+
return available;
6862
}
6963

7064
bool USBStorage::isConnected(){
7165
return this -> connected;
7266
}
7367

74-
void USBStorage::disconnect(){
75-
76-
77-
USBHost * host;
78-
USBDeviceConnected * dev;
79-
host = USBHost::getHostInst();
80-
host -> getDevice(0) -> disconnect();
81-
82-
}
8368

8469
/*
8570
@@ -119,20 +104,12 @@ void USBStorage::checkConnection(){
119104

120105

121106
if ((dev = host->getDevice(0)) != NULL) {
122-
this->available = true;
107+
available = true;
123108

124109
uint8_t ceva = dev->getNbIntf();
125-
/*
126-
127-
Serial.println(dev->getName(ceva));
128-
Serial.println(dev->getVid());
129-
Serial.println(dev->getPid());
130-
Serial.println(dev->getClass());
131-
Serial.println(dev->getSubClass());
132-
*/
133110
found = true;
134111
} else {
135-
this->available = false;
112+
available = false;
136113
}
137114
}
138115

src/USBStorage.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
#ifndef USBStorage_H
44
#define USBStorage_H
55

6+
static bool available = false;
7+
8+
9+
static bool available = false;
10+
11+
612
class USBStorage : public Arduino_UnifiedStorage {
713
public:
814
USBStorage();
@@ -21,15 +27,12 @@ class USBStorage : public Arduino_UnifiedStorage {
2127

2228
void checkConnection();
2329

24-
void disconnect();
2530

2631

2732
private:
28-
void usbCallback();
33+
2934
bool connected = false;
30-
bool available = false;
31-
bool hasChanged = false;
32-
bool isIdentical = false;
35+
3336
unsigned long previousMillis;
3437
int interval = 500;
3538
};

tests/test_qspi_usb_sd/test_c33

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
#!/bin/bash
2+
<<<<<<< Updated upstream
23
arduino-cli compile -b arduino:renesas_portenta:portenta_c33 --library "../../Arduino_POSIXStorage" --library "/home/c.dragomir/ArduinoWorkspace/Arduino_UnifiedStorage"
4+
=======
5+
arduino-cli compile -b arduino:renesas_portenta:portenta_c33 --library "/home/c.dragomir/ArduinoWorkspace/Repos/POSIXStorage" --library "/home/c.dragomir/ArduinoWorkspace/Repos/Arduino_UnifiedStorage"
6+
>>>>>>> Stashed changes
37
arduino-cli upload -b arduino:renesas_portenta:portenta_c33

tests/test_qspi_usb_sd/test_h7

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
#!/bin/bash
2+
<<<<<<< Updated upstream
23
arduino-cli compile -b arduino:mbed_portenta:envie_m7 --library "../../Arduino_POSIXStorage" --library "/home/c.dragomir/ArduinoWorkspace/Arduino_UnifiedStorage"
3-
arduino-cli upload -b arduino:mbed_portenta:envie_m7
4+
arduino-cli upload -b arduino:mbed_portenta:envie_m7
5+
=======
6+
arduino-cli compile -b arduino:mbed_portenta:envie_m7 --library "../../../POSIXStorage" --library "../../../Arduino_UnifiedStorage"
7+
8+
>>>>>>> Stashed changes

tests/test_qspi_usb_sd/test_qspi_usb_sd.ino

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ void runRepeatedMountTest(UnifiedStorage * storage, String storageType, int n =
138138
Serial.println("Unmounting drive");
139139
Serial.println(umountResult);
140140
Serial.println(getErrno());
141+
} else {
142+
Serial.println("Succesfully unmounted");
141143
}
142144
}
143145
}
@@ -151,23 +153,15 @@ void setup() {
151153
runRepeatedMountTest(&sd, "SD");
152154
runRepeatedMountTest(&internal, "QSPI");
153155

154-
155-
156-
#ifdef HAS_QSPI
156+
runTests(&usb, "USB Storage");
157157
runTests(&internal, "Internal Storage (QSPI)");
158-
#endif
159-
160-
#ifdef HAS_SD
161158
runTests(&sd, "SD Storage");
162-
#endif
163159

164-
#ifdef HAS_USB
165-
runTests(&usb, "USB Storage");
166-
#endif
167160

168161

169-
bool thing = interStorageTests(&sd, &internal, "SD", "Internal"); // Test copying/moving from SD to Internal Storage
170-
Serial.println(thing);
162+
163+
interStorageTests(&sd, &internal, "SD", "Internal"); // Test copying/moving from SD to Internal Storage
164+
delay(1000);
171165

172166
interStorageTests(&usb, &sd, "USB", "SD"); // Test copying/moving from USB to SD
173167
delay(1000);
@@ -201,7 +195,7 @@ void runTests(UnifiedStorage * storage, String storageType) {
201195
if (storage->begin()) {
202196

203197
Folder root = storage->getRootFolder();
204-
clearData(root);
198+
205199
Serial.println("=== Testing " + storageType + " ===");
206200

207201
Serial.println("========= UFile Tests =========");
@@ -231,7 +225,7 @@ void runTests(UnifiedStorage * storage, String storageType) {
231225
Serial.println("========= FS Contents after Folder Tests =========");
232226
printFolderContents(root);
233227
Serial.println("=============================\n");
234-
// storage->unmount();
228+
storage->unmount();
235229

236230
} else {
237231
Serial.println(storageType + " not initialized!");

0 commit comments

Comments
 (0)