没有合适的资源?快使用搜索试试~ 我知道了~
STM32F2xx USB OTG host and device library学习资料.pdf
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 198 浏览量
2023-06-06
20:51:49
上传
评论
收藏 1.55MB PDF 举报
温馨提示
试读
107页
STM32F2xx USB OTG host and device library学习资料.pdf
资源推荐
资源详情
资源评论
August 2011 Doc ID 18153 Rev 2 1/107
UM1021
User manual
STM32F105/7 and STM32F2xx
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
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 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 2
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 . . . . . . . . . . . . 16
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 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
6.3.5 USB data transfer handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
6.3.6 Using the multi-packet feature . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
UM1021 Contents
Doc ID 18153 Rev 2 3/107
6.3.7 USB control functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
6.3.8 FIFO size customization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
6.4 USB device library functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
6.5 USB device class interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
6.6 USB device user interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
6.7 USB device classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
6.7.1 HID class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
6.7.2 Mass storage class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
6.7.3 Device firmware upgrade (DFU) class . . . . . . . . . . . . . . . . . . . . . . . . . . 43
6.7.4 Audio class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
6.7.5 Communication device class (CDC) . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
6.7.6 Adding a custom class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
6.8 Application layer description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
6.9 Starting the USB device library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
6.10 USB device examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
6.10.1 USB mass storage device example . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
6.10.2 USB human interface device example . . . . . . . . . . . . . . . . . . . . . . . . . . 63
6.10.3 Dual core USB device example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
6.10.4 USB device firmware upgrade example . . . . . . . . . . . . . . . . . . . . . . . . . 66
6.10.5 USB virtual com port (VCP) device example . . . . . . . . . . . . . . . . . . . . . 68
6.10.6 USB audio device example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
6.10.7 Known limitations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
7 USB host library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
7.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
7.2 USB host library files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
7.3 USB host library description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
7.3.1 Host core state machine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
7.3.2 Device enumeration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
7.3.3 Control transfer state machine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
7.3.4 USB I/O request module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
7.3.5 Host channel control module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
7.3.6 USB host library configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
7.4 USB host library functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
7.5 USB host class interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
7.6 USB host classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
Contents UM1021
4/107 Doc ID 18153 Rev 2
7.6.1 Mass storage class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
7.6.2 HID class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
7.7 USB host user interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
7.7.1 Library user API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
7.7.2 User callback functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
7.7.3 Class callback functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
7.8 Application layer description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
7.9 Starting the USB host library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
7.10 USB host examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
7.10.1 USB mass storage host example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
7.10.2 USB HID Host example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
7.10.3 USB dual core host example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
7.10.4 USB manual dual role device example . . . . . . . . . . . . . . . . . . . . . . . . . 98
8 Frequently-asked questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
9 Troubleshooting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
Appendix A USB hardware connectivity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
10 Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
UM1021 List of tables
Doc ID 18153 Rev 2 5/107
List of tables
Table 1. List of terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Table 2. USB OTG low level file descriptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Table 3. Core configurations. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Table 4. Standard requests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Table 5. USB device core files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
Table 6. usbd_core (.c, .h) files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
Table 7. usbd_ioreq (.c, .h) files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
Table 8. usbd_req (.c, .h). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
Table 9. USB device class files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
Table 10. usbd_hid_core.c,h files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
Table 11. SCSI commands. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Table 12. usbd_msc_core (.c, .h) files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
Table 13. usbd_msc_bot (.c, .h) files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
Table 14. usbd_msc_scsi (.c, .h) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
Table 15. Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Table 16. DFU states . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
Table 17. Supported requests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
Table 18. usbd_dfu_core (.c, .h) files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
Table 19. usbd_dfu_mal (.c, .h) files. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
Table 20. usbd_flash_if (.c,.h) files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
Table 21. Audio control requests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
Table 22. usbd_audio_core (.c, .h) files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
Table 23. usbd_audio_xxx_if (.c, .h) files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
Table 24. Audio player states . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
Table 25. usbd_cdc_core (.c, .h) files. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
Table 26. Configurable CDC parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
Table 27. usbd_cdc_xxx_if (.c, .h) files. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
Table 28. Variables used by usbd_cdc_xxx_if.c/.h. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
Table 29. USB host core files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
Table 30. USB I/O request module. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
Table 31. Host channel control module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
Table 32. Standard request module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
Table 33. Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
Table 34. MSC core module description. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
Table 35. MSC BOT module description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
Table 36. MSC SCSI commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
Table 37. MSC file system interface functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
Table 38. FatFS API commands. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
Table 39. HID class modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
Table 40. MSC core module functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
Table 41. Mouse and keyboard initialization & HID report decoding functions. . . . . . . . . . . . . . . . . . 85
Table 42. Document revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
剩余106页未读,继续阅读
资源评论
oligaga
- 粉丝: 50
- 资源: 2万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功