Skip to content

GIGA R1 USB Mass Storage Directory example causes MbedOS crash #29

Open
@mjs513

Description

@mjs513

Reference: https://forum.arduino.cc/t/giga-r1-usb-mass-storage-examples-has-anyone-managed-to-run-an-example-project/1127694

Several of us (@bobthedog, @KurtE and me) have been experimenting with the USBHost Mass Storage Example:

#include <DigitalOut.h>
#include <FATFileSystem.h>
#include <Arduino_USBHostMbed5.h>

USBHostMSD msd;
mbed::FATFileSystem usb("usb");


void setup()
{
    Serial.begin(115200);
    
    pinMode(PA_15, OUTPUT); //enable the USB-A port
    digitalWrite(PA_15, HIGH);
    
    while (!Serial)
        ;

    Serial.println("Starting USB Dir List example...");

    // if you are using a Max Carrier uncomment the following line
    // start_hub();

    while (!msd.connect()) {
        //while (!port.connected()) {
        delay(1000);
    }

    Serial.print("Mounting USB device... ");
    int err = usb.mount(&msd);
    if (err) {
        Serial.print("Error mounting USB device ");
        Serial.println(err);
        while (1);
    }
    Serial.println("done.");

    char buf[256];

    // Display the root directory
    Serial.print("Opening the root directory... ");
    DIR* d = opendir("/usb/");
    Serial.println(!d ? "Fail :(" : "Done");
    if (!d) {
        snprintf(buf, sizeof(buf), "error: %s (%d)\r\n", strerror(errno), -errno);
        Serial.print(buf);
    }
    Serial.println("done.");

    Serial.println("Root directory:");
    unsigned int count { 0 };
    while (true) {
        struct dirent* e = readdir(d);
        if (!e) {
            break;
        }
        count++;
        snprintf(buf, sizeof(buf), "    %s\r\n", e->d_name);
        Serial.print(buf);
    }
    Serial.print(count);
    Serial.println(" files found!");

    snprintf(buf, sizeof(buf), "Closing the root directory... ");
    Serial.print(buf);
    fflush(stdout);
    err = closedir(d);
    snprintf(buf, sizeof(buf), "%s\r\n", (err < 0 ? "Fail :(" : "OK"));
    Serial.print(buf);
    if (err < 0) {
        snprintf(buf, sizeof(buf), "error: %s (%d)\r\n", strerror(errno), -errno);
        Serial.print(buf);
    }
}

void loop()
{
}

So far as a Bottom Line Up Front:

Windows 10 with 2.2.1 IDE : Red lights of doom.
Windows 10 with 1.8.19 IDE : Works.

Windows 11 with 2.2.1 IDE : Red lights of doom.
Windows 11 with 1.8.19 IDE : Works.

Linux: MacOsX and RPI4
IDE 2.2.1 works

IDE 2.2.1 on Windows 11
Using Serial: Red lights of doom.
Using Serial1: Works

Example works if using release 0.0.3

Posts 31, 37, and 38 show and discuss debug outputs.

Believe in all cases with we are using GIGA version 4.0.8 (installed via boards manager).

As for memory sticks a number have been tested: I have used an old SansDisk Cruzer 2GB and a generic Microcenter 64Gb.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions