USB Component  Version 6.13.6
MDK Middleware for USB Device and Host Communication
 All Data Structures Functions Variables Enumerations Enumerator Groups Pages

User API reference of the Mass Storage Class. More...

Functions

void USBH_MSC_Initialize (uint8_t instance)
 Callback function called when Mass Storage Device was enumerated and is ready. More...
 
void USBH_MSC_Uninitialize (uint8_t instance)
 Callback function called when Mass Storage Device was disconnected. More...
 
uint8_t USBH_MSC_GetDevice (uint8_t instance)
 Get Device instance of Mass Storage Device. More...
 
usbStatus USBH_MSC_GetStatus (uint8_t instance)
 Get status of Mass Storage Device. More...
 
usbStatus USBH_MSC_Read (uint8_t instance, uint32_t lba, uint32_t cnt, uint8_t *buf)
 Read requested number of blocks from Mass Storage Device. More...
 
usbStatus USBH_MSC_Write (uint8_t instance, uint32_t lba, uint32_t cnt, const uint8_t *buf)
 Write requested number of blocks to Mass Storage Device. More...
 
usbStatus USBH_MSC_ReadCapacity (uint8_t instance, uint32_t *block_count, uint32_t *block_size)
 Read capacity of Mass Storage Device. More...
 

Description

User API reference of the Mass Storage Class.

Function Documentation

uint8_t USBH_MSC_GetDevice ( uint8_t  instance)

Get Device instance of Mass Storage Device.

Parameters
[in]instanceinstance of MSC Device.
Returns
instance of Device or non-existing Device instance :
  • value <= 127 : instance of Device
  • value 255 : non-existing Device instance

The function USBH_MSC_GetDevice is used to retrieve device instance that is used to handle mass storage device instance.

The argument instance specifies the MSC device instance.

usbStatus USBH_MSC_GetStatus ( uint8_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_GetStatus checks if a mass storage device is connected and initialized.

The argument instance specifies the MSC device instance.

Code Example

int32_t USBH_MSC_DriveGetMediaStatus (const char *drive_name) {
usbStatus ustatus;
uint8_t drive_num;
drive_num = drive_name[1] - '0'; // get drive number from drive name
ustatus = USBH_MSC_GetStatus (drive_num);
if (ustatus != usbOK) return USBH_MSC_ERROR_DRIVE;
return USBH_MSC_OK;
}
void USBH_MSC_Initialize ( uint8_t  instance)

Callback function called when Mass Storage Device was enumerated and is ready.

Parameters
[in]instanceinstance of MSC Device.
Returns
none.

The function USBH_MSC_Initialize is called when a mass storage device was connected and successfully enumerated and is ready for communication.

The argument instance specifies the MSC device instance.

usbStatus USBH_MSC_Read ( uint8_t  instance,
uint32_t  lba,
uint32_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 physical memory blocks of a mass storage device.

The argument instance specifies the MSC device instance.

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

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

The argument buf is a pointer to the location where the data will be stored. It is recommended that buffer is 4-byte aligned as some drivers might not support 1-byte alignment if DMA is used.

Note
This function is typically used by the File System Component to provide file I/O access.

Code Example

unsigned char buf[0x10000];
usbStatus ustatus;
ustatus = USBH_MSC_Read (0, 10, 1, buf);
if (ustatus == usbOK) {
// data successfully written
}
usbStatus USBH_MSC_ReadCapacity ( uint8_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 gets information about the capacity of a mass storage device.

The argument instance specifies the MSC device instance.

The argument block_count is a pointer to a variable that stores the total number of available blocks.

The argument block_size is a pointer to a variable that stores the block size (in bytes).

Code Example

uint64_t USBH_MSC_DriveGetCapacity (const char *drive_name) {
usbStatus ustatus;
uint32_t block_count;
uint32_t block_size;
uint8_t drive_num;
drive_num = drive_name[1] - '0'; // get drive number from drive name
ustatus = USBH_MSC_GetStatus (drive_num);
if (ustatus != usbOK) return 0;
ustatus = USBH_MSC_ReadCapacity (drive_num, &block_count, &block_size);
if (ustatus != usbOK) return 0;
return (((uint64_t)block_count) * ((uint64_t)block_size));
}
void USBH_MSC_Uninitialize ( uint8_t  instance)

Callback function called when Mass Storage Device was disconnected.

Parameters
[in]instanceinstance of MSC Device.
Returns
none.

The function USBH_MSC_Unitialize is called when a mass storage device was disconnected form the USB Bus.

The argument instance specifies the MSC device instance.

usbStatus USBH_MSC_Write ( uint8_t  instance,
uint32_t  lba,
uint32_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 physical memory blocks of the mass storage device.

The argument instance specifies the MSC device instance.

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

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

The argument buf is a pointer to the location that contains the data to be written. It is recommended that buffer is 4-byte aligned as some drivers might not support 1-byte alignment if DMA is used.

Note
This function is typically used by the File System Component to provide file I/O access.

Code Example

unsigned char buf[0x10000];
usbStatus ustatus;
memset (buf, 0x55, sizeof (buf));
ustatus = USBH_MSC_Write (0, 10, 1, buf);
if (ustatus == usbOK) {
// data successfully written
}