USB Component  Version 5.0
MDK-Professional Middleware for USB Device and Host
 All Data Structures Functions Variables Enumerations Enumerator Groups Pages
Mass Storage Class Functions

Enable the USB Host to support USB Mass Storage Devices. More...

Functions

usbStatus USBH_MSC_GetDeviceStatus (int8_t instance)
 Get status of Mass Storage Device.
 
usbStatus USBH_MSC_Read (int8_t instance, uint32_t lba, uint16_t cnt, uint8_t *buf)
 Read requested number of blocks from Mass Storage Device.
 
usbStatus USBH_MSC_Write (int8_t instance, uint32_t lba, uint16_t cnt, const uint8_t *buf)
 Write requested number of blocks to Mass Storage Device.
 
usbStatus USBH_MSC_ReadCapacity (int8_t instance, uint32_t *block_count, uint32_t *block_size)
 Read capacity of Mass Storage Device.
 

Description

Enable the USB Host to support USB Mass Storage Devices.

The MSC class in the USB Component is used for data storage.

Refer to:

To create an USB Host with support for the MSC class:

Configuration File USBH_Config_MSC.h
The USB Host Component has one configuration file for the MSC Device class: USBH_Config_MSC.h. This configuration file defines the maximum number of concurrent MSC Devices that may be attached to the system.

Code Example

/*------------------------------------------------------------------------------
USB Host Thread
*----------------------------------------------------------------------------*/
void USBH_Thread (void const *arg) {
osPriority priority; /* Thread priority */
char con = 0; /* Connection status of MSCs */
char con_ex = 40; /* Previous connection status
+ initial time in 100 ms
intervals for initial disp */
USBH_Initialize (0); /* Initialize USB Host 0 */
USBH_Initialize (1); /* Initialize USB Host 1 */
while (1) {
con = (((USBH_MSC_GetStatus(1) == usbOK) << 1) | (USBH_MSC_GetStatus(0) == usbOK)) & 3;
if ((con ^ con_ex) & 3) { /* if connection changed */
priority = osThreadGetPriority (osThreadGetId());
osThreadSetPriority (osThreadGetId(), osPriorityHigh);
if ((con ^ con_ex) & 1) {
if (con & 1) { /* if device 0 connected */
con |= init_msd ("U0:");
printf ("\nConnected Drive U0:\n");
} else { /* if device 0 disconnected */
printf ("\nDisconnected Drive U0:\n");
}
}
if ((con ^ con_ex) & 2) {
if (con & 2) { /* if device 1 connected */
con |= init_msd ("U1:");
printf ("\nConnected Drive U1:\n");
} else { /* if device 1 disconnected */
printf ("\nDisconnected Drive U1:\n");
}
}
fflush (stdout);
osThreadSetPriority (osThreadGetId(), priority);
con_ex = con;
} else if (con_ex > 3) { /* if initial time active */
con_ex -= 4; /* decrement initial time */
if ((con_ex <= 3) && (!con)) { /* if initial time expired */
priority = osThreadGetPriority (osThreadGetId());
osThreadSetPriority (osThreadGetId(), osPriorityHigh);
printf ("\nNo drives connected ... \n");
fflush (stdout);
osThreadSetPriority (osThreadGetId(), priority);
con_ex = con;
} else {
osDelay(400);
}
}
osDelay(100);
}
}
osThreadDef(USBH_Thread, osPriorityNormal, 1, NULL);

Function Documentation

usbStatus USBH_MSC_GetDeviceStatus ( int8_t  instance)

Get status of Mass Storage Device.

Parameters
[in]instanceinstance of MSC Device.
Returns
status code that indicates the execution status of the function as defined with usbStatus.

The function USBH_MSC_GetDeviceStatus checks if a mass storage device instance is connected and initialized.

The argument instance is specifying the instance of the MSC device.

Code Example

#include "cmsis_os.h" /* CMSIS RTOS definitions */
#include "rl_fs.h" /* FileSystem definitions */
#include "rl_usb.h" /* RL-USB function prototypes */
/*------------------------------------------------------------------------------
USB Host Thread
*----------------------------------------------------------------------------*/
void USBH_Thread (void const *arg) {
osPriority priority; /* Thread priority */
char con = 0; /* Connection status of MSCs */
char con_ex = 40; /* Previous connection status
+ initial time in 100 ms
intervals for initial disp */
USBH_Initialize (0); /* Initialize USB Host 0 */
USBH_Initialize (1); /* Initialize USB Host 1 */
while (1) {
con = ((USBH_MSC_GetStatus(1) << 1) | USBH_MSC_GetStatus(0)) & 3;
if ((con ^ con_ex) & 3) { /* if connection changed */
priority = osThreadGetPriority (osThreadGetId());
osThreadSetPriority (osThreadGetId(), osPriorityHigh);
if ((con ^ con_ex) & 1) {
if (con & 1) { /* if device 0 connected */
con |= init_msd ("U0:");
printf ("\nConnected Drive U0:\n");
} else { /* if device 0 disconnected */
printf ("\nDisconnected Drive U0:\n");
}
}
if ((con ^ con_ex) & 2) {
if (con & 2) { /* if device 1 connected */
con |= init_msd ("U1:");
printf ("\nConnected Drive U1:\n");
} else { /* if device 1 disconnected */
printf ("\nDisconnected Drive U1:\n");
}
}
fflush (stdout);
osThreadSetPriority (osThreadGetId(), priority);
con_ex = con;
} else if (con_ex > 3) { /* if initial time active */
con_ex -= 4; /* decrement initial time */
if ((con_ex <= 3) && (!con)) { /* if initial time expired */
priority = osThreadGetPriority (osThreadGetId());
osThreadSetPriority (osThreadGetId(), osPriorityHigh);
printf ("\nNo drives connected ... \n");
fflush (stdout);
osThreadSetPriority (osThreadGetId(), priority);
con_ex = con;
} else {
osDelay(400);
}
}
osDelay(100);
}
}
usbStatus USBH_MSC_Read ( int8_t  instance,
uint32_t  lba,
uint16_t  cnt,
uint8_t *  buf 
)

Read requested number of blocks from Mass Storage Device.

Parameters
[in]instanceinstance of MSC Device.
[in]lbalogical block address of first block to read.
[in]cntnumber of contiguous blocks to read.
[out]bufdata buffer in which to read data.
Returns
status code that indicates the execution status of the function as defined with usbStatus.

The function USBH_MSC_Read reads data from a mass storage device and stores them in a buffer.

The argument instance is specifying the device instance.

The argument lba is the address of the starting block to be read.

The argument cnt is a value indicating the number of blocks to be read.

The argument buf is pointing to the location where the data will be read.

Code Example

// coming soon
usbStatus USBH_MSC_ReadCapacity ( int8_t  instance,
uint32_t *  block_count,
uint32_t *  block_size 
)

Read capacity of Mass Storage Device.

Parameters
[in]instanceinstance of MSC Device.
[out]block_countpointer to where total number of blocks available will be read.
[out]block_sizepointer to where block size will be read.
Returns
status code that indicates the execution status of the function as defined with usbStatus.

The function USBH_MSC_ReadCapacity reads the capacity of a mass storage device.

The argument instance is specifying the device instance.

The argument block_count is a pointer to where the total number of available blocks will be written.

The argument block_size is a pointer to where the block size will be written.

Code Example

// coming soon
usbStatus USBH_MSC_Write ( int8_t  instance,
uint32_t  lba,
uint16_t  cnt,
const uint8_t *  buf 
)

Write requested number of blocks to Mass Storage Device.

Parameters
[in]instanceinstance of MSC Device.
[in]lbalogical address of first block to write.
[in]cntnumber of contiguous blocks to write.
[in]bufdata buffer containing data to write.
Returns
status code that indicates the execution status of the function as defined with usbStatus.

The function USBH_MSC_Write writes data to a mass storage device.

The argument instance is specifying the device instance.

The argument lba is the address of the starting block to be written.

The argument cnt is a value indicating the number of blocks to be written.

The argument buf is pointing to the location where the data will be written.

Code Example

// coming soon