Mount 2 MSD with FATfs

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Mount 2 MSD with FATfs

894 Views
aniketmarkande
Contributor III

Hi,

I am working on USB stack(TWR_K22F120MA). FAT demo works pretty good with single pendrive. But when i connect hub and connect two pen drives. i am not able to mount 2 pen drives to 2 different drives. and i believe code also does not support for multi-drive implementation.

So if somebody please guide me or give me code snippets to work for multi-drive implementation, it will be a great help.

Thank you.

Regards,

Aniket

Labels (2)
3 Replies

668 Views
jorge_a_vazquez
NXP Employee
NXP Employee

Hi Aniket Markande

Actually, if you are using the latest USB stack (the one that comes with SDK2.x), it already support HUB drivers. You can find in usb_host_config.h file a macro definitions as #define USB_HOST_CONFIG_HUB (1U), this will enable Host HUB class driver is enable.

Regardless of this, the given example doesn't implement the support for more MSD, but you can add it to it:

1. You have to add a new mass storage device instance, the example uses the g_MsdFatfsInstance global variable for the instance, so you could add a g_MsdFatfsInstance_2.

2. Inside app.c you can see that this instance is used to create the task with USB_HostMsdTask(&g_MsdFatfsInstance); (this variable is declared here as extern because we actually used in host_msd_fatfs.c).

3. In host_msd_fatfs.c implement the controller for more devices inside USB_HostMsdEvent, for example, in the kUSB_HostEventAttach event you find:

if (g_MsdFatfsInstance.deviceState == kStatus_DEV_Idle)
{
     /* the interface is supported by the application */
     g_MsdFatfsInstance.deviceHandle = deviceHandle;
     g_MsdFatfsInstance.interfaceHandle = interface;
     g_MsdFatfsInstance.configHandle = configurationHandle;
     return kStatus_USB_Success;
}‍‍‍‍‍‍‍‍

In this case you will have to implement a count of devices to use different handlers. This instance is also used in kUSB_HostEventEnumerationDone and in kUSB_HostEventDetach events

Hope this information could help you.

Best Regards

Jorge Alcala

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

668 Views
aniketmarkande
Contributor III

Hi,

Thanks for your reply and i was able to run two mass storage devices :smileyhappy:

Now i have one more device connected to hub which is speaker and the problem is "USB_HostEvent()" is common callback for attach/detach. Then how to differentiate which device has been connected?

I tried this way, but it causes problem.

STATIC usb_status_t USB_HostEvent(usb_device_handle deviceHandle,
                                  usb_host_configuration_handle configurationHandle,
                                  uint32_t eventCode)
{
    usb_status_t status = kStatus_USB_Success;
    switch (eventCode)
    {
        case kUSB_HostEventAttach:
        case kUSB_HostEventEnumerationDone:
        case kUSB_HostEventDetach:
                status = USB_HostMsdEvent(deviceHandle, configurationHandle, eventCode);
                status = USB_HostAudioEvent(deviceHandle, configurationHandle, eventCode);
            break;

        case kUSB_HostEventNotSupported:
            usb_echo("Unsupported Device\r\n");
            break;

        default:
            break;
    }
    return status;
}

Thank you.

0 Kudos

668 Views
aniketmarkande
Contributor III

Hi,

i have mounted 1 MSD on 0: and another on 1: , is this correct (as a two physical drives)?

Also when i am trying to change drive using f_chdrive(), its changing the drive variable CurrVol in code. But when i perform any operation it is performed on last drive which i have mounted.

please guide me on how to mount two MSD devices and access them simultaneously using FATfs.

Thank you.

Regards.

0 Kudos