USB Component
Version 6.6
MDK-Professional Middleware for USB Device and Host
|
User API reference of the Mass Storage Class. More...
Functions | |
void | USBD_MSCn_Initialize (void) |
Called during USBD_Initialize to initialize the USB MSC class instance. | |
void | USBD_MSCn_Uninitialize (void) |
Called during USBD_Uninitialize to de-initialize the USB MSC class instance. | |
bool | USBD_MSCn_GetCacheInfo (uint32_t *buffer, uint32_t *size) |
Get cache information. | |
bool | USBD_MSCn_GetMediaCapacity (uint32_t *block_count, uint32_t *block_size) |
Get media capacity. | |
bool | USBD_MSCn_Read (uint32_t lba, uint32_t cnt, uint8_t *buf) |
Read data from media. | |
bool | USBD_MSCn_Write (uint32_t lba, uint32_t cnt, const uint8_t *buf) |
Write data to media. | |
uint32_t | USBD_MSCn_CheckMedia (void) |
Check media presence and write protect status. | |
int32_t | USBD_MSCn_SetMediaOwnerUSB (void) |
Set USB as media owner. | |
int32_t | USBD_MSCn_SetMediaOwnerFS (void) |
Set File System as media owner. | |
User API reference of the Mass Storage Class.
uint32_t USBD_MSCn_CheckMedia | ( | void | ) |
Check media presence and write protect status.
The function USBD_MSCn_CheckMedia is called automatically upon specific USB Host requests (like Test Unit Ready) to check if media is ready for read/write operations. It needs no invocation in the user code. If media check is not available in hardware this function can be omitted.
Modify this function to the application's needs.
Code Example
bool USBD_MSCn_GetCacheInfo | ( | uint32_t * | buffer, |
uint32_t * | size | ||
) |
Get cache information.
[out] | buffer | cache buffer address. |
[out] | size | cache buffer size. |
The function USBD_MSCn_GetCacheInfo enables an MSC device to reuse RAM used by the File System for caching purposes as USB cache. This is required when a USB Host has control over the media so that it cannot be accessed by File System.
The argument buffer returns the cache buffer address, while the argument size returns the size of the cache buffer.
Code Example
bool USBD_MSCn_GetMediaCapacity | ( | uint32_t * | block_count, |
uint32_t * | block_size | ||
) |
Get media capacity.
[out] | block_count | total number of blocks on media. |
[out] | block_size | media block size. |
The function USBD_MSCn_GetMediaCapacity can be used to determine the geometry of the attached storage media.
The argument block_count returns the total number of blocks on the media, while the argument block_size returns the block size of the media.
Code Example
void USBD_MSCn_Initialize | ( | void | ) |
Called during USBD_Initialize to initialize the USB MSC class instance.
The function USBD_MSCn_Initialize is called automatically upon initialization of a Mass Storage Class Device and needs no invocation in the user code.
Modify this function to the application's needs to allocate resources and initialize additional peripherals.
Code Example
bool USBD_MSCn_Read | ( | uint32_t | lba, |
uint32_t | cnt, | ||
uint8_t * | buf | ||
) |
Read data from media.
[in] | lba | logical address of first block to read. |
[in] | cnt | number of contiguous blocks to read from media. |
[out] | buf | data buffer for data read from media. |
The function USBD_MSCn_Read reads the data that should be returned to the USB Host that requested it.
The argument lba specifies the logical address of the first block that is to be read.
The argument cnt specifies the number of contiguous blocks to be read from the media.
The argument buf is pointing to the buffer where the read data should be stored.
Modify this function to the application's needs.
Code Example
int32_t USBD_MSCn_SetMediaOwnerFS | ( | void | ) |
Set File System as media owner.
The function USBD_MSCn_SetMediaOwnerFS sets the File System Component to the media owner of the attached media (drive). This will make the media unavailable to the USB Bus. Use USBD_MSCn_SetMediaOwnerUSB to enable ownership of the media for the USB Bus.
Code Example
This function can be modified in the user code template file USBD_MSC_n.c.
int32_t USBD_MSCn_SetMediaOwnerUSB | ( | void | ) |
Set USB as media owner.
The function USBD_MSCn_SetMediaOwnerUSB sets the USB Bus to the media owner of the attached media (drive). This will make the media unavailable to the File System Component. Use USBD_MSCn_SetMediaOwnerFS to enable ownership of the media for the File System Component.
Code Example
This function can be modified in the user code template file USBD_MSC_n.c.
void USBD_MSCn_Uninitialize | ( | void | ) |
Called during USBD_Uninitialize to de-initialize the USB MSC class instance.
The function USBD_MSCn_Uninitialize is called automatically upon de-initialization of a Mass Storage Class Device and needs no invocation in the user code. If USBD_MSCn_Initialize has been adapted to the application, USBD_MSCn_Uninitialize should release resources and should de-initialize peripherals.
Code Example
bool USBD_MSCn_Write | ( | uint32_t | lba, |
uint32_t | cnt, | ||
const uint8_t * | buf | ||
) |
Write data to media.
[in] | lba | logical address of first block to write. |
[in] | cnt | number of contiguous blocks to write to media. |
[out] | buf | data buffer containing data to write to media. |
The function USBD_MSCn_Write writes data received from the USB Host.
The argument lba specifies the logical address of the first block that is to be written.
The argument cnt specifies the number of contiguous blocks to be written to the media.
The argument buf is pointing to the buffer containing the data to be written.
Modify this function to the application's needs.
Code Example