![]() |
USB Component
Version 5.0
MDK-Professional Middleware for USB Device and Host
|
Implement application specific behaviour of a Mass Storage Class (MSC) Device. More...
Functions | |
void | USBD_MSCn_Initialize (void) |
Called during USBD_Initialize to initialize the USB MSC class Device. | |
void | USBD_MSCn_Uninitialize (void) |
Called during USBD_Uninitialize to un-initialize the USB MSC class Device. | |
bool | USBD_MSCn_Read (uint32_t lba, uint16_t cnt, uint8_t *buf) |
Read data from media. | |
bool | USBD_MSCn_Write (uint32_t lba, uint16_t cnt, const uint8_t *buf) |
Write data to media. | |
Implement application specific behaviour of a Mass Storage Class (MSC) Device.
The MSC class in the USB Component is used for data storage.
Refer to:
The USB Component allows multiple instances of the MSC class. Each MSC class instance has a separate files and interface functions:
This documentation uses n as a placeholder for the instance number 0 - 3. Most applications only require one instance of a MSC class. For the first MSC class instance the instance number is 0:
To create an USB Device with a MSC class:
Configuration File USBD_Config_MSC_n.h
The configuration file USBD_Config_MSC_n.h defines:
These settings are used to create the Interface Descriptor and Endpoint Descriptor of the related USB Device Class. It is important that the settings match the application specific behaviour in the related C source file USBD_User_MSC_n.c.
Software Structure
The handling for the MSC class endpoint events is implemented in USBD_MSC_Thread which is started by USBD_Initialize. Each instance of a MSC class runs an instance of USBD_MSC_Thread which calls the data functions USBD_MSCn_Read and USBD_MSCn_Write.
The following source code is part of the user code template file. The application specific behaviour may be implemented using this code template.
void USBD_MSCn_Initialize | ( | void | ) |
Called during USBD_Initialize to initialize the USB MSC class Device.
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, |
uint16_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. Modify this function to the application's needs.
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.
Code Example
void USBD_MSCn_Uninitialize | ( | void | ) |
Called during USBD_Uninitialize to un-initialize the USB MSC class Device.
The function USBD_MSCn_Uninitialize is called automatically upon un-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, |
uint16_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. Modify this function to the application's needs.
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.
Code Example