Skip to end of metadata
Go to start of metadata

MSC Class Ramdisk LUN Example

This example creates a simple MSC function with a single Logical Unit using a RAM disk as a storage medium. It requires the presence of Micrium OS FS in your project, and assumes that the Block Device module is initialized.

This example will allow you to accomplish the following tasks:

  • Create a RAM disk media named "ramusb"
  • Initialize the MSC class
  • Create a MSC class instance
  • Add a logical unit to the MSC class instance
  • Add the MSC class instance to the Full-Speed configuration
  • Add the MSC class instance to the High-Speed configuration (if available)
  • Attach the "ramusb" storage media to the logical unit

Location

The example implementation is located in /examples/usb/device/all/ex_usbd_msc_ramdisk_lun.c.

Running the Demo Application

Once you connect the device to a Windows host PC (and once the drivers are installed), you should see a new drive available that represents your USB flash drive. Since it uses a RAM disk, you will have to format the drive each time the target is power cycled.

You can then create files/folders, read them, etc.

API

This example offers only one API named Ex_USBD_MSC_Init(). This function is normally called from a USB device core example.

MSC Class Ramdisk Shared Example

This example creates a simple MSC function with a single Logical Unit using a RAM disk as a storage medium. Its purpose is to demonstrate how a storage media can be shared between a USB host and your embedded application. It requires the presence of Micrium OS FS in your project and assumes that the Block Device module is initialized.

This example will allow you to accomplish the following tasks:

  • Create and configure a RAMDisk media named "ramusb"
  • Initialize the MSC class
  • Create a MSC class instance
  • Add a logical unit to the MSC class instance
  • Add the MSC class instance to the Full-Speed configuration
  • Add the MSC class instance to the High-Speed configuration (if available)
  • Create a kernel task that will handle the application that shares the media with the host.

Location

The example implementation is located in /examples/usb/device/all/ex_usbd_msc_ramdisk_shared.c.

Running the Demo Application

This application is executed within the task body implemented in the function Ex_USBD_MSC_Task(). Within a loop, the application executes the following steps:

  • Open the volume present on the RAM disk storage device using the Micrium OS FS API
  • Create/Open a file named "Embedded.txt"
  • Add the string "Iteration number <X>" to the file content (where <X> represents the number of the iteration)
  • Close the file, volume and device
  • Attach the RAM disk device to the MSC class instance logical unit. From this point, the media is visible from the host side
  • Wait five seconds
  • Detach the RAM disk device from the MSC class instance logical unit. From this point, the media appears as unavailable from the host side

The loop executes for 10 iterations. After the 10 iterations, the RAMDisk device remains attached to the logical unit.

API

This example offers only one API named Ex_USBD_MSC_Init(). This function is normally called from a USB device core example.