December 2012 Doc ID 13465 Rev 12 1/85
UM0424
User manual
STM32 USB-FS-Device development kit
Introduction
The STM32 USB-FS-Device development kit is a complete firmware and software package
including examples and demos for all USB transfer types (control, interrupt, bulk and
isochronous).
The aim of the STM32 USB-FS-Device development kit is to use the STM32 USB-FS-
Device library with at least one firmware demo per USB transfer type.
This document presents a description of all the components of the STM32 USB-FS-Device
development kit, including:
■ STM32 USB-FS-Device library: All processes related to default endpoint and standard
requests
■ Device firmware upgrade (DFU) demo: Control transfer
■ Joystick mouse demo: Interrupt transfer
■ Custom HID demo: Interrupt transfer
■ Mass storage demo: Bulk transfer
■ Virtual COM port: Interrupt and bulk transfer
■ CDC LoopBack demo: Interrupt and bulk transfer
■ Composite Example: Interrupt and bulk transfer
■ USB voice speaker demo (USB speaker): Isochronous transfer
Note: Starting from this release, STM32F105/F107 are no longer supported. These devices are
supported by the STM32 USB OTG Host and Device Library. For more details, please refer
to user manual UM1021.
Table 1. Applicable products
Type Part numbers or product categories
Microcontrollers
STM32F102xx and STM32F103xx series
STM32 L1 Ultra Low Power
STM32 F3 Series
www.st.com
Contents UM0424
2/85 Doc ID 13465 Rev 12
Contents
1 Related documents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2 STM32 microcontroller family overview . . . . . . . . . . . . . . . . . . . . . . . . . 9
3 STM32 USB-FS-Device firmware library . . . . . . . . . . . . . . . . . . . . . . . . 10
3.1 USB application hierarchy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
3.2 USB-FS_Device peripheral interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
3.2.1 usb_reg(.h, .c) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
3.2.2 usb_int (.h , .c) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3.2.3 usb_mem (.h , .c) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3.3 USB-FS-Device_Driver medium layer . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3.3.1 usb_init(.h,.c) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3.3.2 usb_core (.h , .c) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3.3.3 usb_sil(.h, .c) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
3.3.4 usb_type.h / usb_def.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
3.3.5 platform_config.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
3.4 Application interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
3.4.1 usb_conf(.h) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
3.4.2 usb_desc (.h, .c) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
3.4.3 usb_prop (.h , .c) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
3.4.4 usb_endp (.c) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
3.4.5 usb_istr(.c) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
3.4.6 usb_pwr (.h , .c) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
3.5 Implementing a USB-FS_Device application using the STM32 USB-FS-
Device library 25
3.5.1 Implementing a no-data class-specific request . . . . . . . . . . . . . . . . . . . 25
3.5.2 How to implement a data class-specific request . . . . . . . . . . . . . . . . . . 25
3.5.3 How to manage data transfers in non-control endpoint . . . . . . . . . . . . . 26
4 Joystick mouse demo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
4.1 General description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
4.2 STM32 low-power management in suspend mode . . . . . . . . . . . . . . . . . 27
4.3 Remote wakeup implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
UM0424 Contents
Doc ID 13465 Rev 12 3/85
5 Custom HID demo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
5.1 General description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
5.2 Descriptor topology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
5.3 Custom HID implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
5.3.1 LED control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
5.3.2 Push-button state report . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
5.3.3 ADC-converted data transfer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
6 Mass storage demo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
6.1 General description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
6.2 Mass storage demo overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
6.3 Mass storage protocol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
6.3.1 Bulk-only transfer (BOT) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
6.3.2 Small computer system interface (SCSI) . . . . . . . . . . . . . . . . . . . . . . . . 38
6.4 Mass storage demo implementations . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
6.4.1 Hardware configuration interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
6.4.2 Endpoint configurations and data management . . . . . . . . . . . . . . . . . . 40
6.4.3 Class-specific requests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
6.4.4 Standard request requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
6.4.5 BOT state machine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
6.4.6 SCSI protocol implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
6.4.7 Memory management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
6.4.8 Medium access management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
6.5 How to customize the mass storage demo . . . . . . . . . . . . . . . . . . . . . . . 46
7 Virtual COM port demo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
7.1 General description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
7.2 Virtual COM port demo proposal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
7.3 Software driver installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
7.4 Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
7.4.1 Hardware implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
7.4.2 Firmware implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
8 VirtualComport_Loopback . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
8.1 General description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
8.2 Demo overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
Contents UM0424
4/85 Doc ID 13465 Rev 12
8.3 Transferring data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
8.3.1 Sending data from device to host . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
8.3.2 Receiving data from host to device . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
8.4 Running the demo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
9 USB voice speaker demo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
9.1 General description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
9.2 Isochronous transfer overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
9.3 Audio device class overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
9.4 STM32 USB audio speaker demo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
9.4.1 General characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
9.4.2 Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
10 Device firmware upgrade . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
10.1 General description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
10.2 DFU extension protocol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
10.2.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
10.2.2 Phases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
10.2.3 Requests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
10.3 DFU mode selection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
10.3.1 Run-time descriptor set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
10.3.2 DFU mode descriptor set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
10.4 Reconfiguration phase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
10.5 Transfer phase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
10.5.1 Requests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
10.5.2 Special command/protocol descriptions . . . . . . . . . . . . . . . . . . . . . . . . 75
10.5.3 DFU state diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
10.5.4 Downloading and uploading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
10.5.5 Manifestation phase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
10.6 STM32 DFU implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
10.6.1 Supported memories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
10.6.2 DFU mode entry mechanism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
10.6.3 DFU firmware architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
10.6.4 Available DFU image for the STM32 . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
10.6.5 Creating a DFU image . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
UM0424 Contents
Doc ID 13465 Rev 12 5/85
11 Composite example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
11.1 General description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
11.2 Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
11.3 USB device descriptor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
11.4 Running the demo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
12 Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83