update rt-thread readme

This commit is contained in:
sakumisu
2021-12-12 21:49:21 +08:00
parent 0dd1c3b3fb
commit e0cc3e7f5a
4 changed files with 59 additions and 44 deletions

View File

@@ -44,14 +44,14 @@ USB Stack is a tiny, beautiful and portable USB host and device stack for embedd
|core | usb core implementation | |core | usb core implementation |
|demo | different chip demo | |demo | different chip demo |
|docs | doc for guiding | |docs | doc for guiding |
|packet capture | packet caputre file | |packet capture | packet capture file |
|port | usb dcd and hcd porting | |port | usb dcd and hcd porting |
## USB Device Stack Overview ## USB Device Stack Overview
USB Device Stack provides a unified framework of functions for standard device requests, CLASS requests, VENDOR requests and custom special requestsThe object-oriented and chained approach allows the user to quickly get started with composite devices without having to worry about the underlying logic. At the same time, a standard dcd porting interface has been standardised for adapting different USB IPs to achieve ip-oriented programming. USB Device Stack provides a unified framework of functions for standard device requests, CLASS requests, VENDOR requests and custom special requests. The object-oriented and chained approach allows the user to quickly get started with composite devices without having to worry about the underlying logic. At the same time, a standard dcd porting interface has been standardised for adapting different USB IPs to achieve ip-oriented programming.
How USB Device Stack is implemented, this video will tell you: <https://www.bilibili.com/video/BV1Ef4y1t73d> How USB Device Stack is implemented, this video will tell you: <https://www.bilibili.com/video/BV1Ef4y1t73d> .
USB Device Stack has the following functions USB Device Stack has the following functions
@@ -67,7 +67,7 @@ USB Device Stack has the following functions
- Support Device Firmware Upgrade CLASS (DFU) - Support Device Firmware Upgrade CLASS (DFU)
- Support USB MIDI CLASS (MIDI) - Support USB MIDI CLASS (MIDI)
- Support Test and Measurement CLASS (TMC) - Support Test and Measurement CLASS (TMC)
- Support Vendor class - Support Vendor class
- Support WINUSB1.0、WINUSB2.0 - Support WINUSB1.0、WINUSB2.0
USB Device Stack resource usage USB Device Stack resource usage

View File

@@ -7,6 +7,8 @@ src = Glob('core/usbd_core.c')
CPPDEFINES = [] CPPDEFINES = []
if GetDepend(['PKG_USB_STACK_USING_HS']): if GetDepend(['PKG_USB_STACK_USING_HS']):
CPPDEFINES+=['CONFIG_USB_HS'] CPPDEFINES+=['CONFIG_USB_HS']
elif GetDepend(['PKG_USB_STACK_USING_HS_IN_FULL']):
CPPDEFINES += ['CONFIG_USB_HS_IN_FULL']
# USB DEVICE # USB DEVICE
if GetDepend(['PKG_USB_STACK_USING_DEVICE']): if GetDepend(['PKG_USB_STACK_USING_DEVICE']):
@@ -32,36 +34,12 @@ if GetDepend(['PKG_USB_STACK_USING_DEVICE']):
path += [cwd + '/class/msc'] path += [cwd + '/class/msc']
src += Glob('class/cdc/usbd_msc.c') src += Glob('class/cdc/usbd_msc.c')
if GetDepend(['SOC_FAMILY_STM32']): if GetDepend(['SOC_FAMILY_STM32']):
if GetDepend(['SOC_SERIES_STM32F0']): if GetDepend(['SOC_SERIES_STM32F0']) or GetDepend(['SOC_SERIES_STM32F1']) or GetDepend(['SOC_SERIES_STM32F3']) or GetDepend(['SOC_SERIES_STM32L0']):
src += Glob('port/stm32/usb_dc_nohal.c') src += Glob('port/fsdev/usb_dc_fsdev.c')
src += Glob('../../../../libraries/STM32F0xx_HAL/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_pcd.c') else:
src += Glob('../../../../libraries/STM32F0xx_HAL/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_pcd_ex.c') src += Glob('port/synopsys/usb_dc_synopsys.c')
src += Glob('../../../../libraries/STM32F0xx_HAL/STM32F0xx_HAL_Driver/Src/stm32f0xx_ll_usb.c') if GetDepend(['SOC_SERIES_STM32F0']):
CPPDEFINES += ['STM32F0'] CPPDEFINES += ['STM32H7']
elif GetDepend(['SOC_SERIES_STM32F1']):
src += Glob('port/stm32/usb_dc_nohal.c')
src += Glob('../../../../libraries/STM32F1xx_HAL/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_pcd.c')
src += Glob('../../../../libraries/STM32F1xx_HAL/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_pcd_ex.c')
src += Glob('../../../../libraries/STM32F1xx_HAL/STM32F1xx_HAL_Driver/Src/stm32f1xx_ll_usb.c')
CPPDEFINES += ['STM32F1']
elif GetDepend(['SOC_SERIES_STM32F3']):
src += Glob('port/stm32/usb_dc_nohal.c')
src += Glob('../../../../libraries/STM32F3xx_HAL/STM32F3xx_HAL_Driver/Src/stm32f3xx_hal_pcd.c')
src += Glob('../../../../libraries/STM32F3xx_HAL/STM32F3xx_HAL_Driver/Src/stm32f3xx_hal_pcd_ex.c')
src += Glob('../../../../libraries/STM32F3xx_HAL/STM32F3xx_HAL_Driver/Src/stm32f3xx_ll_usb.c')
CPPDEFINES += ['STM32F3']
elif GetDepend(['SOC_SERIES_STM32F4']):
src += Glob('port/stm32/usb_dc_hal.c')
src += Glob('../../../../libraries/STM32F4xx_HAL/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pcd.c')
src += Glob('../../../../libraries/STM32F4xx_HAL/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pcd_ex.c')
src += Glob('../../../../libraries/STM32F4xx_HAL/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_usb.c')
CPPDEFINES += ['STM32F4']
elif GetDepend(['SOC_SERIES_STM32H7']):
src += Glob('port/stm32/usb_dc_hal.c')
src += Glob('../../../../libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_pcd.c')
src += Glob('../../../../libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_pcd_ex.c')
src += Glob('../../../../libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_ll_usb.c')
CPPDEFINES += ['STM32H7']
# USB HOST # USB HOST
if GetDepend(['USB_STACK_USING_HOST']): if GetDepend(['USB_STACK_USING_HOST']):

View File

@@ -10,7 +10,7 @@ To use usb stack package, you need to select it in the RT-Thread package manager
--- USB Stack: tiny and portable USB stack for embedded system with USB IP --- USB Stack: tiny and portable USB stack for embedded system with USB IP
USB STACK Options ----> USB STACK Options ---->
[ ] Enable usb high speed mode USB Speed (FS) --->
[*] Enable usb device mode [*] Enable usb device mode
[*] Enable usb cdc acm device [*] Enable usb cdc acm device
[ ] Enable usb hid device [ ] Enable usb hid device
@@ -28,7 +28,7 @@ To use usb stack 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. ~~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
@@ -43,7 +43,21 @@ Currently,if you usb usb device on mcu with usb ip, recommend you to use dcd por
- Generate code. - Generate code.
- Copy **SystemClock_Config** into **board.c**. - Copy **SystemClock_Config** into **board.c**.
- Copy **MX_USB_OTG_FS_PCD_Init** or **MX_USB_OTG_HS_PCD_Init** into **main.c** if you use **usb_dc_hal.c**.Also, USB Irq from **it.c** needs the same. - ~~Copy **MX_USB_OTG_FS_PCD_Init** or **MX_USB_OTG_HS_PCD_Init** into **main.c** if you use **usb_dc_hal.c**.Also, USB Irq from **it.c** needs the same.~~
- Implement **usb_dc_low_level_init** and copy codes in from ``HAL_PCD_MspInit``.
```
void usb_dc_low_level_init(void)
{
/* Peripheral clock enable */
__HAL_RCC_USB_CLK_ENABLE();
/* USB interrupt Init */
HAL_NVIC_SetPriority(USB_LP_CAN1_RX0_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(USB_LP_CAN1_RX0_IRQn);
}
```
- Implement **printf** or modify with **rt_kprintf** in **usb_utils.h**, usb stack needs. - Implement **printf** or modify with **rt_kprintf** in **usb_utils.h**, usb stack needs.
- Now we can call some functions provided by **usb_stack**.Your should register descriptors、interfaces and endpoint callback firstly, and then call `usb_dc_init`. Example is as follows: - Now we can call some functions provided by **usb_stack**.Your should register descriptors、interfaces and endpoint callback firstly, and then call `usb_dc_init`. Example is as follows:
@@ -52,10 +66,11 @@ int main(void)
{ {
extern void cdc_init(void); extern void cdc_init(void);
cdc_init(); cdc_init();
extern void usb_dc_init(void);
usb_dc_init(); usb_dc_init();
while (1) while (1)
{ {
uint8_t data_buffer[10] = { 0x31, 0x32, 0x33, 0x34, 0x35, 0x31, 0x32, 0x33, 0x34, 0x35 };
usbd_ep_write(0x81, data_buffer, 10, NULL);
rt_thread_mdelay(500); rt_thread_mdelay(500);
} }
} }

View File

@@ -10,7 +10,7 @@
--- USB Stack: tiny and portable USB stack for embedded system with USB IP --- USB Stack: tiny and portable USB stack for embedded system with USB IP
USB STACK Options ----> USB STACK Options ---->
[ ] Enable usb high speed mode USB Speed (FS) --->
[*] Enable usb device mode [*] Enable usb device mode
[*] Enable usb cdc acm device [*] Enable usb cdc acm device
[ ] Enable usb hid device [ ] Enable usb hid device
@@ -27,7 +27,7 @@
### 在 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 版本。 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**
#### 使用 USB Device 功能 #### 使用 USB Device 功能
@@ -42,22 +42,44 @@ 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** 中复制中断函数。 - ~~如果你使用的是 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`` 里面内容复制进来。
```
void usb_dc_low_level_init(void)
{
/* Peripheral clock enable */
__HAL_RCC_USB_CLK_ENABLE();
/* USB interrupt Init */
HAL_NVIC_SetPriority(USB_LP_CAN1_RX0_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(USB_LP_CAN1_RX0_IRQn);
}
```
- 实现 **printf** 函数或者将 **usb_utils.h** 中的 **printf** 改成 **rt_kprintf**,并添加 `#include <rtthread.h>` - 实现 **printf** 函数或者将 **usb_utils.h** 中的 **printf** 改成 **rt_kprintf**,并添加 `#include <rtthread.h>`
- 现在我们可以调用 USB Stack 中的函数来注册描述符、接口、端点中断,并调用 `usb_dc_init`,示例如下: - 现在我们可以调用 USB Stack 中的函数来注册描述符、接口、端点中断,并调用 `usb_dc_init`,示例如下:
``` ```
#include <rtthread.h>
#include <rtdevice.h>
#include <board.h>
#include <stdio.h>
extern void usb_dc_init(void);
int main(void) int main(void)
{ {
extern void cdc_init(void); extern void cdc_init(void);
cdc_init(); cdc_init();
extern void usb_dc_init(void);
usb_dc_init(); usb_dc_init();
while (1) while (1)
{ {
uint8_t data_buffer[10] = { 0x31, 0x32, 0x33, 0x34, 0x35, 0x31, 0x32, 0x33, 0x34, 0x35 };
usbd_ep_write(0x81, data_buffer, 10, NULL);
rt_thread_mdelay(500); rt_thread_mdelay(500);
} }
} }
``` ```
- 关于如何注册 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)。