![]() |
USB Component
Version 6.10.0
MDK Middleware for USB Device and Host Communication
|
Implement application specific behavior of a Mass Storage Class (MSC) USB Device. More...
Content | |
User API | |
User API reference of the Mass Storage Class. | |
Configuration | |
Configuration of the USB Device MSC Class in µVision. | |
Implement application specific behavior of a Mass Storage Class (MSC) USB 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:
Software Structure
The handling for the MSC class endpoint events is implemented in USBD_MSCn_Thread which is started by USBD_Initialize. Each instance of a MSC class runs an instance of USBD_MSCn_Thread which calls the data functions USBD_MSCn_Read and USBD_MSCn_Write.
To create an USB Device with a MSC class:
Media Ownership
Sometimes, it is required to implement the ownership control over attached media and changing the ownership between USB and File System. This is required if you have a device that connects to a PC as a USB MSC device while the storage media also needs to be accessible to a user application. Using the two functions USBD_MSCn_SetMediaOwnerUSB and USBD_MSCn_SetMediaOwnerFS you can change the owner of the media to either the USB (the host PC) or the File System (the user application). The user code template USBD_MSC.c provides means to manage the ownership.
The following picture shows the connection of the device to the PC and the user application running on the device:
In the file USBD_MSC.c the variable usbd_msc0_media_own
is used to set the ownership of the media device to the application or the File System. In the file USBD_User_MSC.c the variable is used to initialize it at the beginning of the application (in the USBD_MSCn_Initialize function) and to check the ownership of the media (in the USBD_MSCn_CheckMedia function). The application then only makes use of the two functions USBD_MSCn_SetMediaOwnerUSB and USBD_MSCn_SetMediaOwnerFS as explained in this code example.
User Code Templates
There are two user code templates available that help to add support for a MSC device:
User Code Template USBD_User_MSC.c
The following source code can be used to implement the application specific behavior of a USB MSC Device.
User Code Template USBD_MSC_n.c
The following source code can be used to implement ownership control for attached media devices.
This code snippet shows how to use the two functions in a user application: