Ver Fonte

docs: update rst

Signed-off-by: sakumisu <1203593632@qq.com>
sakumisu há 6 meses atrás
pai
commit
749cd8531f

+ 4 - 0
docs/source/api/api_device.rst

@@ -7,6 +7,10 @@
 - 有多少个接口就调用多少次 `usbd_add_interface`,参数填相关 `xxx_init_intf`, 如果没有支持的,手动创建一个 intf 填入
 - 有多少个端点就调用多少次 `usbd_add_endpoint`,当中断完成时,会调用到注册的端点回调中。
 
+参考下面这张图:
+
+.. figure:: img/api_device1.png
+
 CORE
 -----------------
 

+ 5 - 6
docs/source/api/api_host.rst

@@ -15,12 +15,11 @@ CLASS 驱动信息结构体
 .. code-block:: C
 
     struct usbh_class_info {
-        uint8_t match_flags; /* Used for product specific matches; range is inclusive */
-        uint8_t class;       /* Base device class code */
-        uint8_t subclass;    /* Sub-class, depends on base class. Eg. */
-        uint8_t protocol;    /* Protocol, depends on base class. Eg. */
-        uint16_t vid;        /* Vendor ID (for vendor/product specific devices) */
-        uint16_t pid;        /* Product ID (for vendor/product specific devices) */
+        uint8_t match_flags;           /* Used for product specific matches; range is inclusive */
+        uint8_t bInterfaceClass;       /* Base device class code */
+        uint8_t bInterfaceSubClass;    /* Sub-class, depends on base class. Eg. */
+        uint8_t bInterfaceProtocol;    /* Protocol, depends on base class. Eg. */
+        const uint16_t (*id_table)[2]; /* List of Vendor/Product ID pairs */
         const struct usbh_class_driver *class_driver;
     };
 

+ 0 - 0
demo/adb/cherryadb.png → docs/source/demo/img/cherryadb.png


BIN
docs/source/demo/img/rtt_adb_shell1.png


BIN
docs/source/demo/img/rtt_adb_shell2.png


+ 28 - 0
docs/source/demo/usbd_adb.rst

@@ -0,0 +1,28 @@
+usbd_adb
+===============
+
+本节主要介绍如何使用 adb device。支持 **cherrysh** 和 rt-thread **msh**,只需要在 main 中添加以下初始化即可。
+
+.. code-block:: C
+
+    cherryadb_init(0, xxxxx);
+
+如果使用 rt-thread,还需要在 menuconfig 中使能 adb device。
+
+.. figure:: img/rtt_adb_shell1.png
+
+进入 adb
+--------------
+
+- 使用 **cherrysh** 时枚举完成以后自动进入 adb 模式
+- 使用 **msh** 需要在 **msh** 中输入 ``adb_enter`` 进入 adb 模式
+
+退出 adb
+--------------
+
+- 使用 **cherrysh** 时输入 ``exit`` 退出 adb 模式
+- 使用 **msh** 需要在 **msh** 中输入 ``adb_exit`` 退出 adb 模式
+
+.. figure:: img/cherryadb.png
+
+.. figure:: img/rtt_adb_shell2.png

+ 1 - 1
docs/source/demo/usbh_msc.rst

@@ -18,7 +18,7 @@ usbh_msc
 
 
 - 不使用 fatfs,则直接使用 usbh_msc_scsi_read10 或者 usbh_msc_scsi_write10 函数进行读写操作。
-- 如果使用 fatfs,则需要在 usbh_msc_thread 中调用 fatfs 的接口进行读写操作。msc读写适配fatfs 参考 `platform/none/usbh_fatfs.c`
+- 如果使用 fatfs,则需要在 usbh_msc_thread 中调用 fatfs 的接口进行读写操作。msc读写适配fatfs 参考 `platform/fatfs/usbh_fatfs.c`
 
 .. code-block:: C
 

+ 2 - 0
docs/source/demo/usbh_net.rst

@@ -104,3 +104,5 @@ TCPIP_THREAD_STACKSIZE 推荐大于 1K,防止栈溢出。
     #if TCPIP_THREAD_STACKSIZE < 1024
     #error TCPIP_THREAD_STACKSIZE must be >= 1024
     #endif
+
+- 具体移植文章可以参考 https://club.rt-thread.org/ask/article/5cf3e9e0b2d95800.html

+ 2 - 0
docs/source/demo/usbh_serial.rst

@@ -1,2 +1,4 @@
 usbh_serial
 ===============
+
+当前仅支持 rt-thread device 框架,包括 cdc acm, ftdi, cp210x, ch34x, pl2303, 具体使用方式参考 rt-thread device api 即可。

+ 1 - 0
docs/source/index.rst

@@ -107,6 +107,7 @@ CherryUSB 是一个小而美的、可移植性高的、用于嵌入式系统的
    demo/usbd_video
    demo/usbd_winusb
    demo/usbd_webusb
+   demo/usbd_adb
    demo/usbh_serial
    demo/usbh_hid
    demo/usbh_msc

+ 4 - 5
docs/source/quick_start/demo.rst

@@ -177,6 +177,8 @@ USB Device 移植要点
 
 .. figure:: img/stm32_13.png
 
+- 如果芯片带 cache,cache 修改参考 :ref:`usb_cache` 章节
+
 - 调用 template 的内容初始化,并填入 `busid` 和 USB IP 的 `reg base`, `busid` 从 0 开始,不能超过 `CONFIG_USBDEV_MAX_BUS`
 
 .. figure:: img/stm32_15.png
@@ -212,13 +214,10 @@ USB Host 移植要点
 
 - 拷贝 **xxx_msp.c** 中的 `HAL_HCD_MspInit` 函数中的内容到 `usb_hc_low_level_init` 函数中,屏蔽 st 生成的 usb 初始化
 - 在中断函数中调用 `USBH_IRQHandler`,并传入 `busid`
+- 链接脚本修改参考 :ref:`usbh_link_script` 章节
+- 如果芯片带 cache,cache 修改参考 :ref:`usb_cache` 章节
 - 调用 `usbh_initialize` 并填入 `busid` 和 USB IP 的 `reg base`, `busid` 从 0 开始,不能超过 `CONFIG_USBHOST_MAX_BUS`
 - 启动线程
 
 .. figure:: img/stm32_18.png
 .. figure:: img/stm32_19.png
-
-- 如果使用 **msc**,并且带文件系统,需要自行添加文件系统文件了,对应的 porting 编写参考 **fatfs_usbh.c** 文件。
-
-.. figure:: img/stm32_21.png
-

+ 9 - 94
docs/source/quick_start/rtthread.rst

@@ -28,35 +28,19 @@
         #define CONFIG_USB_PRINTF(...) rt_kprintf(__VA_ARGS__)
 
 * USB IP 相关的 config 需要用户自己根据芯片实际情况修改
-* 退出以后不急着编译,需要在代码中实现 `usb_dc_low_level_init` 函数。
+* 在代码中实现 `usb_dc_low_level_init` 函数
+* 在 USB 中断函数中调用 `USBD_IRQHandler`,并传入 `busid`
 * 调用 `usbd_initialize` 并填入 `busid` 和 USB IP 的 `reg base`, `busid` 从 0 开始,不能超过 `CONFIG_USBDEV_MAX_BUS`
-* 以上内容我们推荐放在 **board.c** 中,如下代码:
-
-.. code-block:: C
-
-        void OTG_HS_IRQHandler(void)
-        {
-        extern void USBD_IRQHandler(uint8_t busid);
-        USBD_IRQHandler(0);
-        }
-
-        int usbd_init(void)
-        {
-        xxx_template_init(0, USB_OTG_HS_PERIPH_BASE);
-        return 0;
-        }
-
-        INIT_APP_EXPORT(usbd_init);
-
 * 使用 `scons --target=mdk5` 或者 `scons` 进行编译,如果是mdk,需要使用 AC6 编译器
+* 如果芯片带 cache,cache 修改参考 :ref:`usb_cache` 章节
 
 主机配置
 --------------------------
 
-* 选择 Enable usb host mode 并敲回车进入
-* 选择 USB host ip,不清楚自己芯片是哪个 ip 的可以参考 **port** 目录下对应的 readme
+* 选择 Enable usb host mode 并敲回车进入
+* 选择 USB host ip,不清楚自己芯片是哪个 ip 的可以参考 **port** 目录下对应的 readme
 * 根据需要勾选 class 驱动
-* 选择是否开启模板 demo,请注意, msc 禁止使能,因为默认对接到 dfs。
+* 选择是否开启模板 demo,推荐不用
 
 .. figure:: img/env2.png
 
@@ -71,77 +55,8 @@
 
 * USB IP 相关的 config 需要用户自己根据芯片实际情况修改
 * 在代码中实现 `usb_hc_low_level_init` 函数
+* 在 USB 中断函数中调用 `USBH_IRQHandler`,并传入 `busid`
 * 调用 `usbh_initialize` 并填入 `busid` 和 USB IP 的 `reg base`, `busid` 从 0 开始,不能超过 `CONFIG_USBHOST_MAX_BUS`
-* 以上内容我们推荐放在 **board.c** 中,如下代码:
-
-.. code-block:: C
-
-        void OTG_HS_IRQHandler(void)
-        {
-        extern void USBH_IRQHandler(uint8_t busid);
-        USBH_IRQHandler(0);
-        }
-
-        int usbh_init(void)
-        {
-        usbh_initialize(0, USB_OTG_HS_PERIPH_BASE);
-        return 0;
-        }
-
-        INIT_APP_EXPORT(usbh_init);
-
 * 使用 `scons --target=mdk5` 或者 `scons` 进行编译,如果是mdk,需要使用 AC6 编译器
-* 如果使用的是 GCC ,需要在链接脚本(需要放在 flash 位置)中添加如下代码:
-
-.. code-block:: C
-
-        /* section information for usbh class */
-        . = ALIGN(4);
-        __usbh_class_info_start__ = .;
-        KEEP(*(.usbh_class_info))
-        __usbh_class_info_end__ = .;
-
-
-举例如下:
-
-.. code-block:: C
-
-        /* The program code and other data into "FLASH" Rom type memory */
-        .text :
-        {
-        . = ALIGN(4);
-        *(.text)           /* .text sections (code) */
-        *(.text*)          /* .text* sections (code) */
-        *(.glue_7)         /* glue arm to thumb code */
-        *(.glue_7t)        /* glue thumb to arm code */
-        *(.eh_frame)
-
-        KEEP (*(.init))
-        KEEP (*(.fini))
-        . = ALIGN(4);
-        __usbh_class_info_start__ = .;
-        KEEP(*(.usbh_class_info))
-        __usbh_class_info_end__ = .;
-        . = ALIGN(4);
-        _etext = .;        /* define a global symbols at end of code */
-        } > FLASH
-
-借助 STM32CubeMX 生成 USB 初始化
-----------------------------------
-
-使用 STM32CubeMX 主要是用来生成 usb 时钟、引脚、中断的配置。我们需要点击如图所示文件,并配置好 USB 的时钟、中断,点击 `Generate Code`。
-
-.. figure:: img/stm32cubemx0.png
-.. figure:: img/stm32cubemx1.png
-.. figure:: img/stm32cubemx2.png
-.. figure:: img/stm32cubemx_clk.png
-
-- 将 `main.c` 中的 `SystemClock_Config` 替换掉 `board.c` 中的配置
-
-.. figure:: img/stm32_init2.png
-
-.. note :: 下面步骤从 V1.5.0 开始不再需要,**fsdev/usb_glue_st.c**, **dwc2/usb_glue_st.c** 文件中已经实现
-
-- 将 `stm32xxxx_hal_msp.c` 中的 `HAL_PCD_MspInit` 或者是 `HAL_HCD_MspInit` 中的内容复制到 `usb_dc_low_level_init` 和 `usb_hc_low_level_init` 函数中,举例如下:
-
-.. figure:: img/stm32_init.png
+* 链接脚本修改参考 :ref:`usbh_link_script` 章节
+* 如果芯片带 cache,cache 修改参考 :ref:`usb_cache` 章节

+ 22 - 6
docs/source/quick_start/transplant.rst

@@ -12,6 +12,7 @@ USB Device 移植要点
 - 描述符的注册、class的注册、接口的注册、端点中断的注册。不会的参考 demo 下的 template
 - 调用 `usbd_initialize` 并填入 `busid` 和 USB IP 的 `reg base`, `busid` 从 0 开始,不能超过 `CONFIG_USBDEV_MAX_BUS`
 - 在中断函数中调用 `USBD_IRQHandler`,并传入 `busid`, 如果你的 SDK 中中断入口已经存在 `USBD_IRQHandler` ,请更改 USB 协议栈中的名称
+- 如果芯片带 cache,cache 修改参考 :ref:`usb_cache` 章节
 - 编译使用。各个 class 如何使用,参考 demo 下的 template
 
 USB Host 移植要点
@@ -22,7 +23,20 @@ USB Host 移植要点
 - 实现 `usb_hc_low_level_init` 函数(该函数主要负责 USB 时钟、引脚、中断的初始化)。该函数可以放在你想要放的任何参与编译的 c 文件中。如何进行 USB 的时钟、引脚、中断等初始化,请自行根据你使用的芯片原厂提供的源码中进行添加。
 - 调用 `usbh_initialize` 并填入 `busid` 和 USB IP 的 `reg base`, `busid` 从 0 开始,不能超过 `CONFIG_USBHOST_MAX_BUS`
 - 在中断函数中调用 `USBH_IRQHandler`,并传入 `busid`, 如果你的 SDK 中中断入口已经存在 `USBH_IRQHandler` ,请更改 USB 协议栈中的名称
-- 如果使用的是 GCC ,需要在链接脚本中添加如下代码(需要放在 flash 位置):
+- 链接脚本修改参考 :ref:`usbh_link_script` 章节
+- 如果芯片带 cache,cache 修改参考 :ref:`usb_cache` 章节
+- 编译使用。基础的 cdc + hid + msc 参考 `usb_host.c` 文件,其余参考 **platform** 目录下适配
+
+.. _usbh_link_script:
+
+主机链接脚本修改
+-----------------------
+
+在使用主机时,如果没有修改链接脚本,会报 `__usbh_class_info_start__` 和 `__usbh_class_info_end__` 未定义的错误。因为主机协议栈需要在链接脚本中添加一个 section 来存储 class 信息。
+
+- 如果使用的是 KEIL 无需修改
+
+- 如果使用的是 GCC ,需要在链接脚本中添加如下代码(需要放在 flash 位置,建议放最后):
 
 .. code-block:: C
 
@@ -68,15 +82,17 @@ GCC 举例如下:
         place in AXI_SRAM                         { block cherryusb_usbh_class_info };
         keep { section .usbh_class_info};
 
-- 编译使用。各个 class 如何使用,参考 demo 下的 `usb_host.c` 文件
 
-带 cache 功能的芯片使用注意
+.. _usb_cache:
+
+cache 配置修改
 -------------------------------
 
-协议栈以及 port 中不会对 cache 区域的 ram 进行 clean 或者 invalid,所以需要使用一块非 cache 区域的 ram 来维护。 `USB_NOCACHE_RAM_SECTION` 宏表示将变量指定到非 cache ram上,
-因此,用户需要在对应的链接脚本中添加 no cache ram 的 section。默认 `USB_NOCACHE_RAM_SECTION` 定义为  `__attribute__((section(".noncacheable")))`。
+对于带 cache 的芯片,协议栈以及 port 中不会对 cache 区域的 ram 进行 clean 或者 invalid,所以需要使用一块非 cache 区域的 ram 来维护。
+`USB_NOCACHE_RAM_SECTION` 宏表示将变量指定到非 cache ram上,默认 `USB_NOCACHE_RAM_SECTION` 定义为  `__attribute__((section(".noncacheable")))`。
+因此,用户需要在对应的链接脚本中添加 no cache ram 的 section,并且 section 段包含 `.noncacheable`。
 
-.. note:: 需要注意,光指定 section 是不够的,还需要配置该 section 中的 ram 是真的 nocache,一般需要配置 mpu 属性(arm 的参考 stm32h7 demo)。
+.. note:: 需要注意,光修改链接脚本中的 nocache section 是不够的,还需要配置该 section 中的 ram 是真的 nocache,一般需要配置 mpu 属性(arm 的参考 stm32h7 demo)。
 
 GCC: