USB Host functions to support Mass Storage Class (MSC) USB Devices.
More...
|
| User API |
| User API reference of the Mass Storage Class.
|
|
| Configuration |
| Configuration of the USB Host MSC Class.
|
|
USB Host functions to support Mass Storage Class (MSC) USB Devices.
The Mass Storage Class (MSC) in the USB Host Component provides physical access to a data storage device. The USB MSC drive in the File System Component gives file I/O access to that data storage.
Software Stack
The following picture shows how the software stack is built-up for MSC device support:
Refer to:
Software Structure
The application starts the USB Host by calling USBH_Initialize. The USB Host Core will wait until an USB MSC device is attached to the system. As soon as this happens it will enumerate the device and it will be ready to be used by the application.
The data functions USBH_MSC_Read and USBH_MSC_Write can be either called by the user thread directly or called indirectly when the user thread is using file system routines like fread/fwrite which use the USB MSC Device as media for data storage.
Implementation
Steps to create an USB Host application with MSC support:
- In the Manage Run-Time Environment window select USB:Host:MSC for support of the MSC class and File System:CORE, File System:Drive:USB for using the File System Component with support for USB mass storage devices. For the File System:Drive:USB you have to set the number to the number of devices you need to support simultaneously.
- Configure the number of USB MSC devices connected in the file USBH_Config_MSC.h.
- Use the functions of the related file (USBH_MSC.c) to access the data storage.
User Code Template USBH_MSC.c
#include "USBH_MSC.h"
#include <stdint.h>
#if (!defined (RTE_FileSystem_Drive_USB_0) && !defined (RTE_FileSystem_Drive_USB_1))
#error "Project does not contain USB storage device support"
#endif
int32_t USBH_MSC_DriveGetMediaStatus (const char *drive_name) {
uint8_t drive_num;
drive_num = (uint8_t)(drive_name[1] - '0');
if (ustatus !=
usbOK)
return USBH_MSC_ERROR_DRIVE;
return USBH_MSC_OK;
}
int32_t USBH_MSC_DriveMount (const char *drive_name) {
fsStatus fstatus;
fstatus = finit (drive_name);
if (fstatus != fsOK) return USBH_MSC_ERROR;
fstatus = fmount (drive_name);
switch (fstatus) {
case fsOK:
break;
case fsNoFileSystem:
return USBH_MSC_ERROR_FORMAT;
case fsError:
case fsUnsupported:
case fsAccessDenied:
case fsInvalidParameter:
case fsInvalidDrive:
case fsInvalidPath:
case fsUninitializedDrive:
case fsDriverError:
case fsMediaError:
case fsNoMedia:
case fsNoFreeSpace:
case fsFileNotFound:
case fsDirNotEmpty:
case fsTooManyOpenFiles:
case fsAlreadyExists:
case fsNotDirectory:
return USBH_MSC_ERROR;
}
return USBH_MSC_OK;
}
int32_t USBH_MSC_DriveUnmount (const char *drive_name) {
fsStatus fstatus;
fstatus = funmount (drive_name);
if (fstatus != fsOK) return USBH_MSC_ERROR;
fstatus = funinit (drive_name);
if (fstatus != fsOK) return USBH_MSC_ERROR;
return USBH_MSC_OK;
}
uint64_t USBH_MSC_DriveGetCapacity (const char *drive_name) {
uint32_t block_count;
uint32_t block_size;
uint8_t drive_num;
drive_num = (uint8_t)(drive_name[1] - '0');
if (ustatus !=
usbOK)
return 0;
if (ustatus !=
usbOK)
return 0;
return (((uint64_t)block_count) * ((uint64_t)block_size));
}