1
+ #include < Arduino_UnifiedStorage.h>
2
+
3
+ // #define HAS_USB
4
+ // #define HAS_SD
5
+ #define HAS_QSPI
6
+
7
+ #if defined(HAS_USB)
8
+ USBStorage usb = USBStorage();
9
+ #endif
10
+
11
+ #if defined(HAS_SD)
12
+ SDStorage sd = SDStorage();
13
+ #endif
14
+
15
+ #if defined(HAS_QSPI)
16
+ InternalStorage internal = InternalStorage(2 , " user" , FS_FAT);
17
+ #endif
18
+
19
+ void runRepeatedMountTest (Arduino_UnifiedStorage * storage, String storageType, int n = 10 ){
20
+ Serial.println (" Running repeated mount test for " + storageType);
21
+
22
+ for (size_t i=0 ;i<n;i++){
23
+ int mountResult = storage->begin ();
24
+
25
+ Serial.println (" Mounting drive" );
26
+ if (mountResult != 1 ) {
27
+ Serial.println (mountResult);
28
+ Serial.println (getErrno ());
29
+ }
30
+
31
+ Folder root = storage->getRootFolder ();
32
+ UFile file = root.createFile (" file.txt" , FileMode::WRITE);
33
+ file.write (" writing stuff to the file" );
34
+ file.changeMode (FileMode::READ);
35
+ Serial.println (file.readAsString ());
36
+ file.close ();
37
+ file.remove ();
38
+
39
+ int umountResult = storage->unmount ();
40
+ if (!umountResult) {
41
+ Serial.println (" Unmounting drive" );
42
+ Serial.println (umountResult);
43
+ Serial.println (getErrno ());
44
+ } else {
45
+ Serial.println (" Succesfully unmounted" );
46
+ }
47
+ }
48
+ }
49
+
50
+
51
+ void setup (){
52
+ Serial.begin (115200 );
53
+ while (!Serial);
54
+
55
+ // format storage as FAT32
56
+ #if defined(HAS_USB)
57
+ Serial.println (" RUNNING FORMAT AND REPEATED MOUNT - USB \n " );
58
+ Serial.println (" Formatting USB drive as LittleFS: " + String (usb.formatLittleFS ()));
59
+ runRepeatedMountTest (&usb, " USB" );
60
+ Serial.println (" Formatting USB drive as FAT32: " + String (usb.formatFAT ()));
61
+ runRepeatedMountTest (&usb, " USB" );
62
+
63
+ Serial.println (" Formatting USB drive as LittleFS again: " + String (usb.formatLittleFS ()));
64
+ runRepeatedMountTest (&usb, " USB" );
65
+ Serial.println (" Formatting USB drive as FAT32 again: " + String (usb.formatFAT ()));
66
+ runRepeatedMountTest (&usb, " USB" );
67
+ #endif
68
+
69
+
70
+
71
+ #if defined(HAS_SD)
72
+ Serial.println (" RUNNING FORMAT AND REPEATED MOUNT - SD Card \n " );
73
+ Serial.println (" Formatting SD drive as LittleFS: " + String (sd.formatLittleFS ()));
74
+ runRepeatedMountTest (&sd, " SD" );
75
+ Serial.println (" Formatting SD drive as FAT32: " + String (sd.formatFAT ()));
76
+ runRepeatedMountTest (&sd, " SD" );
77
+ Serial.println (" Formatting SD drive as LittleFS again: " + String (sd.formatLittleFS ()));
78
+ runRepeatedMountTest (&sd, " SD" );
79
+ Serial.println (" Formatting SD drive as FAT32 again: " + String (sd.formatFAT ()));
80
+ runRepeatedMountTest (&sd, " SD" );
81
+ #endif
82
+
83
+
84
+ #if defined(HAS_QSPI)
85
+ Serial.println (" RUNNING FORMAT AND REPEATED MOUNT - QSPI Storage \n " );
86
+ Serial.println (" Formatting QSPI drive as LittleFS: " + String (internal.formatLittleFS ()));
87
+ runRepeatedMountTest (&internal, " QSPI" );
88
+ Serial.println (" Formatting QSPI drive as FAT32: " + String (internal.formatFAT ()));
89
+ runRepeatedMountTest (&internal, " QSPI" );
90
+ Serial.println (" Formatting SD drive as LittleFS again: " + String (internal.formatLittleFS ()));
91
+ runRepeatedMountTest (&internal, " QSPI" );
92
+ Serial.println (" Formatting SD drive as FAT32 again: " + String (internal.formatFAT ()));
93
+ runRepeatedMountTest (&internal, " QSPI" );
94
+ #endif
95
+
96
+ }
97
+
98
+ void loop (){
99
+
100
+ }
0 commit comments