Using the MSC Driver

To use the MSC driver, two files, in addition to the generic file system files, must be included in the build:

  • fs_dev_msc.c.
  • fs_dev_msc.h.

The file fs_dev_msc.h must also be #included in any application or header files that directly reference the driver (for example, by registering the device driver). The following directory must be on the project include path:

  • \Micrium\Software\uC-FS\Dev\MSC

Before µC/FS is initialized, the µC/USB host stack must be initialized as shown in Listing - Example µC/USB initialization. The file system initialization function (FS_Init()) must then be called and the MSC driver, FSDev_MSC, restivered (using FS_DevDrvAdd()). The USB notification function should add/remove devices when events occur, as shown in Listing - Example µC/USB initialization.

ROM/RAM characteristics and performance benchmarks of the MSC driver can be found in Driver Characterization.


Listing - Example µC/USB initialization
static  void  App_InitUSB_Host (void)
{
    USBH_ERR  err;
    err = USBH_HostCreate(&App_USB_Host, &USBH_AT91SAM9261_Drv);
    if (err != USBH_ERR_NONE) {
        return;
    }
    err = USBH_HostInit(&App_USB_Host);
    if (err != USBH_ERR_NONE) {
        return;
    }
    USBH_ClassDrvReg(&App_USB_Host, &USBH_MSC_ClassDrv, 
                             (USBH_CLASS_NOTIFY_FNCT)App_USB_HostMSC_ClassNotify, (void *)0);
}


Listing - µC/USB MSC notification function
static  void  App_USB_HostMSC_ClassNotify (void        *pclass_dev,
                                           CPU_INT08U   is_conn,
                                           void        *pctx)
{
    USBH_MSC_DEV  *p_msc_dev;
    USBH_ERR       usb_err;
    FS_ERR         fs_err;
    p_msc_dev = (USBH_MSC_DEV *)pclass_dev;
    switch (is_conn) {
        case USBH_CLASS_DEV_STATE_CONNECTED:        /* ----- MASS STORAGE DEVICE CONN'D ----- */
             usb_err = USBH_MSC_RefAdd(p_msc_dev);
             if (usb_err == USBH_ERR_NONE) {
                 FSDev_MSC_DevOpen(p_msc_dev, &fs_err);
             }
             break;
        case USBH_CLASS_DEV_STATE_REMOVED:          /* ----- MASS STORAGE DEVICE REMOVED ---- */
             FSDev_MSC_DevClose(p_msc_dev);
             USBH_MSC_RefRel(p_msc_dev);
             break;
        default:
             break;
    }
}

If the file system and USB stack initialization succeed, the file system will produce the trace output as shown in Figure - MSC detection trace output (if a sufficiently high trace level is configured) when the a MSC device is connected. See Trace Configuration about configuring the trace level. 

Figure - MSC detection trace output