Skip to content

Commit 6ae4909

Browse files
committed
Fixed USB code in demo sketch
1 parent b55a4c6 commit 6ae4909

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

examples/clox_gfx_demo/clox_gfx_demo.ino

+17-9
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ Arduino_H7_Video Display(1024, 768, USBCVideo);
3232
#include <Arduino_USBHostMbed5.h>
3333

3434
USBHostMSD msd;
35-
mbed::FATFileSystem usb("usb");
3635
#if ( defined(ARDUINO_PORTENTA_H7_M7) && defined(ARDUINO_ARCH_MBED) )
3736
mbed::DigitalOut otg(PB_14, 0);
3837
#endif
@@ -107,6 +106,14 @@ void setup() {
107106
SDRAM.begin();
108107
#endif
109108
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
110117
digitalWrite(LEDB, HIGH);
111118
}
112119

@@ -180,13 +187,8 @@ void loop() {
180187
String readFile(String filename) {
181188
String fileData;
182189
#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-
}
189190
Serial_printf("Mounting USB device...\n");
191+
mbed::FATFileSystem usb("usb");
190192
int err = usb.mount(&msd);
191193
if (err) {
192194
Serial_printf("Error mounting USB device: %d\n", err);
@@ -271,7 +273,10 @@ void* reallocate(void* pointer, size_t oldSize, size_t newSize) {
271273
}
272274

273275
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+
}
275280
memcpy(result, pointer, (oldSize < newSize) ? oldSize : newSize);
276281
SDRAM.free(pointer);
277282
return result;
@@ -292,7 +297,10 @@ void* reallocate(void* pointer, size_t oldSize, size_t newSize) {
292297
}
293298

294299
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+
}
296304
return result;
297305
}
298306
#endif

library.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=clox_gfx
2-
version=0.0.3
2+
version=0.0.4
33
author=Richard Spencer <cpptutor@outlook.com>
44
maintainer=Richard Spencer <cpptutor@outlook.com>
55
sentence=Port of the Lox interpreted programming language to Arduino

0 commit comments

Comments
 (0)