Skip to content

Commit fafc677

Browse files
committed
docs: update rst
Signed-off-by: sakumisu <[email protected]>
1 parent 734cacb commit fafc677

File tree

10 files changed

+73
-111
lines changed

10 files changed

+73
-111
lines changed

docs/source/api/api_device.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
- 有多少个接口就调用多少次 `usbd_add_interface`,参数填相关 `xxx_init_intf`, 如果没有支持的,手动创建一个 intf 填入
88
- 有多少个端点就调用多少次 `usbd_add_endpoint`,当中断完成时,会调用到注册的端点回调中。
99

10+
参考下面这张图:
11+
12+
.. figure:: img/api_device1.png
13+
1014
CORE
1115
-----------------
1216

docs/source/api/api_host.rst

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,11 @@ CLASS 驱动信息结构体
1515
.. code-block:: C
1616
1717
struct usbh_class_info {
18-
uint8_t match_flags; /* Used for product specific matches; range is inclusive */
19-
uint8_t class; /* Base device class code */
20-
uint8_t subclass; /* Sub-class, depends on base class. Eg. */
21-
uint8_t protocol; /* Protocol, depends on base class. Eg. */
22-
uint16_t vid; /* Vendor ID (for vendor/product specific devices) */
23-
uint16_t pid; /* Product ID (for vendor/product specific devices) */
18+
uint8_t match_flags; /* Used for product specific matches; range is inclusive */
19+
uint8_t bInterfaceClass; /* Base device class code */
20+
uint8_t bInterfaceSubClass; /* Sub-class, depends on base class. Eg. */
21+
uint8_t bInterfaceProtocol; /* Protocol, depends on base class. Eg. */
22+
const uint16_t (*id_table)[2]; /* List of Vendor/Product ID pairs */
2423
const struct usbh_class_driver *class_driver;
2524
};
2625
File renamed without changes.
66 KB
Loading
497 KB
Loading

docs/source/demo/usbd_adb.rst

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
usbd_adb
2+
===============
3+
4+
本节主要介绍如何使用 adb device。支持 **cherrysh** 和 rt-thread **msh**,只需要在 main 中添加以下初始化即可。
5+
6+
.. code-block:: C
7+
8+
cherryadb_init(0, xxxxx);
9+
10+
如果使用 rt-thread,还需要在 menuconfig 中使能 adb device。
11+
12+
.. figure:: img/rtt_adb_shell1.png
13+
14+
进入 adb
15+
--------------
16+
17+
- 使用 **cherrysh** 时枚举完成以后自动进入 adb 模式
18+
- 使用 **msh** 需要在 **msh** 中输入 ``adb_enter`` 进入 adb 模式
19+
20+
退出 adb
21+
--------------
22+
23+
- 使用 **cherrysh** 时输入 ``exit`` 退出 adb 模式
24+
- 使用 **msh** 需要在 **msh** 中输入 ``adb_exit`` 退出 adb 模式
25+
26+
.. figure:: img/cherryadb.png
27+
28+
.. figure:: img/rtt_adb_shell2.png

docs/source/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ CherryUSB 是一个小而美的、可移植性高的、用于嵌入式系统的
107107
demo/usbd_video
108108
demo/usbd_winusb
109109
demo/usbd_webusb
110+
demo/usbd_adb
110111
demo/usbh_serial
111112
demo/usbh_hid
112113
demo/usbh_msc

docs/source/quick_start/demo.rst

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ USB Device 移植要点
177177

178178
.. figure:: img/stm32_13.png
179179

180+
- 如果芯片带 cache,cache 修改参考 :ref:`usb_cache` 章节
181+
180182
- 调用 template 的内容初始化,并填入 `busid` 和 USB IP 的 `reg base`, `busid` 从 0 开始,不能超过 `CONFIG_USBDEV_MAX_BUS`
181183

182184
.. figure:: img/stm32_15.png
@@ -212,13 +214,10 @@ USB Host 移植要点
212214
213215
- 拷贝 **xxx_msp.c** 中的 `HAL_HCD_MspInit` 函数中的内容到 `usb_hc_low_level_init` 函数中,屏蔽 st 生成的 usb 初始化
214216
- 在中断函数中调用 `USBH_IRQHandler`,并传入 `busid`
217+
- 链接脚本修改参考 :ref:`usbh_link_script` 章节
218+
- 如果芯片带 cache,cache 修改参考 :ref:`usb_cache` 章节
215219
- 调用 `usbh_initialize` 并填入 `busid` 和 USB IP 的 `reg base`, `busid` 从 0 开始,不能超过 `CONFIG_USBHOST_MAX_BUS`
216220
- 启动线程
217221

218222
.. figure:: img/stm32_18.png
219223
.. figure:: img/stm32_19.png
220-
221-
- 如果使用 **msc**,并且带文件系统,需要自行添加文件系统文件了,对应的 porting 编写参考 **fatfs_usbh.c** 文件。
222-
223-
.. figure:: img/stm32_21.png
224-

docs/source/quick_start/rtthread.rst

Lines changed: 9 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -28,35 +28,19 @@
2828
#define CONFIG_USB_PRINTF(...) rt_kprintf(__VA_ARGS__)
2929
3030
* USB IP 相关的 config 需要用户自己根据芯片实际情况修改
31-
* 退出以后不急着编译,需要在代码中实现 `usb_dc_low_level_init` 函数。
31+
* 在代码中实现 `usb_dc_low_level_init` 函数
32+
* 在 USB 中断函数中调用 `USBD_IRQHandler`,并传入 `busid`
3233
* 调用 `usbd_initialize` 并填入 `busid` 和 USB IP 的 `reg base`, `busid` 从 0 开始,不能超过 `CONFIG_USBDEV_MAX_BUS`
33-
* 以上内容我们推荐放在 **board.c** 中,如下代码:
34-
35-
.. code-block:: C
36-
37-
void OTG_HS_IRQHandler(void)
38-
{
39-
extern void USBD_IRQHandler(uint8_t busid);
40-
USBD_IRQHandler(0);
41-
}
42-
43-
int usbd_init(void)
44-
{
45-
xxx_template_init(0, USB_OTG_HS_PERIPH_BASE);
46-
return 0;
47-
}
48-
49-
INIT_APP_EXPORT(usbd_init);
50-
5134
* 使用 `scons --target=mdk5` 或者 `scons` 进行编译,如果是mdk,需要使用 AC6 编译器
35+
* 如果芯片带 cache,cache 修改参考 :ref:`usb_cache` 章节
5236

5337
主机配置
5438
--------------------------
5539

56-
* 选择 Enable usb host mode 并敲回车进入
57-
* 选择 USB host ip,不清楚自己芯片是哪个 ip 的可以参考 **port** 目录下对应的 readme
40+
* 选择 Enable usb host mode 并敲回车进入
41+
* 选择 USB host ip,不清楚自己芯片是哪个 ip 的可以参考 **port** 目录下对应的 readme
5842
* 根据需要勾选 class 驱动
59-
* 选择是否开启模板 demo,请注意, msc 禁止使能,因为默认对接到 dfs。
43+
* 选择是否开启模板 demo,推荐不用
6044

6145
.. figure:: img/env2.png
6246

@@ -71,77 +55,8 @@
7155
7256
* USB IP 相关的 config 需要用户自己根据芯片实际情况修改
7357
* 在代码中实现 `usb_hc_low_level_init` 函数
58+
* 在 USB 中断函数中调用 `USBH_IRQHandler`,并传入 `busid`
7459
* 调用 `usbh_initialize` 并填入 `busid` 和 USB IP 的 `reg base`, `busid` 从 0 开始,不能超过 `CONFIG_USBHOST_MAX_BUS`
75-
* 以上内容我们推荐放在 **board.c** 中,如下代码:
76-
77-
.. code-block:: C
78-
79-
void OTG_HS_IRQHandler(void)
80-
{
81-
extern void USBH_IRQHandler(uint8_t busid);
82-
USBH_IRQHandler(0);
83-
}
84-
85-
int usbh_init(void)
86-
{
87-
usbh_initialize(0, USB_OTG_HS_PERIPH_BASE);
88-
return 0;
89-
}
90-
91-
INIT_APP_EXPORT(usbh_init);
92-
9360
* 使用 `scons --target=mdk5` 或者 `scons` 进行编译,如果是mdk,需要使用 AC6 编译器
94-
* 如果使用的是 GCC ,需要在链接脚本(需要放在 flash 位置)中添加如下代码:
95-
96-
.. code-block:: C
97-
98-
/* section information for usbh class */
99-
. = ALIGN(4);
100-
__usbh_class_info_start__ = .;
101-
KEEP(*(.usbh_class_info))
102-
__usbh_class_info_end__ = .;
103-
104-
105-
举例如下:
106-
107-
.. code-block:: C
108-
109-
/* The program code and other data into "FLASH" Rom type memory */
110-
.text :
111-
{
112-
. = ALIGN(4);
113-
*(.text) /* .text sections (code) */
114-
*(.text*) /* .text* sections (code) */
115-
*(.glue_7) /* glue arm to thumb code */
116-
*(.glue_7t) /* glue thumb to arm code */
117-
*(.eh_frame)
118-
119-
KEEP (*(.init))
120-
KEEP (*(.fini))
121-
. = ALIGN(4);
122-
__usbh_class_info_start__ = .;
123-
KEEP(*(.usbh_class_info))
124-
__usbh_class_info_end__ = .;
125-
. = ALIGN(4);
126-
_etext = .; /* define a global symbols at end of code */
127-
} > FLASH
128-
129-
借助 STM32CubeMX 生成 USB 初始化
130-
----------------------------------
131-
132-
使用 STM32CubeMX 主要是用来生成 usb 时钟、引脚、中断的配置。我们需要点击如图所示文件,并配置好 USB 的时钟、中断,点击 `Generate Code`。
133-
134-
.. figure:: img/stm32cubemx0.png
135-
.. figure:: img/stm32cubemx1.png
136-
.. figure:: img/stm32cubemx2.png
137-
.. figure:: img/stm32cubemx_clk.png
138-
139-
- 将 `main.c` 中的 `SystemClock_Config` 替换掉 `board.c` 中的配置
140-
141-
.. figure:: img/stm32_init2.png
142-
143-
.. note :: 下面步骤从 V1.5.0 开始不再需要,**fsdev/usb_glue_st.c**, **dwc2/usb_glue_st.c** 文件中已经实现
144-
145-
- 将 `stm32xxxx_hal_msp.c` 中的 `HAL_PCD_MspInit` 或者是 `HAL_HCD_MspInit` 中的内容复制到 `usb_dc_low_level_init` 和 `usb_hc_low_level_init` 函数中,举例如下:
146-
147-
.. figure:: img/stm32_init.png
61+
* 链接脚本修改参考 :ref:`usbh_link_script` 章节
62+
* 如果芯片带 cache,cache 修改参考 :ref:`usb_cache` 章节

docs/source/quick_start/transplant.rst

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ USB Device 移植要点
1212
- 描述符的注册、class的注册、接口的注册、端点中断的注册。不会的参考 demo 下的 template
1313
- 调用 `usbd_initialize` 并填入 `busid` 和 USB IP 的 `reg base`, `busid` 从 0 开始,不能超过 `CONFIG_USBDEV_MAX_BUS`
1414
- 在中断函数中调用 `USBD_IRQHandler`,并传入 `busid`, 如果你的 SDK 中中断入口已经存在 `USBD_IRQHandler` ,请更改 USB 协议栈中的名称
15+
- 如果芯片带 cache,cache 修改参考 :ref:`usb_cache` 章节
1516
- 编译使用。各个 class 如何使用,参考 demo 下的 template
1617

1718
USB Host 移植要点
@@ -22,7 +23,20 @@ USB Host 移植要点
2223
- 实现 `usb_hc_low_level_init` 函数(该函数主要负责 USB 时钟、引脚、中断的初始化)。该函数可以放在你想要放的任何参与编译的 c 文件中。如何进行 USB 的时钟、引脚、中断等初始化,请自行根据你使用的芯片原厂提供的源码中进行添加。
2324
- 调用 `usbh_initialize` 并填入 `busid` 和 USB IP 的 `reg base`, `busid` 从 0 开始,不能超过 `CONFIG_USBHOST_MAX_BUS`
2425
- 在中断函数中调用 `USBH_IRQHandler`,并传入 `busid`, 如果你的 SDK 中中断入口已经存在 `USBH_IRQHandler` ,请更改 USB 协议栈中的名称
25-
- 如果使用的是 GCC ,需要在链接脚本中添加如下代码(需要放在 flash 位置):
26+
- 链接脚本修改参考 :ref:`usbh_link_script` 章节
27+
- 如果芯片带 cache,cache 修改参考 :ref:`usb_cache` 章节
28+
- 编译使用。基础的 cdc + hid + msc 参考 `usb_host.c` 文件,其余参考 **platform** 目录下适配
29+
30+
.. _usbh_link_script:
31+
32+
主机链接脚本修改
33+
-----------------------
34+
35+
在使用主机时,如果没有修改链接脚本,会报 `__usbh_class_info_start__` 和 `__usbh_class_info_end__` 未定义的错误。因为主机协议栈需要在链接脚本中添加一个 section 来存储 class 信息。
36+
37+
- 如果使用的是 KEIL 无需修改
38+
39+
- 如果使用的是 GCC ,需要在链接脚本中添加如下代码(需要放在 flash 位置,建议放最后):
2640

2741
.. code-block:: C
2842
@@ -68,15 +82,17 @@ GCC 举例如下:
6882
place in AXI_SRAM { block cherryusb_usbh_class_info };
6983
keep { section .usbh_class_info};
7084
71-
- 编译使用。各个 class 如何使用,参考 demo 下的 `usb_host.c` 文件
7285
73-
带 cache 功能的芯片使用注意
86+
.. _usb_cache:
87+
88+
cache 配置修改
7489
-------------------------------
7590

76-
协议栈以及 port 中不会对 cache 区域的 ram 进行 clean 或者 invalid,所以需要使用一块非 cache 区域的 ram 来维护。 `USB_NOCACHE_RAM_SECTION` 宏表示将变量指定到非 cache ram上,
77-
因此,用户需要在对应的链接脚本中添加 no cache ram 的 section。默认 `USB_NOCACHE_RAM_SECTION` 定义为 `__attribute__((section(".noncacheable")))`。
91+
对于带 cache 的芯片,协议栈以及 port 中不会对 cache 区域的 ram 进行 clean 或者 invalid,所以需要使用一块非 cache 区域的 ram 来维护。
92+
`USB_NOCACHE_RAM_SECTION` 宏表示将变量指定到非 cache ram上,默认 `USB_NOCACHE_RAM_SECTION` 定义为 `__attribute__((section(".noncacheable")))`。
93+
因此,用户需要在对应的链接脚本中添加 no cache ram 的 section,并且 section 段包含 `.noncacheable`。
7894

79-
.. note:: 需要注意,光指定 section 是不够的,还需要配置该 section 中的 ram 是真的 nocache,一般需要配置 mpu 属性(arm 的参考 stm32h7 demo)。
95+
.. note:: 需要注意,光修改链接脚本中的 nocache section 是不够的,还需要配置该 section 中的 ram 是真的 nocache,一般需要配置 mpu 属性(arm 的参考 stm32h7 demo)。
8096

8197
GCC:
8298

0 commit comments

Comments
 (0)