update doc

This commit is contained in:
sakumisu
2022-05-02 23:08:57 +08:00
parent 5ab847d745
commit 33c0c2f02c
21 changed files with 92 additions and 18 deletions

View File

@@ -6,27 +6,20 @@
CherryUSB 使用指南
======================================================
CherryUSB 是一个小而美的、可移植性高的、用于嵌入式系统的 USB 主从协议栈。
CherryUSB 是一个小而美的、可移植性高的、用于嵌入式系统的 USB 主从协议栈。同时 CherryUSB 具有以下优点:
**小在哪?**
- 比较全面的 class 驱动,并且 class 驱动全部模板化,方便自主添加
- 协议栈采用链表动态注册的方式,减少内存占用
- 树状化编程,方便理清 class 驱动与接口、端点的关系hub、port、class 之间的关系
- 标准化的 porting 接口
- 设备协议栈的使用简化到类如 uart 、dma 的使用,主机协议栈的使用简化到文件的使用
- 协议栈实现代码简短,并且从上往下看完就能理清 usb 枚举过程和 class 加载机制
代码中基本不使用全局的数组,使用链表的方式由用户动态的添加。并且基本不占用很大的 ramflash 的占用也非常小。
其他相关链接:
**美在哪?**
代码从上到下是逐次递进的过程,不存在什么跳到其他文件,或者顺序倒换的问题,也就是说当你从上往下把代码看完,你也就知道 usb 协议栈是如何工作的了。
**可移植性高在哪?**
根据 usb ip 的特点,定义了标准的 dcd 和 hcd 的 porting 接口,只要依次实现,就可以使用 usb 协议栈了。
最重要的一点,无论从机还是主机协议栈,协议栈只做枚举过程的操作,其余所有应用层操作,协议栈不会做。比如使用从机时,触发了其他端点的 out 中断,那么将直接调用到用户注册的函数中,由用户自己读取,而协议栈并不会使用类似 ringbuffer 的形式读取到一块 buffer上先存着减少 copy 次数。而类似 msc 和 rndis 这种已经成标准的则由协议栈进行操作。
此外使用从机协议栈过程中你就发现out 中断就像串口接收中断一样in 中断就像 dma 完成中断一样。而主机协议栈则是在枚举完成后提供了注册的 **devname** ,用户通过 **devname** 得到收发时需要的句柄,从而进行数据的收发,无需知道收发设备的端点和地址,用户也不想知道这么多信息,太过复杂。
- 从机协议栈视频教程https://www.bilibili.com/video/BV1Ef4y1t73d
- 主机协议栈视频教程TODO
- github https://github.com/sakumisu/CherryUSB
- **从机协议栈视频教程** https://www.bilibili.com/video/BV1Ef4y1t73d
- **主机协议栈视频教程** TODO
- **github** https://github.com/sakumisu/CherryUSB
.. toctree::
:maxdepth: 1

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 97 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 73 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 56 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 73 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.7 KiB

View File

@@ -15,6 +15,8 @@ USB Device 移植要点
- 编译使用。各个 class 如何使用,参考 demo 下的 template
.. note:: device 移植要点其实就三个,实现 `usb_dc_low_level_init` ,改 `USBD_IRQHandler=xxxx``USB_BASE=0xxxxx``USB_NUM_BIDIR_ENDPOINTS=x`,改 `usb_config.h` 中的内容
USB Host 移植要点
-----------------------
@@ -35,6 +37,8 @@ USB Host 移植要点
- 编译使用。各个 class 如何使用,参考 demo 下的 `usb_host.c` 文件
.. note:: device 移植要点其实就三个,实现 `usb_hc_low_level_init` ,改 `USBH_IRQHandler=xxxx``USB_BASE=0xxxxx` ,改 `usb_config.h` 中的内容
.. note:: 使用 host 时,推荐添加除了 hub 以外的所有适配的 class 驱动,达到自动加载驱动的目的。当然,如果不用,那就不添加。
.. caution:: 如果主从 ip 共用一个中断,推荐设置 `USBD_IRQHandler=USBD_IRQHandler``USBH_IRQHandler=USBH_IRQHandler` ,然后由真正的中断函数根据主从模式调用这两个函数。

View File

@@ -1,2 +1,79 @@
基于 STM32F429 开发指南
=========================
本节是基于 stm32f429 开发板的使用,仓库中已经默认有主从机的 demo ,其余 stm32 系列,基本类似,所以后续不再赘述。
.. note:: stm32的 porting 使用寄存器编写,所以 st 的 usb 库没有一丁点用想删就删。ps 主机还没用寄存器,所以删不了)
工程样例试用
-----------------------
默认删除 Drivers ,所以需要使用 stm32cubemx 生成一下 Drivers 目录下的文件demo 底下提供了 **stm32f429igt6.ioc** 文件,双击打开,点击 **Generate Code** 即可。
USB Device 移植要点
-----------------------
- 使用 **stm32cubemx** 创建工程,配置基本的 RCC、UART (作为log使用)
.. figure:: img/stm32f429_1.png
.. figure:: img/stm32f429_2.png
- 如果使用 PA11 和 PA12勾选 **USB_OTG_FS**,否则勾选 **USB_OTG_HS**,并按下面进行配置,我们只需要开启中断和 gpio 配置,其他配置对我们没用。
.. figure:: img/stm32f429_3.png
- 配置 usb clock 为 48M
.. figure:: img/stm32f429_4.png
- 选择好工程,这里我们选择 keil设置好 stack 和 heap如果使用 msc 可以推荐设置大点,然后点击 **Generate Code**
.. figure:: img/stm32f429_5.png
- 添加 CherryUSB 必须要的源码( **usbd_core.c****usb_dc_synopsys.c** ,以及想要使用的 class 驱动,可以将对应的 class template 添加方便测试。
.. figure:: img/stm32f429_6.png
- 头文件该加的加
.. figure:: img/stm32f429_7.png
- 复制一份 **usb_config.h**,这里放到 `Core/Inc` 目录下
.. figure:: img/stm32f429_8.png
- 如果使用 PB14 和 PB15并且仅使用 FS 模式,编译选项中添加 `CONFIG_USB_HS_IN_FULL`,剩下的按照下图配置,编译器推荐使用 **AC6**。打开 **Microlib**,后续 **printf** 使用
.. figure:: img/stm32f429_9.png
.. figure:: img/stm32f429_10.png
- 实现 printf如果关闭 usb 的log可以不实现
.. figure:: img/stm32f429_11.png
- 拷贝 **xxx_msp.c** 中的 **HAL_PCD_MspInit** 函数中的内容到 **usb_dc_low_level_init** 函数中,屏蔽 st 生成的 usb 中断函数和 usb 初始化
.. figure:: img/stm32f429_12.png
.. figure:: img/stm32f429_13.png
.. figure:: img/stm32f429_14.png
.. figure:: img/stm32f429_15.png
- 主函数屏蔽 **stm32cubemx** 生成的中断函数和 usb 初始化,然后调用 template 的内容初始化,就可以使用了
USB Host 移植要点
-----------------------
前面 9 步与 Device 一样,目前 Host 暂时用的 st 的 hal 库,后面有时间了再整理成寄存器的并进行优化。
- 添加 CherryUSB 必须要的源码( **usbh_core.c****usb_hc_synopsys.c** 、以及 **osal** 目录下的适配层文件),以及想要使用的 class 驱动(推荐添加除了 hub 之外的所有的 class可以将对应的 usb host template 添加方便测试。
.. figure:: img/stm32f429_16.png
- 主函数屏蔽 st 的 usb 初始化,屏蔽 st 生成的 usb 中断函数,然后调用 **usbh_initialize** 以及 os 需要的启动线程的函数即可使用
.. figure:: img/stm32f429_17.png
- 如果使用 **msc**,并且带文件系统,需要自行添加文件系统文件了,对应的 porting 编写参考 **fatfs_usbh.c** 文件。
.. figure:: img/stm32f429_18.png