From 1ac20b5fdefe91cd1eb01697244747f31dce7a5c Mon Sep 17 00:00:00 2001 From: sakumisu <1203593632@qq.com> Date: Sat, 4 Dec 2021 14:41:09 +0800 Subject: add rt-thread userguide --- docs/rt-thread.md | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 docs/rt-thread.md (limited to 'docs/rt-thread.md') diff --git a/docs/rt-thread.md b/docs/rt-thread.md new file mode 100644 index 00000000..ce00a0d0 --- /dev/null +++ b/docs/rt-thread.md @@ -0,0 +1,72 @@ +# RT-Thread package Userguide with usb stack + +[中文版](rt-thread_zh.md) + +To use usb stack package, you need to select it in the RT-Thread package manager. The specific path is as follows: + +``` +-> RT-Thread online packages + -> system packages + --- USB Stack: tiny and portable USB stack for embedded system with USB IP + + USB STACK Options ----> + [ ] Enable usb high speed mode + [*] Enable usb device mode + [*] Enable usb cdc acm device + [ ] Enable usb hid device + [ ] Enable usb dfu device + [ ] Enable usb msc device + [ ] Enable usb hub device + [ ] Enable usb audio device + [ ] Enable usb video device + + Version (latest) ---> +``` + +## How to use + +### 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 **DesignWare**),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 + +- Firstly,you should have a bsp project,and then go to `board\CubeMX_Config` directory, open file that suffix name with `.ioc` in **STM32CubeMX**. +- Enable **USB** or **USB_OTG_FS** or **USB_OTG_HS** in **Connectivity** List,enable USB IRQ in **NVIC Setting**. + +![STM32CubeMX USB setting](img/stm32cubemx.png) + +- Enable USB Clock for 48Mhz in **Clock configuration**. + +![STM32CubeMX USB clock](img/stm32cubemx_clk.png) + +- Generate code. +- 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. +- 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: + +``` +int main(void) +{ + extern void cdc_init(void); + cdc_init(); + extern void usb_dc_init(void); + usb_dc_init(); + while (1) + { + rt_thread_mdelay(500); + } +} +``` + +- How to register class you can go to [stm32 class examples](https://github.com/sakumisu/usb_stack/tree/master/demo/stm32/stm32f103c8t6/example) for a reference. + +#### CDC Demo Demonstration + +![CDC Demo](img/rtt_cdc_demo.png) + +#### Video manual + +If you have problem from steps above, you can see this video:[Use USB Stack in RT-Thread package manager](https://www.bilibili.com/video/BV1Ef4y1t73d?p=26)。 \ No newline at end of file -- cgit v1.3.1