@@ -32,7 +32,6 @@ Arduino_H7_Video Display(1024, 768, USBCVideo);
32
32
#include < Arduino_USBHostMbed5.h>
33
33
34
34
USBHostMSD msd;
35
- mbed::FATFileSystem usb (" usb" );
36
35
#if ( defined(ARDUINO_PORTENTA_H7_M7) && defined(ARDUINO_ARCH_MBED) )
37
36
mbed::DigitalOut otg (PB_14, 0 );
38
37
#endif
@@ -107,6 +106,14 @@ void setup() {
107
106
SDRAM.begin ();
108
107
#endif
109
108
initVM ();
109
+ #if CLOX_USB_HOST
110
+ Serial_printf (" Waiting for USB device...\n " );
111
+ long until = millis () + 15 * 1000L ;
112
+ while (!msd.connected () && (until > millis ())) {
113
+ msd.connect ();
114
+ delay (3000 );
115
+ }
116
+ #endif
110
117
digitalWrite (LEDB, HIGH);
111
118
}
112
119
@@ -180,13 +187,8 @@ void loop() {
180
187
String readFile (String filename) {
181
188
String fileData;
182
189
#if CLOX_USB_HOST
183
- Serial_printf (" Waiting for USB device...\n " );
184
- long until = millis () + 10 * 1000 ;
185
- while (!msd.connected () && (until > millis ())) {
186
- msd.connect ();
187
- delay (3000 );
188
- }
189
190
Serial_printf (" Mounting USB device...\n " );
191
+ mbed::FATFileSystem usb (" usb" );
190
192
int err = usb.mount (&msd);
191
193
if (err) {
192
194
Serial_printf (" Error mounting USB device: %d\n " , err);
@@ -271,7 +273,10 @@ void* reallocate(void* pointer, size_t oldSize, size_t newSize) {
271
273
}
272
274
273
275
void * result = SDRAM.malloc (newSize);
274
- if (result == NULL ) exit (1 );
276
+ if (result == NULL ) {
277
+ Serial_printf (" Fatal Error: Out of memory." );
278
+ exit (1 );
279
+ }
275
280
memcpy (result, pointer, (oldSize < newSize) ? oldSize : newSize);
276
281
SDRAM.free (pointer);
277
282
return result;
@@ -292,7 +297,10 @@ void* reallocate(void* pointer, size_t oldSize, size_t newSize) {
292
297
}
293
298
294
299
void * result = realloc (pointer, newSize);
295
- if (result == NULL ) exit (1 );
300
+ if (result == NULL ) {
301
+ Serial_printf (" Fatal Error: Out of memory." );
302
+ exit (1 );
303
+ }
296
304
return result;
297
305
}
298
306
#endif
0 commit comments