March 2012 Doc ID 18153 Rev 3 1/107
UM1021
User manual
STM32F105xx, STM32F107xx, STM32F2xx and STM32F4xx USB
On-The-Go host and device library
Introduction
The USB On-The-Go Host and Device Library is a firmware and application software
package for USB (universal serial bus) hosts and devices. This package includes example
and demonstration software for developing applications using USB full speed and high
speed transfer types (control, interrupt, bulk and isochronous).
The aim of the USB OTG Host and Device Library is to provide at least one firmware
example demonstration for each USB transfer type. This library is designed for use with the
following evaluation boards:
STM3210C-EVAL evaluation board (UM0600) for STM32F105/7 devices
STM3220G-EVAL evaluation board (UM1057) for STM32F20x devices
STM3221G-EVAL evaluation board (UM1065) for STM32F21x devices
STM3240G-EVAL evaluation board (UM1461) for STM32F40x devices
STM3241G-EVAL evaluation board (UM1460) for STM32F41x devices
This document describes all the components of a USB OTG host and device library,
including examples for the following types of devices:
Mass storage, based on the microSD card available on the evaluation boards
HID joystick, based on the embedded joystick on the evaluation boards
Virtual COM port
Direct Firmware Update-based
Audio (OUT)
Dual Core, based on mass storage and HID examples (available only for
STM322xG-EVAL and STM324xG-EVAL evaluation boards)
And the following examples for hosts:
Mass storage, using file explorer, write files and slide show
HID, dynamic support for mice and keyboards
Dual core, for mass storage on the high speed port and HID (keyboards or mice) on the
full speed port
The package also includes an example of a manual dual role device that enables the core to
switch between host and device modes depending on user input.
www.st.com
Contents UM1021
2/107 Doc ID 18153 Rev 3
Contents
1 Reference information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.1 Glossary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2 USB host and device library overview . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.1 Main features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3 USB host and device library folder structure . . . . . . . . . . . . . . . . . . . . 10
4 USB OTG core . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
4.1 USB OTG full speed core . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
4.1.1 OTG_FS interface main features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
4.2 USB OTG high speed core . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
5 USB OTG low level driver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
5.1 USB OTG low level driver architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
5.2 USB OTG low level driver files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
5.3 USB OTG low level driver configuration . . . . . . . . . . . . . . . . . . . . . . . . . . 14
5.4 USB OTG driver programming manual . . . . . . . . . . . . . . . . . . . . . . . . . . 15
5.4.1 Low level driver structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
5.4.2 Programming considerations when using internal DMA . . . . . . . . . . . . 15
5.4.3 Selecting USB physical interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
5.4.4 Programming device drivers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
5.4.5 Programming host drivers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
6 USB device library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
6.1 USB device library overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
6.2 USB device library files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
6.3 USB device library description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
6.3.1 USB device library flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
6.3.2 USB device library process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
6.3.3 USB device data flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
6.3.4 USB device library configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
6.3.5 USB data transfer handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
6.3.6 Using the multi-packet feature . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30