update readme for host
This commit is contained in:
BIN
docs/img/rtt_host_demo.png
Normal file
BIN
docs/img/rtt_host_demo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 5.4 KiB |
BIN
docs/img/rtt_libc.png
Normal file
BIN
docs/img/rtt_libc.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 20 KiB |
BIN
docs/img/rtt_menuconfig1.png
Normal file
BIN
docs/img/rtt_menuconfig1.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 33 KiB |
BIN
docs/img/rtt_menuconfig2.png
Normal file
BIN
docs/img/rtt_menuconfig2.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 22 KiB |
BIN
docs/img/stm32cubemx2.png
Normal file
BIN
docs/img/stm32cubemx2.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 41 KiB |
@@ -28,7 +28,6 @@ To use CherryUSB package, you need to select it in the RT-Thread package manager
|
|||||||
### In STM32
|
### In STM32
|
||||||
|
|
||||||
Please note that stm32 series have two usb ip. For usb ip, like stm32f0、stm32f1、stm32f3, for usb otg ip(as we know it is from **synopsys**),like stm32f4、stm32f7 and so on.
|
Please note that stm32 series have two usb ip. For usb ip, like stm32f0、stm32f1、stm32f3, for usb otg ip(as we know it is from **synopsys**),like stm32f4、stm32f7 and so on.
|
||||||
~~Currently,if you usb usb device on mcu with usb ip, recommend you to use dcd porting named **usb_dc_nohal.c**,otherwise use **usb_dc_hal.c**.In the future,**usb_dc_hal.c** will be droped~~.
|
|
||||||
|
|
||||||
#### Use USB Device
|
#### Use USB Device
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
CherryUSB Options ---->
|
CherryUSB Options ---->
|
||||||
USB Speed (FS) --->
|
USB Speed (FS) --->
|
||||||
[*] Enable usb device mode
|
[*] Enable usb device mode
|
||||||
|
[ ] Enable usb host mode
|
||||||
[*] Enable usb cdc acm device
|
[*] Enable usb cdc acm device
|
||||||
[ ] Enable usb hid device
|
[ ] Enable usb hid device
|
||||||
[ ] Enable usb dfu device
|
[ ] Enable usb dfu device
|
||||||
@@ -23,11 +24,11 @@
|
|||||||
Version (latest) --->
|
Version (latest) --->
|
||||||
```
|
```
|
||||||
|
|
||||||
## 使用 USB Stack
|
## 使用 CherryUSB
|
||||||
|
|
||||||
### 在 STM32 平台
|
### 在 STM32 平台
|
||||||
|
|
||||||
STM32 系列单片机有两种 USB IP,分别是 USB IP 和 USB OTG IP。其中 USB IP,例如 STM32F0、STM32F1、STM32F3等等,USB OTG IP(我们都知道用的是 **synopsys** 公司的)的有 STM32F4、STM32F7、STM32H7等等。当前如果你需要使用 USB Device 功能,porting 接口提供了两种,~~一种是不带 hal 层的 **usb_dc_nohal.c**,一种是带 hal 层的 **usb_dc_hal.c**,如果你使用的是 USB IP系列,推荐用前者,否则用后者,需要注意的是后者在后面会删除,不使用 hal 版本~~ 一种是适配 USB IP的 **fsdev**,另一种是适配 USB OTG IP 的 **synopsys**。
|
STM32 系列单片机有两种 USB IP,分别是 USB IP 和 USB OTG IP。其中 USB IP,例如 STM32F0、STM32F1、STM32F3等等,USB OTG IP(我们都知道用的是 **synopsys** 公司的)的有 STM32F4、STM32F7、STM32H7等等。当前如果你需要使用 USB Device 功能,porting 接口提供了两种,一种是适配 USB IP的 **fsdev**,另一种是适配 USB OTG IP 的 **synopsys**。
|
||||||
|
|
||||||
#### 使用 USB Device 功能
|
#### 使用 USB Device 功能
|
||||||
|
|
||||||
@@ -42,8 +43,7 @@ STM32 系列单片机有两种 USB IP,分别是 USB IP 和 USB OTG IP。其中 U
|
|||||||
|
|
||||||
- 点击 **Generate code**。
|
- 点击 **Generate code**。
|
||||||
- 复制 **SystemClock_Config** 函数内容到 **board.c** 中。
|
- 复制 **SystemClock_Config** 函数内容到 **board.c** 中。
|
||||||
- ~~如果你使用的是 hal 版本,需要复制 **MX_USB_OTG_FS_PCD_Init** 或者 **MX_USB_OTG_HS_PCD_Init** 到你的应用程序中,比如 **main.c**,并且还需要从 **it.c** 中复制中断函数。~~
|
- 实现 ``usb_dc_low_level_init``,并将 ``HAL_PCD_MspInit`` 里面内容复制进来,例如:
|
||||||
- 实现 ``usb_dc_low_level_init``,并将 ``HAL_PCD_MspInit`` 里面内容复制进来。
|
|
||||||
|
|
||||||
```
|
```
|
||||||
void usb_dc_low_level_init(void)
|
void usb_dc_low_level_init(void)
|
||||||
@@ -57,8 +57,13 @@ void usb_dc_low_level_init(void)
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
- 实现 **printf** 函数或者将 **usb_utils.h** 中的 **printf** 改成 **rt_kprintf**,并添加 `#include <rtthread.h>`
|
- 由于协议栈默认使用 `printf` 和 `malloc` 和 `free`,所以需要开启 libc 支持或者自己实现。
|
||||||
- 现在我们可以调用 USB Stack 中的函数来注册描述符、接口、端点中断,并调用 `usb_dc_init`,示例如下:
|

|
||||||
|
|
||||||
|
- 使用 **menuconfig** 配置 **CherryUSB** 软件包,使能 usb device 并勾选需要的 device class。
|
||||||
|

|
||||||
|
|
||||||
|
- 现在我们可以调用 CherryUSB 中的函数来注册描述符、接口、端点中断,并调用 `usb_dc_init`,示例如下:
|
||||||
|
|
||||||
```
|
```
|
||||||
#include <rtthread.h>
|
#include <rtthread.h>
|
||||||
@@ -84,9 +89,59 @@ int main(void)
|
|||||||
|
|
||||||
- 关于如何注册 class 类可以参考 [stm32 class examples](https://github.com/sakumisu/usb_stack/tree/master/demo/stm32/stm32f103c8t6/example)。
|
- 关于如何注册 class 类可以参考 [stm32 class examples](https://github.com/sakumisu/usb_stack/tree/master/demo/stm32/stm32f103c8t6/example)。
|
||||||
|
|
||||||
#### CDC demo 演示
|
#### 使用 USB Host 功能
|
||||||
|
|
||||||

|
- 首先,你需要有一个 bsp 工程,之后进入到 `board\CubeMX_Config` 目录下,使用 **STM32CubeMX** 打开后缀名为 `.ioc` 的文件。
|
||||||
|
- 进入 **Connectivity** 选项,选择 **USB_OTG_FS** 或者 **USB_OTG_HS**,并使能 **host only** 功能,在 **NVIC Setting** 中开启 OTG GLOBAL 中断,其余两个端点中断不需要。
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
- 在 **Clock configuration** 栏配置 USB 时钟为 48Mhz.
|
||||||
|
- 点击 **Generate code**。
|
||||||
|
- 复制 **SystemClock_Config** 函数内容到 **board.c** 中。
|
||||||
|
- 修改 **usb_hc_synopsys.c** 中 HAL 库头文件包含,例如 `#include "stm32f4xx_hal.h"`。
|
||||||
|
- 手动增加 **xxx_hal_hcd.c** 和 **xxx_ll_usb.c** 文件
|
||||||
|
- 由于协议栈默认使用 `printf` 和 `malloc` 和 `free`,所以需要开启 libc 支持或者自己实现。
|
||||||
|

|
||||||
|
|
||||||
|
- 使用 **menuconfig** 配置 **CherryUSB** 软件包,使能 usb host(默认加载所有支持的 class)。
|
||||||
|

|
||||||
|
|
||||||
|
- `main.c` 中调用 `usbh_initialize` 初始化 host 协议栈。
|
||||||
|
|
||||||
|
```
|
||||||
|
#include <rtthread.h>
|
||||||
|
#include <rtdevice.h>
|
||||||
|
#include <board.h>
|
||||||
|
#include "usbh_core.h"
|
||||||
|
/* defined the LED0 pin: PH10 */
|
||||||
|
#define LED0_PIN GET_PIN(H, 10)
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
/* set LED0 pin mode to output */
|
||||||
|
rt_pin_mode(LED0_PIN, PIN_MODE_OUTPUT);
|
||||||
|
usbh_initialize();
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
rt_pin_write(LED0_PIN, PIN_HIGH);
|
||||||
|
rt_thread_mdelay(500);
|
||||||
|
rt_pin_write(LED0_PIN, PIN_LOW);
|
||||||
|
rt_thread_mdelay(500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Demo 演示
|
||||||
|
|
||||||
|
- cdc acm device demo
|
||||||
|
|
||||||
|

|
||||||
|
- host demo
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
#### 视频教程
|
#### 视频教程
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user