Skip to content

Commit 6dc5317

Browse files
little fixes
1 parent 6c89cfb commit 6dc5317

File tree

17 files changed

+134
-144
lines changed

17 files changed

+134
-144
lines changed

.vscode/settings.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"files.associations": {
3+
"array": "cpp",
4+
"deque": "cpp",
5+
"string": "cpp",
6+
"unordered_map": "cpp",
7+
"vector": "cpp",
8+
"string_view": "cpp",
9+
"initializer_list": "cpp"
10+
}
11+
}

docs/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ void setup(){
2424
### Format QSPI Flash, SD cards, and USB mass storage devices
2525
This library also allows you to format any partition or drive to either FAT or LittleFS filesystems.
2626

27-
```storageMedium.formatFAT()```
27+
```storageMedium.format(FS_FAT)```
2828
or
29-
```storageMedium.formatLittleFS();```
29+
```storageMedium.format(FS_LITTLEFS);```
3030

3131
Please make sure you call format before calling `begin()` or after calling `unmount()`.
3232

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(2, "user", FS_FAT);
30+
InternalStorage internalStorage = InternalStorage();
3131

3232

3333
// Helper function to prints the contents of a folder, including subdirectories (marked as "[D]") and files (marked as "[F]").

examples/PortentaH7Logger/PortentaH7Logger.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ void setup() {
156156
while (!Serial);
157157
pinMode(USB_MOUNTED_LED, OUTPUT);
158158
Serial.println("Formatting internal storage...");
159-
int formatted = internalStorage.formatFAT();
159+
int formatted = internalStorage.format(FS_FAT);
160160
Serial.print("QSPI Format status: "); Serial.println(formatted);
161161

162162
//configureRS485(baudrate);

examples/SimpleStorageWriteRead/SimpleStorageWriteRead.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ void printFolderContents(Folder dir, int indentation = 0) {
5151
// Uncomment one of the three lines below to select between SD card, USB or internal storage
5252
//SDStorage unifiedStorage = SDStorage(); // Create an instance for interacting with SD card storage
5353
//USBStorage unifiedStorage = USBStorage() // Create an instance for interacting with USB storage
54-
InternalStorage internalStorage = InternalStorage(2, "user", FS_FAT); // Create an instance for interacting with internal Flash storage (default)
54+
InternalStorage internalStorage = InternalStorage(); // Create an instance for interacting with internal Flash storage (default)
5555

5656
void setup() {
5757
Serial.begin(115200);

extras/tests/TestExisting/TestExisting.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ void setup() {
1414

1515

1616

17-
internalStorage.formatLittleFS();
17+
internalStorage.format(FS_LITTLEFS);
1818
internalStorage.begin();
1919

2020

extras/tests/TestRepeatedFormatMount/TestRepeatedFormatMount.ino

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,41 +55,41 @@ void setup(){
5555
// format storage as FAT32
5656
#if defined(HAS_USB)
5757
Serial.println("RUNNING FORMAT AND REPEATED MOUNT - USB \n");
58-
Serial.println("Formatting USB drive as LittleFS: " + String(usb.formatLittleFS()));
58+
Serial.println("Formatting USB drive as LittleFS: " + String(usb.format(FS_LITTLEFS)));
5959
runRepeatedMountTest(&usb, "USB");
60-
Serial.println("Formatting USB drive as FAT32: " + String(usb.formatFAT()));
60+
Serial.println("Formatting USB drive as FAT32: " + String(usb.format(FS_FAT)));
6161
runRepeatedMountTest(&usb, "USB");
6262

63-
Serial.println("Formatting USB drive as LittleFS again: " + String(usb.formatLittleFS()));
63+
Serial.println("Formatting USB drive as LittleFS again: " + String(usb.format(FS_LITTLEFS)));
6464
runRepeatedMountTest(&usb, "USB");
65-
Serial.println("Formatting USB drive as FAT32 again: " + String(usb.formatFAT()));
65+
Serial.println("Formatting USB drive as FAT32 again: " + String(usb.format(FS_FAT)));
6666
runRepeatedMountTest(&usb, "USB");
6767
#endif
6868

6969

7070

7171
#if defined(HAS_SD)
7272
Serial.println("RUNNING FORMAT AND REPEATED MOUNT - SD Card \n");
73-
Serial.println("Formatting SD drive as LittleFS: " + String(sd.formatLittleFS()));
73+
Serial.println("Formatting SD drive as LittleFS: " + String(sd.format(FS_LITTLEFS)));
7474
runRepeatedMountTest(&sd, "SD");
75-
Serial.println("Formatting SD drive as FAT32: " + String(sd.formatFAT()));
75+
Serial.println("Formatting SD drive as FAT32: " + String(sd.format(FS_FAT)));
7676
runRepeatedMountTest(&sd, "SD");
77-
Serial.println("Formatting SD drive as LittleFS again: " + String(sd.formatLittleFS()));
77+
Serial.println("Formatting SD drive as LittleFS again: " + String(sd.format(FS_LITTLEFS)));
7878
runRepeatedMountTest(&sd, "SD");
79-
Serial.println("Formatting SD drive as FAT32 again: " + String(sd.formatFAT()));
79+
Serial.println("Formatting SD drive as FAT32 again: " + String(sd.format(FS_FAT)));
8080
runRepeatedMountTest(&sd, "SD");
8181
#endif
8282

8383

8484
#if defined(HAS_QSPI)
8585
Serial.println("RUNNING FORMAT AND REPEATED MOUNT - QSPI Storage \n");
86-
Serial.println("Formatting QSPI drive as LittleFS: " + String(internal.formatLittleFS()));
86+
Serial.println("Formatting QSPI drive as LittleFS: " + String(internal.format(FS_LITTLEFS)));
8787
runRepeatedMountTest(&internal, "QSPI");
88-
Serial.println("Formatting QSPI drive as FAT32: " + String(internal.formatFAT()));
88+
Serial.println("Formatting QSPI drive as FAT32: " + String(internal.format(FS_FAT)));
8989
runRepeatedMountTest(&internal, "QSPI");
90-
Serial.println("Formatting SD drive as LittleFS again: " + String(internal.formatLittleFS()));
90+
Serial.println("Formatting SD drive as LittleFS again: " + String(internal.format(FS_LITTLEFS)));
9191
runRepeatedMountTest(&internal, "QSPI");
92-
Serial.println("Formatting SD drive as FAT32 again: " + String(internal.formatFAT()));
92+
Serial.println("Formatting SD drive as FAT32 again: " + String(internal.format(FS_FAT)));
9393
runRepeatedMountTest(&internal, "QSPI");
9494
#endif
9595

extras/tests/TestUnified/TestUnified.ino

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ void sd_and_usb(){
6868
Serial.println("TESTING SD AND USB \n\n\n\n");
6969

7070
Serial.println("-----------------------------");
71-
Serial.println("Formatting USB to FAT: " + String(usb->formatFAT()));
72-
Serial.println("Formatting SD to FAT: " + String(sd->formatFAT()));
71+
Serial.println("Formatting USB to FAT: " + String(usb->format(FS_FAT)));
72+
Serial.println("Formatting SD to FAT: " + String(sd->format(FS_FAT)));
7373
Serial.println("-----------------------------");
7474

7575

@@ -80,7 +80,7 @@ void sd_and_usb(){
8080
test("copy", sd, usb, "SD FAT", "USB FAT");
8181

8282
Serial.println("-----------------------------");
83-
Serial.println("Formatting USB to LittleFS:" + String(usb->formatLittleFS()));
83+
Serial.println("Formatting USB to LittleFS:" + String(usb->format(FS_LITTLEFS)));
8484
Serial.println("-----------------------------");
8585

8686
test("move", usb, sd, "USB LittleFS", "SD FAT ");
@@ -90,7 +90,7 @@ void sd_and_usb(){
9090
test("copy", sd, usb, "SD FAT", "USB LittleFS");
9191

9292
Serial.println("-----------------------------");
93-
Serial.println("Formatting SD to LittleFS: "+ String(sd->formatLittleFS()));
93+
Serial.println("Formatting SD to LittleFS: "+ String(sd->format(FS_LITTLEFS)));
9494
Serial.println("-----------------------------");
9595

9696
test("move", sd, usb, "SD LittleFS", "USB LittleFS");
@@ -100,7 +100,7 @@ void sd_and_usb(){
100100
test("copy", usb, sd, "USB LittleFS", "SD LittleFS");
101101

102102
Serial.println("-----------------------------");
103-
Serial.println("Formatting USB to FAT: " + String(usb->formatFAT()));
103+
Serial.println("Formatting USB to FAT: " + String(usb->format(FS_FAT)));
104104
Serial.println("-----------------------------");
105105

106106
test("move", usb, sd, "USB FAT", "SD LittleFS");
@@ -116,8 +116,8 @@ void sd_and_usb(){
116116
void qspi_and_sd() {
117117
Serial.println("TESTING QSPI AND SD \n\n\n\n");
118118
Serial.println("-----------------------------");
119-
Serial.println("Formatting QSPI to FAT: " + String(qspi->formatFAT()));
120-
Serial.println("Formatting SD to FAT: " + String(sd->formatFAT()));
119+
Serial.println("Formatting QSPI to FAT: " + String(qspi->format(FS_FAT)));
120+
Serial.println("Formatting SD to FAT: " + String(sd->format(FS_FAT)));
121121
Serial.println("-----------------------------");
122122

123123
test("move", qspi, sd, "QSPI FAT", "SD FAT");
@@ -127,7 +127,7 @@ void qspi_and_sd() {
127127
test("copy", sd, qspi, "SD FAT", "QSPI FAT");
128128

129129
Serial.println("-----------------------------");
130-
Serial.println("Formatting QSPI to LittleFS:" + String(qspi->formatLittleFS()));
130+
Serial.println("Formatting QSPI to LittleFS:" + String(qspi->format(FS_LITTLEFS)));
131131
Serial.println("-----------------------------");
132132

133133
test("move", qspi, sd, "QSPI LittleFS", "SD FAT");
@@ -137,7 +137,7 @@ void qspi_and_sd() {
137137
test("copy", sd, qspi, "SD FAT", "QSPI LittleFS");
138138

139139
Serial.println("-----------------------------");
140-
Serial.println("Formatting SD to LittleFS: "+ String(sd->formatLittleFS()));
140+
Serial.println("Formatting SD to LittleFS: "+ String(sd->format(FS_LITTLEFS)));
141141
Serial.println("-----------------------------");
142142

143143
test("move", qspi, sd, "QSPI LittleFS", "SD LittleFS");
@@ -147,7 +147,7 @@ void qspi_and_sd() {
147147
test("copy", sd, qspi, "SD LittleFS", "QSPI LittleFS");
148148

149149
Serial.println("-----------------------------");
150-
Serial.println("Formatting QSPI to FAT: " + String(qspi->formatFAT()));
150+
Serial.println("Formatting QSPI to FAT: " + String(qspi->format(FS_FAT)));
151151
Serial.println("-----------------------------");
152152

153153
test("move", sd, qspi, "SD LittleFS", "QSPI FAT");
@@ -163,8 +163,8 @@ void qspi_and_usb() {
163163

164164
Serial.println("TESTING QSPI AND USB \n\n\n\n");
165165
Serial.println("-----------------------------");
166-
Serial.println("Formatting QSPI to FAT: " + String(qspi->formatFAT()));
167-
Serial.println("Formatting USB to FAT: " + String(usb->formatFAT()));
166+
Serial.println("Formatting QSPI to FAT: " + String(qspi->format(FS_FAT)));
167+
Serial.println("Formatting USB to FAT: " + String(usb->format(FS_FAT)));
168168
Serial.println("-----------------------------");
169169

170170
test("move", qspi, usb, "QSPI FAT", "USB FAT");
@@ -174,7 +174,7 @@ void qspi_and_usb() {
174174
test("copy", usb, qspi, "USB FAT", "QSPI FAT");
175175

176176
Serial.println("-----------------------------");
177-
Serial.println("Formatting QSPI to LittleFS:" + String(qspi->formatLittleFS()));
177+
Serial.println("Formatting QSPI to LittleFS:" + String(qspi->format(FS_LITTLEFS)));
178178
Serial.println("-----------------------------");
179179

180180
test("move", qspi, usb, "QSPI LittleFS", "USB FAT");
@@ -184,7 +184,7 @@ void qspi_and_usb() {
184184
test("copy", usb, qspi, "USB FAT", "QSPI LittleFS");
185185

186186
Serial.println("-----------------------------");
187-
Serial.println("Formatting USB to LittleFS: "+ String(usb->formatLittleFS()));
187+
Serial.println("Formatting USB to LittleFS: "+ String(usb->format(FS_LITTLEFS)));
188188
Serial.println("-----------------------------");
189189

190190
test("move", qspi, usb, "QSPI LittleFS", "USB LittleFS");
@@ -195,7 +195,7 @@ void qspi_and_usb() {
195195
test("copy", usb, qspi, "USB LittleFS", "QSPI LittleFS");
196196

197197
Serial.println("-----------------------------");
198-
Serial.println("Formatting QSPI to FAT:" + String(qspi->formatFAT()));
198+
Serial.println("Formatting QSPI to FAT:" + String(qspi->format(FS_FAT)));
199199
Serial.println("-----------------------------");
200200

201201
test("move", usb, qspi, "USB LittleFS", "QSPI FAT");
@@ -216,23 +216,23 @@ void setup(){
216216
sd_and_usb();
217217
qspi_and_sd();
218218
Serial.println("Tests finished, formatting all partitions back to FAT:");
219-
Serial.println("\t * Formatting QSPI to FAT: " + String(qspi->formatFAT()));
220-
Serial.println("\t * Formatting SD to FAT: " + String(sd->formatFAT()));
221-
Serial.println("\t * Formatting USB to FAT: " + String(usb->formatFAT()));
219+
Serial.println("\t * Formatting QSPI to FAT: " + String(qspi->format(FS_FAT)));
220+
Serial.println("\t * Formatting SD to FAT: " + String(sd->format(FS_FAT)));
221+
Serial.println("\t * Formatting USB to FAT: " + String(usb->format(FS_FAT)));
222222
#elif defined(HAS_USB) && defined(HAS_SD)
223223
sd_and_usb();
224-
Serial.println("\t * Formatting SD to FAT:" + String(sd->formatFAT()));
225-
Serial.println("\t * Formatting USB to FAT:" + String(usb->formatFAT()));
224+
Serial.println("\t * Formatting SD to FAT:" + String(sd->format(FS_FAT)));
225+
Serial.println("\t * Formatting USB to FAT:" + String(usb->format(FS_FAT)));
226226
#elif defined(HAS_USB) && defined(HAS_QSPI)
227227
qspi_and_usb();
228228
Serial.println("Tests finished, formatting all partitions back to FAT:");
229-
Serial.println("\t * Formatting QSPI to FAT:" + String(qspi->formatFAT()));
230-
Serial.println("\t * Formatting USB to FAT:" + String(usb->formatFAT()));
229+
Serial.println("\t * Formatting QSPI to FAT:" + String(qspi->format(FS_FAT)));
230+
Serial.println("\t * Formatting USB to FAT:" + String(usb->format(FS_FAT)));
231231
#elif defined(HAS_SD) && defined(HAS_QSPI)
232232
qspi_and_sd();
233233
Serial.println("Tests finished, formatting all partitions back to FAT:");
234-
Serial.println("\t * Formatting QSPI to FAT:" + String(qspi->formatFAT()));
235-
Serial.println("\t * Formatting SD to FAT:" + String(sd->formatFAT()));
234+
Serial.println("\t * Formatting QSPI to FAT:" + String(qspi->format(FS_FAT)));
235+
Serial.println("\t * Formatting SD to FAT:" + String(sd->format(FS_FAT)));
236236
#elif defined(HAS_USB)
237237
Serial.println("Cannot perform tests if only one storage type is selected");
238238
#elif defined(HAS_SD)

src/Arduino_UnifiedStorage.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,11 @@ class Arduino_UnifiedStorage {
5858
virtual Folder getRootFolder() = 0;
5959

6060
/**
61-
* Formats the storage with the FAT file system.
61+
* Formats the storage with the selected file system.
6262
* @return 1 if successful, 0 if failed.
6363
*/
64-
virtual int formatLittleFS() = 0;
64+
virtual int format(FileSystems fs) = 0;
6565

66-
/**
67-
* Formats the storage with the FAT file system.
68-
*
69-
* @return 1 if successful, 0 if failed.
70-
*/
71-
virtual int formatFAT() = 0;
7266
};
7367

7468

src/InternalStorage.cpp

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -72,30 +72,29 @@ void InternalStorage::setQSPIPartitionName(const char * name){
7272
this -> partitionName = (char *)name;
7373
}
7474

75-
int InternalStorage::formatFAT(){
75+
int InternalStorage::format(FileSystems fs){
7676
this -> begin();
7777
this -> unmount();
78-
this -> fs = FS_FAT;
79-
#if defined(ARDUINO_PORTENTA_C33)
80-
this -> userDataFileSystem = new FATFileSystem(this->partitionName);
81-
return this -> userDataFileSystem -> reformat(this-> userData);
82-
#elif defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_OPTA)
83-
this -> userDataFileSystem = new mbed::FATFileSystem(this->partitionName);
84-
return this -> userDataFileSystem -> reformat(this-> userData);
85-
#endif
86-
}
78+
this -> fs = fs;
8779

88-
int InternalStorage::formatLittleFS(){
89-
this -> begin();
90-
this -> unmount();
91-
this -> fs = FS_LITTLEFS;
92-
#if defined(ARDUINO_PORTENTA_C33)
93-
this -> userDataFileSystem = new LittleFileSystem(this->partitionName);
94-
return this -> userDataFileSystem -> reformat(this-> userData);
95-
#elif defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_OPTA)
96-
this -> userDataFileSystem = new mbed::LittleFileSystem(this->partitionName);
97-
return this -> userDataFileSystem -> reformat(this-> userData);
98-
#endif
80+
81+
if(fs == FS_FAT){
82+
#if defined(ARDUINO_PORTENTA_C33)
83+
this -> userDataFileSystem = new FATFileSystem(this->partitionName);
84+
return this -> userDataFileSystem -> reformat(this-> userData);
85+
#elif defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_OPTA)
86+
this -> userDataFileSystem = new mbed::FATFileSystem(this->partitionName);
87+
return this -> userDataFileSystem -> reformat(this-> userData);
88+
#endif
89+
} if (fs == FS_LITTLEFS) {
90+
#if defined(ARDUINO_PORTENTA_C33)
91+
this -> userDataFileSystem = new LittleFileSystem(this->partitionName);
92+
return this -> userDataFileSystem -> reformat(this-> userData);
93+
#elif defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_OPTA)
94+
this -> userDataFileSystem = new mbed::LittleFileSystem(this->partitionName);
95+
return this -> userDataFileSystem -> reformat(this-> userData);
96+
#endif
97+
}
9998
}
10099

101100
#if defined(ARDUINO_PORTENTA_C33)

src/InternalStorage.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,12 @@ class InternalStorage : public Arduino_UnifiedStorage {
6666
void setQSPIPartitionName(const char *name);
6767

6868
/**
69-
* Formats the internal storage with the FAT file system.
69+
* Formats the internal storage with the selceted file system.
7070
*
7171
* @return 1 if successful, 0 if failed.
7272
*/
73-
int formatFAT();
73+
int format(FileSystems fs) override;
7474

75-
/**
76-
* Formats the internal storage with the LittleFS file system.
77-
*
78-
* @return 1 if successful, 0 if failed.
79-
*/
80-
int formatLittleFS();
8175

8276
/**
8377
* Retrieves the block device associated with the internal storage.

src/SDStorage.cpp

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ SDStorage::SDStorage(){
99
}
1010

1111
int SDStorage::begin(){
12-
return mount(DEV_SDCARD, this->fs, MNT_DEFAULT) == 0;
12+
return mount(DEV_SDCARD, this->fileSystem, MNT_DEFAULT) == 0;
1313
}
1414

1515
int SDStorage::begin(FileSystems fs){
16-
this -> fs = fs;
16+
this -> fileSystem = fs;
1717
this -> begin();
1818
}
1919

@@ -25,18 +25,19 @@ Folder SDStorage::getRootFolder(){
2525
return Folder("/sdcard");
2626
}
2727

28-
int SDStorage::formatFAT(){
29-
this -> begin();
30-
this -> unmount();
31-
this -> fs = FS_FAT;
32-
return mkfs(DEV_SDCARD, FS_FAT);
33-
}
28+
int SDStorage::format(FileSystems fs){
29+
if(fs == FS_FAT){
30+
this -> begin();
31+
this -> unmount();
32+
this -> fileSystem = FS_FAT;
33+
return mkfs(DEV_SDCARD, FS_FAT);
34+
} else if (fs == FS_LITTLEFS) {
35+
this -> begin();
36+
this -> unmount();
37+
this -> fileSystem = FS_LITTLEFS;
38+
return mkfs(DEV_SDCARD, FS_LITTLEFS);
39+
}
3440

35-
int SDStorage::formatLittleFS(){
36-
this -> begin();
37-
this -> unmount();
38-
this -> fs = FS_LITTLEFS;
39-
return mkfs(DEV_SDCARD, FS_LITTLEFS);
4041
}
4142

4243

0 commit comments

Comments
 (0)