USBDevice stack architecture

The aim of this webpage is to explain the architecture of the USB Device stack.

Compatibility

Note that the same stack is available for both the mbed LPC11U24 and the mbed LPC1768.

Architecture diagram

USBDevice Stack Architecture

Description of each layer

  • USBHAL: The USB hardware layer for the LPC11U24 and for the LPC1768. In this class, all low level methods are defined:
    • The constructor to initialize the USB Device controller
    • The USB IRQ handler: when an event occurs on a certain endpoint, a virtual function is called so that all child class can perform their own treatment
    • Add a certain endpoint
    • Read or write a certain endpoint
  • USBDevice: This layer is in charge to abstract the hardware. Starting from this layer, no difference is made between the LPC11U24 and the LPC1768. Moreover, different methods are available:
    • init() to initialize the USB controller
    • connect() to connect a device
    • disconnect() to disconnect a device
    • addEndpoint to add a specific endpoint
    • readEP to read a specific endpoint
    • writeEP to write a specific endpoint

      It's also in this class that the enumeration step is performed for requests concerning standard descriptors. When a packet is received on the control endpoint (endpoint 0 OUT), it is decoded and analyzed. A response is then sent to the host. Descriptors are accessible via virtual functions such as getDeviceDesc() which returns a pointer on the descriptor. As these functions are virtual, all child classes are able to define their own descriptors.
  • USB class layer: If the host sends a class specific request, all classes can handle it by redefining the virtual function USBCallback_request()
    • USBHID: implements standard requests of the HID class specification. When you instantiate a USBHID object, the mbed is enumerated as a generic HID device so that you can send and receive raw data to and from a custom program running on the host side.
    • USBCDC: implements a subset of the CDC class specification to allow the mbed to be recognized as a virtual serial port
    • USBMIDI: enables the mbed to send and receive MIDI message to and from a computer
    • USBAudio: implements standard requests of the USBAudio class
    • USBMSD: implements the mass storage protocol. Calls pure virtual functions to access all kinds of block memory chips:
      • 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)
  • Device class layer:
    • USBMouse: used to emulate a mouse
    • USBKeyboard: used to emulate a keyboard. This class also inherits from Stream which means that methods such as printf, puts, putc are available.
    • USBMouseKeyboard: used to emulate a mouse and a keyboard at the same time
    • USBSerial: used to emulate a virtual serial port. This class also inherits from Stream which means that methods such as printf, scanf, puts, putc, gets and getc are available.
    • USBMSD_SD: example of mass storage device using an SD card
    • USBMSD_??: All users can implement their own class which inherits from USBMSD in order to access their storage chip.

More information

If you just want an overview of all the capabilities of the USBDevice stack, visit the USBDevice capabilities webpage.

More specific information of each devices are available in the handbook. There are descriptions and program examples for each USB device:

The USBDevice library is available here.


Please log in to post comments.