USB composite device example program, drag-and-drop flash writer.

Dependencies:   SWD USBDevice mbed BaseDAP

Embed: (wiki syntax)

« Back to documentation index

USB_MSD Class Reference

USB_MSD Class Reference

USBMSD2 class: generic class in order to use all kinds of blocks storage chip. More...

#include <USB_MSD.h>

Public Member Functions

bool connect ()
 Connect the USB MSD device.
void disconnect ()
 Disconnect the USB MSD device.
 ~USB_MSD ()
 Destructor.

Detailed Description

USBMSD2 class: generic class in order to use all kinds of blocks storage chip.

Introduction

The USBMSD implements the MSD protocol. It permits to access a memory chip (flash, sdcard,...) from a computer over USB. But this class doesn't work standalone, you need to subclass this class and define virtual functions which are called in USBMSD.

How to use this class with your chip ?

You have to inherit and define some pure virtual functions (mandatory step):

  • virtual int disk_read(char * data, int block): function to read a block
  • virtual int disk_write(const char * data, int block): function to write a block
  • virtual int disk_initialize(): function to initialize the memory
  • virtual int disk_sectors(): return the number of blocks
  • virtual int disk_size(): return the memory size
  • virtual int disk_status(): return the status of the storage chip (0: OK, 1: not initialized, 2: no medium in the drive, 4: write protection)

All functions names are compatible with the fat filesystem library. So you can imagine using your own class with USBMSD and the fat filesystem library in the same program. Just be careful because there are two different parts which will access the sd card. You can do a master/slave system using the disk_status method.

Once these functions defined, you can call connect() (at the end of the constructor of your class for instance) of USBMSD to connect your mass storage device. connect() will first call disk_status() to test the status of the disk. If disk_status() returns 1 (disk not initialized), then disk_initialize() is called. After this step, connect() will collect information such as the number of blocks and the memory size.

Definition at line 54 of file USB_MSD.h.


Constructor & Destructor Documentation

~USB_MSD (  )

Destructor.


Member Function Documentation

bool connect (  )

Connect the USB MSD device.

Establish disk initialization before really connect the device.

Returns:
true if successful

Definition at line 73 of file USB_MSD.cpp.

void disconnect (  )

Disconnect the USB MSD device.

Definition at line 102 of file USB_MSD.cpp.