Skip to content

Commit aa6f2a1

Browse files
tests and sketches should run on H7 and C33
1 parent 9ce07c6 commit aa6f2a1

File tree

7 files changed

+159
-83
lines changed

7 files changed

+159
-83
lines changed

examples/AdvancedUSBInternalOperations/AdvancedUSBInternalOperations.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
// Two instances are made for the USB and internal storage respectively
2929
USBStorage usbStorage = USBStorage();
30-
InternalStorage internalStorage = InternalStorage();
30+
InternalStorage internalStorage = InternalStorage(2, "user");
3131

3232
// Helper function to prints the contents of a folder, including subdirectories (marked as "[D]") and files (marked as "[F]").
3333
void printFolderContents(Folder dir, int indentation = 0) {

examples/logger/logger.ino renamed to examples/PoftentaH7Logger/PortentaH7Logger.ino

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,11 @@ void setup() {
157157
while (!Serial);
158158
pinMode(USB_MOUNTED_LED, OUTPUT);
159159
Serial.println("Formatting internal storage...");
160+
internalStorage.begin();
161+
internalStorage.unmount();
160162
int formatted = internalStorage.format();
163+
internalStorage.begin();
164+
161165
Serial.print("QSPI Format status: "); Serial.println(formatted);
162166

163167
//configureRS485(baudrate);
@@ -173,9 +177,9 @@ void setup() {
173177
}
174178

175179
void loop() {
176-
#if defined(ARDUINO_PORTENTA_H7_M7)
177-
usbStorage.checkConnection();
178-
#endif
180+
181+
usbStorage.checkConnection();
182+
179183
runPeriodically(logDataToRAM, 100, &lastLog);
180184
runPeriodically(moveDataToQSPI, 1000, &lastMove);
181185
runPeriodically(backupToUSB, 10000, &lastBackup);

examples/SimpleStorageWriteRead/SimpleStorageWriteRead.ino

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,46 @@
2323

2424
#include "Arduino_UnifiedStorage.h"
2525

26+
void printFolderContents(Folder dir, int indentation = 0) {
27+
std::vector<Folder> directories = dir.getFolders();
28+
std::vector<UFile> files = dir.getFiles();
29+
30+
// Print directories
31+
for (Folder subdir : directories) {
32+
for (int i = 0; i < indentation; i++) {
33+
Serial.print(" ");
34+
}
35+
Serial.print("[D] ");
36+
Serial.println(subdir.getPath());
37+
printFolderContents(subdir, indentation + 1);
38+
}
39+
40+
// Print files
41+
for (UFile file : files) {
42+
for (int i = 0; i < indentation; i++) {
43+
Serial.print(" ");
44+
}
45+
Serial.print("[F] ");
46+
Serial.println(file.getPath());
47+
}
48+
}
49+
50+
2651
// Uncomment one of the three lines below to select between SD card, USB or internal storage
2752
//SDStorage unifiedStorage = SDStorage(); // Create an instance for interacting with SD card storage
2853
//USBStorage unifiedStorage = USBStorage() // Create an instance for interacting with USB storage
29-
InternalStorage unifiedStorage = InternalStorage(); // Create an instance for interacting with internal Flash storage (default)
54+
InternalStorage internalStorage = InternalStorage(2, "user"); // Create an instance for interacting with internal Flash storage (default)
3055

3156
void setup() {
3257
Serial.begin(115200);
3358
while (!Serial);
3459

35-
if(!unifiedStorage.begin()==0){
60+
if(!internalStorage.begin()){
3661
Serial.println("Error mounting storage device.");
3762
}
3863

3964
// Create a root directory in storage device
40-
Folder root = unifiedStorage.getRootFolder();
65+
Folder root = internalStorage.getRootFolder();
4166

4267
// Create subdirectories inside the root directory
4368
Folder subdir1 = root.createSubfolder("subdir1");
@@ -65,8 +90,9 @@ void setup() {
6590

6691
// Read data from file1
6792
file1.seek(0); // Move the file pointer to the beginning
93+
Serial.println(file1.available());
6894
while (file1.available()) {
69-
char data = file1.read();
95+
char data = file1.read();
7096
Serial.write(data);
7197
}
7298
Serial.println();
@@ -75,17 +101,19 @@ void setup() {
75101
file2.seek(0); // Move the file pointer to the beginning
76102
while (file2.available()) {
77103
char data = file2.read();
78-
Serial.write(data);
104+
Serial.print(data);
79105
}
80106
Serial.println();
81107

82108
// Read data from file3
83109
file3.seek(0); // Move the file pointer to the beginning
84110
while (file3.available()) {
85111
char data = file3.read();
86-
Serial.write(data);
112+
Serial.print(data);
87113
}
88114
Serial.println();
115+
116+
printFolderContents(internalStorage.getRootFolder());
89117
}
90118

91119
void loop() {

src/Folder.cpp

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,16 +105,29 @@ String Folder::getPathString() {
105105
}
106106

107107
Folder Folder::createSubfolder(const char* subfolderName) {
108-
// Construct the full path of the subfolder
108+
bool alreadyExists = false;
109109
std::string subfolderPath = this->path + "/" + subfolderName;
110110

111-
// Create the subfolder
111+
for(Folder d: this->getFolders()){
112+
if(d.getPath() == subfolderPath){
113+
alreadyExists = true;
114+
115+
}
116+
}
117+
118+
// Construct the full path of the subfolder
119+
120+
if (!alreadyExists){
112121
int result = mkdir(subfolderPath.c_str(), 0777);
113-
if (result == 0) {
114-
return Folder(subfolderPath.c_str());
122+
if (result == 0) {
123+
return Folder(subfolderPath.c_str());
124+
} else {
125+
return Folder();
126+
}
115127
} else {
116-
return Folder(); // Return an empty directory object on failure
128+
return Folder(subfolderPath.c_str());
117129
}
130+
118131
}
119132

120133
Folder Folder::createSubfolder(String subfolderName) {

src/USBStorage.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
USBStorage::USBStorage(){
1010
#if defined(ARDUINO_PORTENTA_C33)
1111
register_hotplug_callback(DEV_USB, [](){
12-
available = !available;
12+
usb_available = !usb_available;
1313

1414
});
1515
#endif
@@ -57,7 +57,7 @@ Folder USBStorage::getRootFolder(){
5757

5858

5959
bool USBStorage::isAvailable(){
60-
return available;
60+
return usb_available;
6161
}
6262

6363
bool USBStorage::isConnected(){
@@ -103,12 +103,12 @@ void USBStorage::checkConnection(){
103103

104104

105105
if ((dev = host->getDevice(0)) != NULL) {
106-
available = true;
106+
usb_available = true;
107107

108108
uint8_t ceva = dev->getNbIntf();
109109
found = true;
110110
} else {
111-
available = false;
111+
usb_available = false;
112112
}
113113
}
114114

src/USBStorage.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66

77

8-
static bool available = false;
8+
static bool usb_available = false;
99

1010
class USBStorage : public Arduino_UnifiedStorage {
1111
public:

0 commit comments

Comments
 (0)