I found an issue with the USB A port on the Giga with newer USB drives. I have a few older flash drives that have always worked just fine with my Giga, but newer flash drives would seem to go to sleep or some kind of idle mode that the Giga would interpret as disconnected, and I couldn't get the Giga to access them again, and it was causing the Mbed OS to crash when it was called to use the USB for logging.
I had been trying a bunch of different things and couldn't solve it, so I turned to ChatGPT, Gemini, and Copilot for help. Between the three of them, a solution that "we" came up with was to patch USBHostMSD.h (found in C:\Users\(your profile)\Documents\Arduino\libraries\Arduino_USBHostMbed5\src\USBHostMSD) under public with a function to access the private testUnitReady() function:
int keepAwake()
{
if (!host || !dev || !dev_connected || !disk_init) {
return -1;
}
return testUnitReady();
}
Then to access this function, we used an RTOS function to call the patched function at regular intervals that were shorter than the sleep/idle mode starting (3.5 seconds seems to work, but you can try different times if you want).
Function (I used usbMutex.trylock() instead of usbMutex.lock()in case the USB drive was currently being used to log information, as it uses usbMutex.lock()):
void usb_keep_awake_worker() {
while (true) {
{
if (usbMutex.trylock()) {
msd.read(usbKeepAwakeBuffer, 0, sizeof(usbKeepAwakeBuffer));
msd.keepAwake();
usbMutex.unlock();
}
}
rtos::ThisThread::sleep_for(3500);
}
}
As always, if you want to try it, use this code with caution.
Thanks for taking the time to share your findings @littlejohn657!
In order to make relevant information available to any who are interested in this subject, I'll share a link to the formal report you submitted to the developers of the "Arduino_USBHostMbed5" library:
Hi @littlejohn657 , I hit this same problem some time ago. Your solution is elegant, mine not so much - but I'll share it as it doesn't require a lib hack.
I use the USB-A drive from the M4 core for blackbox logging of M7 activity. I use this code snippet to open an 'idle' file for overwrite, write to it and close, if the drive's not been written to in the last 5 secs to keep it awake.