diff options
| author | sakumisu <[email protected]> | 2026-01-30 22:10:34 +0800 |
|---|---|---|
| committer | sakumisu <[email protected]> | 2026-01-30 23:16:00 +0800 |
| commit | eaefb8ed21ed23f732e8b608ed7948e6b71ab0d8 (patch) | |
| tree | 427acdc61cd9bbe9a03f500bfa604a425ed3b1e4 /docs/en/quick_start | |
| parent | 76b3720445f5b2396f3cd7dfdbecc277cafc76e7 (diff) | |
docs: update docs and add english version
Signed-off-by: sakumisu <[email protected]>
Diffstat (limited to 'docs/en/quick_start')
36 files changed, 849 insertions, 0 deletions
diff --git a/docs/en/quick_start/demo.rst b/docs/en/quick_start/demo.rst new file mode 100755 index 00000000..4168d870 --- /dev/null +++ b/docs/en/quick_start/demo.rst @@ -0,0 +1,313 @@ +Quick Verification Based on Existing Demos +============================================= + +Before learning USB or CherryUSB code, we need to quickly verify based on existing demos. Why? To enhance interest in USB and build confidence for the next steps. If demos can't run, or if you explore writing code by yourself, or read USB basic concepts first, you may find that you can't understand anything in the end - there are so many concepts that you simply can't remember them, thus losing interest in USB. Therefore, running demos first is very important. Below I will list the currently supported demo repositories. + +Based on Bouffalolab Series Chips (Official SDK Support) +-------------------------------------------------------------- + +.. list-table:: + :widths: 10 10 10 + :header-rows: 1 + + * - Repo url + - USB IP + - Version + * - https://github.com/CherryUSB/cherryusb_bouffalolab + - FOTG210 + - less than latest + +Based on HPMicro Series Chips (Official SDK Support) +----------------------------------------------------- + +.. list-table:: + :widths: 10 10 10 + :header-rows: 1 + + * - Repo url + - USB IP + - Version + * - https://github.com/CherryUSB/cherryusb_hpmicro + - CHIPIDEA + - less than latest + +Based on esp32s2/s3/p4 Series Chips (Official SDK Support) +------------------------------------------------------------------------------- + +.. list-table:: + :widths: 10 10 10 + :header-rows: 1 + + * - Repo url + - USB IP + - Version + * - https://github.com/CherryUSB/cherryusb_esp32 + - DWC2 + - less than latest + +Default demo uses component library installation form, can be searched at https://components.espressif.com/ for cherryusb + +ESP-Registry can refer to the official documentation, recommended to use vscode + esp-idf development environment. + +- ctrl + shift + p select ESP-IDF welcome interface, then select Component manager + +.. figure:: img/esp1.png + +- Find cherryusb and install + +.. figure:: img/esp2.png + +- Open menuconfig, and open cherryusb configuration, select host or device mode according to actual situation + +.. figure:: img/esp3.png +.. figure:: img/esp4.png + +Based on Phytium Series Chips (Official SDK Support) +------------------------------------------------------- + +.. list-table:: + :widths: 10 10 10 + :header-rows: 1 + + * - Repo url + - USB IP + - Version + * - https://gitee.com/phytium_embedded/phytium-free-rtos-sdk + - PUSB2/XHCI + - equal to v1.4.0 + +Based on Essemi Series Chips (Official SDK Support) +------------------------------------------------------------- + +.. list-table:: + :widths: 10 10 10 + :header-rows: 1 + + * - Repo url + - USB IP + - Version + * - https://github.com/CherryUSB/cherryusb_es32 + - MUSB + - less than latest + +Based on Artinchip Series Chips (Official SDK Support) +------------------------------------------------------------------- + +.. list-table:: + :widths: 10 10 10 + :header-rows: 1 + + * - Repo url + - USB IP + - Version + * - https://gitee.com/artinchip/luban-lite + - AIC/EHCI/OHCI + - less than latest + +Based on Kendryte canmv-k230 Chip (Official SDK Support) +--------------------------------------------------------- + +.. list-table:: + :widths: 10 10 10 + :header-rows: 1 + + * - Repo url + - USB IP + - Version + * - https://github.com/CherryUSB/k230_sdk + - DWC2 + - less than latest + +Based on NXP MCX Series Chips +------------------------------------- + +.. list-table:: + :widths: 10 10 10 + :header-rows: 1 + + * - Repo url + - USB IP + - Version + * - https://github.com/CherryUSB/cherryusb_mcx https://github.com/RT-Thread/rt-thread/tree/master/bsp/nxp/mcx + - CHIPIDEA/kinetis + - less than latest + +Based on SiFli SF32 Series Chips (Official SDK Support) +-------------------------------------------------------- + +.. list-table:: + :widths: 10 10 10 + :header-rows: 1 + + * - Repo url + - USB IP + - Version + * - https://github.com/OpenSiFli/SiFli-SDK + - MUSB + - less than latest + +Based on RP2040/RP2035 Chips (Official SDK Support Coming Soon) +-------------------------------------------------------------------------- + +.. list-table:: + :widths: 10 10 10 + :header-rows: 1 + + * - Repo url + - USB IP + - Version + * - https://github.com/CherryUSB/pico-examples https://github.com/CherryUSB/pico-sdk + - RP2040 + - less than latest + +Based on Actionstech Series Chips (Official SDK Support) +----------------------------------------------------------- + +Not opensource, please contact to Actionstech official + +Based on ST Series Chips +--------------------------- + +.. list-table:: + :widths: 10 10 10 + :header-rows: 1 + + * - Repo url + - USB IP + - Version + * - https://github.com/CherryUSB/cherryusb_stm32 + - DWC2/FSDEV + - less than latest + +Default demo projects provided: + +- F103 uses fsdev ip +- F429 host and device use USB1, pins pb14/pb15, default device does not enable DMA mode +- H7 device uses USB0, pins pa11/pa12, DMA mode not enabled. Host uses USB1, pins pb14/pb15, and needs nocache processing + +Demo provides **stm32xxx.ioc** file, double click to open, click **Generate Code**. + +.. caution:: After generation, please use git reset function to restore the overwritten `main.c` and `stm32xxx_it.c` files, prohibit being overwritten by cubemx. + +Covers F1/F4/H7, other chips are basically similar and won't be repeated. Specific differences are: + +- usb ip difference: F1 uses fsdev, F4/H7 use dwc2 +- dwc2 ip difference: USB0 (pins PA11/PA12) and USB1 (pins PB14/PB15), where USB1 defaults to full-speed, can connect external PHY to form high-speed host, and has DMA functionality +- F4 has no cache, H7 has cache + +If it's STM32F7/STM32H7 with cache functionality, you need to locate the ram used by usb to the no cache ram area. Example as follows + +.. code-block:: C + + cpu_mpu_config(0, MPU_Normal_NonCache, 0x24070000, MPU_REGION_SIZE_64KB); + +Corresponding sct script modification in Keil: + +.. code-block:: C + + LR_IROM1 0x08000000 0x00200000 { ; load region size_region + ER_IROM1 0x08000000 0x00200000 { ; load address = execution address + *.o (RESET, +First) + *(InRoot$$Sections) + .ANY (+RO) + .ANY (+XO) + } + RW_IRAM2 0x24000000 0x00070000 { ; RW data + .ANY (+RW +ZI) + } + USB_NOCACHERAM 0x24070000 0x00010000 { ; RW data + *(.noncacheable) + } + } + +USB Device Porting Points +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +- Use **stm32cubemx** to create project, configure basic RCC, UART (used as log) + +.. figure:: img/stm32_1.png +.. figure:: img/stm32_2.png + +- If using fsdev ip, check **USB**. If using dwc2 ip, check **USB_OTG_FS** or **USB_OTG_HS**. Enable USB interrupt. Other configurations are useless to us, no ST USB library will be used in the code. + +.. figure:: img/stm32_3_1.png +.. figure:: img/stm32_3_2.png + +- Configure usb clock to 48M + +.. figure:: img/stm32_4_1.png +.. figure:: img/stm32_4_2.png + +- Select project, here we choose keil, set stack and heap properly. If using msc, it's recommended to set them larger, then click **Generate Code**. + +.. figure:: img/stm32_5.png + +- Add CherryUSB required source code (**usbd_core.c**, **dwc2/usb_dc_dwc2.c** or **fsdev/usb_dc_fsdev.c**), as well as the class drivers you want to use. You can add corresponding class templates for convenient testing. + +.. figure:: img/stm32_6.png + +- Add necessary header files + +.. figure:: img/stm32_7.png + +- Copy **cherryusb_config_template.h**, place it in the `Core/Inc` directory, and name it `usb_config.h` + +.. figure:: img/stm32_8.png + +- If using fsdev ip, (starting from V1.5.0, need to add **fsdev/usb_glue_st.c**) implement the following macro definition in `usb_config.h`. The specific value varies for different chips: + +.. code-block:: C + + #define CONFIG_USBDEV_FSDEV_PMA_ACCESS 2 + +- Compiler recommends using **AC6**. Check **Microlib**, and implement **printf** for convenient log viewing later. + +.. figure:: img/stm32_10.png +.. figure:: img/stm32_11.png + +.. note :: Starting from V1.5.0, the following two steps are no longer needed because they are already implemented in **fsdev/usb_glue_st.c** and **dwc2/usb_glue_st.c** files + +- Copy the content of **HAL_PCD_MspInit** function in **xxx_msp.c** to **usb_dc_low_level_init** function, disable ST generated USB initialization + +.. figure:: img/stm32_12.png +.. figure:: img/stm32_14.png + +- Call `USBD_IRQHandler` in interrupt function and pass in `busid` + +.. figure:: img/stm32_13.png + +- If the chip has cache, please refer to :ref:`usb_cache` chapter for cache modification + +- Call template content initialization and fill in `busid` and USB IP's `reg base`. `busid` starts from 0 and cannot exceed `CONFIG_USBDEV_MAX_BUS` + +.. figure:: img/stm32_15.png + +USB Host Porting Points +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +The first 6 steps are the same as device side. Note that host driver only supports HS port with DMA (pins PB14/PB15), so FS port (pins PA11/PA12) is not supported (what's the point of a host without DMA). + +- Add CherryUSB required source code (**usbh_core.c**, **usbh_hub.c**, **usb_hc_dwc2.c**, **usb_glue_st.c** and adapter layer files in **osal** directory), as well as the class drivers you want to use, and you can add corresponding **usb host.c** for convenient testing. + +.. figure:: img/stm32_16.png + +- Compiler recommends using **AC6**. Check **Microlib**, and implement **printf** for convenient log viewing later. + +.. figure:: img/stm32_10.png +.. figure:: img/stm32_11.png + +- Copy **cherryusb_config_template.h**, place it in the `Core/Inc` directory, and name it `usb_config.h` + +.. note :: Starting from V1.5.0, the following two steps are no longer needed because they are already implemented in **fsdev/usb_glue_st.c** and **dwc2/usb_glue_st.c** files + +- Copy the content of `HAL_HCD_MspInit` function in **xxx_msp.c** to `usb_hc_low_level_init` function, disable ST generated USB initialization +- Call `USBH_IRQHandler` in interrupt function and pass in `busid` + +.. figure:: img/stm32_19.png + +- For linker script modifications, refer to :ref:`usbh_link_script` chapter +- If the chip has cache, please refer to :ref:`usb_cache` chapter for cache modification +- Call `usbh_initialize` and fill in `busid` and USB IP's `reg base` and `event_handler` (can be omitted as NULL). `busid` starts from 0 and cannot exceed `CONFIG_USBHOST_MAX_BUS` +- Start thread + +.. figure:: img/stm32_18.png diff --git a/docs/en/quick_start/img/env0.png b/docs/en/quick_start/img/env0.png Binary files differnew file mode 100755 index 00000000..c0a8b03f --- /dev/null +++ b/docs/en/quick_start/img/env0.png diff --git a/docs/en/quick_start/img/env1.png b/docs/en/quick_start/img/env1.png Binary files differnew file mode 100755 index 00000000..2a68e052 --- /dev/null +++ b/docs/en/quick_start/img/env1.png diff --git a/docs/en/quick_start/img/env2.png b/docs/en/quick_start/img/env2.png Binary files differnew file mode 100755 index 00000000..ee37101a --- /dev/null +++ b/docs/en/quick_start/img/env2.png diff --git a/docs/en/quick_start/img/esp1.png b/docs/en/quick_start/img/esp1.png Binary files differnew file mode 100755 index 00000000..1f059e71 --- /dev/null +++ b/docs/en/quick_start/img/esp1.png diff --git a/docs/en/quick_start/img/esp2.png b/docs/en/quick_start/img/esp2.png Binary files differnew file mode 100755 index 00000000..fd20e9ce --- /dev/null +++ b/docs/en/quick_start/img/esp2.png diff --git a/docs/en/quick_start/img/esp3.png b/docs/en/quick_start/img/esp3.png Binary files differnew file mode 100755 index 00000000..82a7162f --- /dev/null +++ b/docs/en/quick_start/img/esp3.png diff --git a/docs/en/quick_start/img/esp4.png b/docs/en/quick_start/img/esp4.png Binary files differnew file mode 100755 index 00000000..ffb2882a --- /dev/null +++ b/docs/en/quick_start/img/esp4.png diff --git a/docs/en/quick_start/img/question1.png b/docs/en/quick_start/img/question1.png Binary files differnew file mode 100755 index 00000000..a852e6aa --- /dev/null +++ b/docs/en/quick_start/img/question1.png diff --git a/docs/en/quick_start/img/question2.png b/docs/en/quick_start/img/question2.png Binary files differnew file mode 100755 index 00000000..e00b3bfa --- /dev/null +++ b/docs/en/quick_start/img/question2.png diff --git a/docs/en/quick_start/img/stm32_1.png b/docs/en/quick_start/img/stm32_1.png Binary files differnew file mode 100755 index 00000000..b91044a5 --- /dev/null +++ b/docs/en/quick_start/img/stm32_1.png diff --git a/docs/en/quick_start/img/stm32_10.png b/docs/en/quick_start/img/stm32_10.png Binary files differnew file mode 100755 index 00000000..d55b38e7 --- /dev/null +++ b/docs/en/quick_start/img/stm32_10.png diff --git a/docs/en/quick_start/img/stm32_11.png b/docs/en/quick_start/img/stm32_11.png Binary files differnew file mode 100755 index 00000000..3ad5b074 --- /dev/null +++ b/docs/en/quick_start/img/stm32_11.png diff --git a/docs/en/quick_start/img/stm32_12.png b/docs/en/quick_start/img/stm32_12.png Binary files differnew file mode 100755 index 00000000..84aaffe8 --- /dev/null +++ b/docs/en/quick_start/img/stm32_12.png diff --git a/docs/en/quick_start/img/stm32_13.png b/docs/en/quick_start/img/stm32_13.png Binary files differnew file mode 100755 index 00000000..f12fad75 --- /dev/null +++ b/docs/en/quick_start/img/stm32_13.png diff --git a/docs/en/quick_start/img/stm32_14.png b/docs/en/quick_start/img/stm32_14.png Binary files differnew file mode 100755 index 00000000..e5aa5b19 --- /dev/null +++ b/docs/en/quick_start/img/stm32_14.png diff --git a/docs/en/quick_start/img/stm32_15.png b/docs/en/quick_start/img/stm32_15.png Binary files differnew file mode 100755 index 00000000..7c293287 --- /dev/null +++ b/docs/en/quick_start/img/stm32_15.png diff --git a/docs/en/quick_start/img/stm32_16.png b/docs/en/quick_start/img/stm32_16.png Binary files differnew file mode 100755 index 00000000..70f2e63c --- /dev/null +++ b/docs/en/quick_start/img/stm32_16.png diff --git a/docs/en/quick_start/img/stm32_18.png b/docs/en/quick_start/img/stm32_18.png Binary files differnew file mode 100755 index 00000000..456df189 --- /dev/null +++ b/docs/en/quick_start/img/stm32_18.png diff --git a/docs/en/quick_start/img/stm32_19.png b/docs/en/quick_start/img/stm32_19.png Binary files differnew file mode 100755 index 00000000..a796dc75 --- /dev/null +++ b/docs/en/quick_start/img/stm32_19.png diff --git a/docs/en/quick_start/img/stm32_2.png b/docs/en/quick_start/img/stm32_2.png Binary files differnew file mode 100755 index 00000000..671b1b82 --- /dev/null +++ b/docs/en/quick_start/img/stm32_2.png diff --git a/docs/en/quick_start/img/stm32_3_1.png b/docs/en/quick_start/img/stm32_3_1.png Binary files differnew file mode 100755 index 00000000..9e42196d --- /dev/null +++ b/docs/en/quick_start/img/stm32_3_1.png diff --git a/docs/en/quick_start/img/stm32_3_2.png b/docs/en/quick_start/img/stm32_3_2.png Binary files differnew file mode 100755 index 00000000..492d6739 --- /dev/null +++ b/docs/en/quick_start/img/stm32_3_2.png diff --git a/docs/en/quick_start/img/stm32_4_1.png b/docs/en/quick_start/img/stm32_4_1.png Binary files differnew file mode 100755 index 00000000..e81437bc --- /dev/null +++ b/docs/en/quick_start/img/stm32_4_1.png diff --git a/docs/en/quick_start/img/stm32_4_2.png b/docs/en/quick_start/img/stm32_4_2.png Binary files differnew file mode 100755 index 00000000..dd90f5b8 --- /dev/null +++ b/docs/en/quick_start/img/stm32_4_2.png diff --git a/docs/en/quick_start/img/stm32_5.png b/docs/en/quick_start/img/stm32_5.png Binary files differnew file mode 100755 index 00000000..5bec9878 --- /dev/null +++ b/docs/en/quick_start/img/stm32_5.png diff --git a/docs/en/quick_start/img/stm32_6.png b/docs/en/quick_start/img/stm32_6.png Binary files differnew file mode 100755 index 00000000..f0ad9a0b --- /dev/null +++ b/docs/en/quick_start/img/stm32_6.png diff --git a/docs/en/quick_start/img/stm32_7.png b/docs/en/quick_start/img/stm32_7.png Binary files differnew file mode 100755 index 00000000..8aef0bfa --- /dev/null +++ b/docs/en/quick_start/img/stm32_7.png diff --git a/docs/en/quick_start/img/stm32_8.png b/docs/en/quick_start/img/stm32_8.png Binary files differnew file mode 100755 index 00000000..08d2e724 --- /dev/null +++ b/docs/en/quick_start/img/stm32_8.png diff --git a/docs/en/quick_start/migration.rst b/docs/en/quick_start/migration.rst new file mode 100755 index 00000000..2ea61df7 --- /dev/null +++ b/docs/en/quick_start/migration.rst @@ -0,0 +1,62 @@ +Partial Changes Migration Guide +====================================== + +usbh_initialize +------------------ + +usbh_initialize has added event_handler parameter starting from v1.6.0. Usually not needed, can pass NULL. + +dwc2 glue st +---------------- + +Starting from v1.5.0, dwc2 glue file has built-in low-level initialization, such as `usb_dc_low_level_init`, which depends on `HAL_PCD_MspInit` and `HAL_HCD_MspInit`. Must use stm32cubemx generation. Third-party platforms do not guarantee having these function implementations, check by yourself. + + +dwc2 glue +---------------- + +Starting from v1.5.1, dwc2 adds `struct dwc2_user_params` for implementing different configurations for multiple dwc2 ports. It replaces `usbd_get_dwc2_gccfg_conf` and `usbh_get_dwc2_hccfg_conf` functions, +and adds `dwc2_get_user_params` function implementation, example as follows: + +.. code-block:: C + + #ifndef CONFIG_USB_DWC2_CUSTOM_PARAM + void dwc2_get_user_params(uint32_t reg_base, struct dwc2_user_params *params) + { + memcpy(params, ¶m_common, sizeof(struct dwc2_user_params)); + #ifdef CONFIG_USB_DWC2_CUSTOM_FIFO + struct usb_dwc2_user_fifo_config s_dwc2_fifo_config; + + dwc2_get_user_fifo_config(reg_base, &s_dwc2_fifo_config); + + params->device_rx_fifo_size = s_dwc2_fifo_config.device_rx_fifo_size; + for (uint8_t i = 0; i < MAX_EPS_CHANNELS; i++) { + params->device_tx_fifo_size[i] = s_dwc2_fifo_config.device_tx_fifo_size[i]; + } + #endif + } + #endif + +host serial +---------------- + +Starting from v1.6.0, host adds host serial framework for unifying all serial-like devices. The following APIs need to be replaced with new serial APIs: + +.. code-block:: C + + int usbh_xxx_set_line_coding(struct usbh_xxx *xxx_class, struct cdc_line_coding *line_coding); + int usbh_xxx_get_line_coding(struct usbh_xxx *xxx_class, struct cdc_line_coding *line_coding); + int usbh_xxx_set_line_state(struct usbh_xxx *xxx_class, bool dtr, bool rts); + + int usbh_xxx_bulk_in_transfer(struct usbh_xxx *xxx_class, uint8_t *buffer, uint32_t buflen, uint32_t timeout); + int usbh_xxx_bulk_out_transfer(struct usbh_xxx *xxx_class, uint8_t *buffer, uint32_t buflen, uint32_t timeout); + +Replace with: + +.. code-block:: C + + struct usbh_serial *usbh_serial_open(const char *devname, uint32_t open_flags); + int usbh_serial_close(struct usbh_serial *serial); + int usbh_serial_control(struct usbh_serial *serial, int cmd, void *arg); + int usbh_serial_write(struct usbh_serial *serial, const void *buffer, uint32_t buflen); + int usbh_serial_read(struct usbh_serial *serial, void *buffer, uint32_t buflen); diff --git a/docs/en/quick_start/opensource.rst b/docs/en/quick_start/opensource.rst new file mode 100755 index 00000000..ed8af520 --- /dev/null +++ b/docs/en/quick_start/opensource.rst @@ -0,0 +1,61 @@ +Official Open Source Project Sharing +========================================= + +In addition to basic vendor SDK support, we have also supported some popular open source projects to help developers better use these projects. Below are the adapted demo project links. For specific adaptation layers, refer to https://github.com/cherry-embedded/CherryUSB/tree/master/platform. + +DAPLINK +-------------- + +Adaptation link: https://github.com/cherry-embedded/CherryDAP + +Blackmagic +-------------- + +Adaptation link: https://github.com/zhangjiance/bmp-hpm-port + +RT-Thread +-------------- + +Adaptation link: https://github.com/RT-Thread/rt-thread + +NUTTX/VELA +-------------- + +Adaptation link: https://github.com/CherryUSB/cherryusb_nuttx + +Zephyr +-------------- + +Adaptation link: https://github.com/hpmicro/zephyr_sdk_glue + +Cangaroo +-------------- + +Cangaroo is an open source CAN bus analyzer software. We provide four-channel CANFD analyzer based on hpmicro hpm5361 + +Host computer adaptation link: https://github.com/RCSN/cangaroo_hpmicro_canfd_analyzer +Lower computer adaptation link: https://github.com/RCSN/hpm_sdk_extra/tree/main/demos/cangaroo_hpmicro + +LVGL +-------------- + +Adaptation link: https://github.com/cherry-embedded/CherryUSB/tree/master/platform/lvgl + +QMK +-------------- + +QMK is an open-source keyboard firmware for Atmel AVR and Arm USB families. + +Adaptation link: To be released + +Klipper +-------------- + +Klipper is a 3D-printer firmware. + +Adaptation link: To be released + +MAKCU/KMBOX +-------------- + +Those who know, know - not released
\ No newline at end of file diff --git a/docs/en/quick_start/q&a.rst b/docs/en/quick_start/q&a.rst new file mode 100755 index 00000000..3780b578 --- /dev/null +++ b/docs/en/quick_start/q&a.rst @@ -0,0 +1,135 @@ +Q & A +============================================ + +Porting Question Template +------------------------------ + +Please submit questions through the following channels: +- RT-Thread Official Forum: https://club.rt-thread.org/ask/tag/5f5f851966917b14.html +- Github issue: https://github.com/cherry-embedded/CherryUSB/issues/new/choose + +Please include the following information in your question: + +- Version being used +- Board, pins, and USB IP being used +- Whether USB interrupts, USB clock, USB pins, USB PHY configuration are configured, and whether USB register addresses are correct (include screenshots) +- Whether USB interrupts are triggered +- Whether the chip has cache functionality and whether no-cache processing has been implemented (include screenshots) +- Whether USB circuit is drawn correctly, whether dupont wires are used for connection, whether direct connection is used; if normal, please explain why it's normal +- If interrupts can be triggered, configure **#define CONFIG_USB_DBG_LEVEL USB_DBG_LOG** and provide logs (limited to commercial IPs only; other IPs are prohibited from enabling logs, otherwise enumeration will fail) +- Whether the chip has been taped out and is being sold + +Other Question Template +-------------------------------- + +Specifically describe the phenomenon, reproduction method, test using my provided demo, and provide complete logs + +How Much Performance Can CherryUSB Achieve +---------------------------------------------------------------- + +Reference: :ref:`performace_show` + +ST IP Naming Issues +------------------------- + +ST naming uses USB_OTG_FS, USB_OTG_HS, which doesn't indicate whether it's actually high-speed or full-speed, but represents the maximum speed it can support (high-speed). Both are actually full-speed and require external high-speed PHY. Therefore, please avoid using these terms in questions; use USB0(PA11/PA12), USB1(PB14/PB15) instead. The same applies to other domestic manufacturers. + +GD IP Issues +------------------ + +GD IP uses DWC2, but all hardware parameters read are 0 (I don't understand why they don't want people to know). Therefore, users need to know the hardware information themselves. Starting from version 1.5.0, because hardware information needs to be read, it cannot be used directly. + +Additionally, GD cannot use the EPDIS function to close endpoints after reset. Users need to delete the following code from the reset interrupt: + +.. code-block:: C + + USB_OTG_INEP(i)->DIEPCTL = (USB_OTG_DIEPCTL_EPDIS | USB_OTG_DIEPCTL_SNAK); + USB_OTG_OUTEP(i)->DOEPCTL = (USB_OTG_DOEPCTL_EPDIS | USB_OTG_DOEPCTL_SNAK); + +There may also be other unknown bugs; please test yourself. + +Cannot enumerate after enabling USB_LOG_DBG +---------------------------------------------------------------- + +Only commercial IPs can enumerate after enabling, other IPs are prohibited from enabling, otherwise enumeration will fail. Those who know, know. + +Which version to use for USB3 CV testing +-------------------------------------------- + +Version 1.4.3 and above + +Ep addr XXX fifo overflow +------------------------------ + +.. figure:: img/question1.png + +This error indicates that the default FIFO space setting for this endpoint is insufficient and needs to be increased. This is commonly seen in DWC2/MUSB IP. Refer to relevant glue files for FIFO settings. + +Ep addr XXX overflow +------------------------------ + +.. figure:: img/question2.png + +This error indicates that the IP hardware doesn't have that many endpoints. Please change IP or reduce endpoint usage. +Of course, you can also modify to bidirectional endpoints. Considering that not all IPs support bidirectional endpoints, the default demo doesn't implement bidirectional functionality. For example, the default is 81 02 rather than 81 01. If supported, modify it yourself. Some IP bidirectional endpoints may occupy the same hardware information and may not be usable simultaneously, please check yourself. + +This dwc2 version does not support dma mode, so stop working +---------------------------------------------------------------- + +This DWC2 version doesn't support DMA mode, prohibited from use. Not using DMA mode will frequently trigger NAK interrupts (about every tens of microseconds), causing excessively high CPU usage. + +Which chips support OTG +------------------------------ + +Currently, only HPM chips support OTG functionality in the mainline, automatically switching between host/device modes via ID pin. For other chips, please use manual switching mode OR implement ID recognition driver yourself. + +How to change PC-recognized COM port name +---------------------------------------------------------------- + +This is a Microsoft CDC ACM driver issue that cannot be modified. If modification is needed, please contact Microsoft, pay fees, and write driver to make changes. + +Connect and disconnect events not triggering +---------------------------------------------------------------- + +Currently only HPM chips support connect and disconnect events. For other chips, please use USB VBUS detection circuit. DWC2 IP supports it, but because it requires pin usage and most are log ports, and different enabling configurations vary, support is not provided. + +__has_include error +------------------------------------------------------------------ +If error occurs, compiler needs to support C99 syntax. If using Keil, please use AC6 compiler. + +When to use CONFIG_USB_HS +---------------------------------------------------------------- + +Enable when your chip hardware supports high speed and you want to initialize in high-speed mode. Related IP will configure internal or external high-speed PHY based on this macro. + +Failed to enable port +---------------------------------------------------------------- + +Insufficient power supply or hardware USB circuit issues + +Porting USB host encounters URB return -12/-14 +---------------------------------------------------------------- + +Check PHY configuration, cache configuration (if any), power supply (recommend self-powered) + +USB_ERR_NAK explanation +---------------------------------------------------------------- + +USB_ERR_NAK only exists in DWC2 buffer DMA/slave mode (we don't use slave mode). DWC2 in buffer DMA mode doesn't support hardware handling of NAK interrupts for interrupt transfers, requiring software handling, resulting in very frequent NAK interrupts. Recommend using with timer. +DWC2 scatter/gather DMA mode is fully handled by hardware but doesn't support split transfers. In summary, **tasteless to eat, pity to discard**. + +USB host connecting USB network adapter issues +---------------------------------------------------------------- + +Manifests as network adapter recognition and IP address allocation but inability to ping. This is because the network adapter itself needs to enable auto-dial, usually requiring AT port settings. Specifically for EC20/ML307 modules. + +When to enable CONFIG_USB_DCACHE_ENABLE +------------------------------------------------- + +Enable this macro when chip has cache functionality and doesn't use no-cache RAM to ensure data consistency. **When using EHCI, nocache RAM is still needed internally**. Usually, for third-party platforms or components that don't use no-cache RAM macros but use global variables or malloc operations, this RAM typically goes through cache, requiring this macro. Recommend mandatory enabling for third-party platform usage. + +Which IPs have data alignment requirements +------------------------------------------------- + +- When CONFIG_USB_DCACHE_ENABLE is not enabled, only DWC2/WCH/AIC IP requires 4-byte alignment, others need only 1-byte alignment. +- When CONFIG_USB_DCACHE_ENABLE is enabled, all IPs need alignment to CONFIG_USB_ALIGN_SIZE bytes
\ No newline at end of file diff --git a/docs/en/quick_start/rtthread.rst b/docs/en/quick_start/rtthread.rst new file mode 100755 index 00000000..d01f2673 --- /dev/null +++ b/docs/en/quick_start/rtthread.rst @@ -0,0 +1,62 @@ +RT-Thread Software Package Development Guide +============================================= + +.. note:: CherryUSB has been added to the RT-Thread mainline and you can choose to use the mainline version with the same configuration method. + +This section mainly introduces using the software package manager provided by RT-Thread to configure projects, demonstrated with env. The operations in this section are the same for different chips and won't be repeated later. After opening env, use menuconfig to enter the package manager and select CherryUSB in the path shown in the figure. + +.. figure:: img/env0.png + +Device Configuration +-------------------------- + +* Select Enable USB device mode and press Enter to enter. +* The first configuration is to configure USB speed, divided into **FS, HS**, indicating whether to use full-speed or high-speed functionality. High-speed functionality requires built-in high-speed PHY or external PHY +* The second configuration is to select the USB device IP. If you are not sure which IP your chip uses, refer to the README in the corresponding `port` directory. +* Select the class you want to use +* Choose whether to use a demo template + +.. figure:: img/env1.png + +* Finally exit and save. +* Copy `cherryusb_config_template.h` file to your project directory, rename it to `usb_config.h`, add the corresponding header file path, and modify the following content: + +.. code-block:: C + + #include "rtthread.h" + + #define CONFIG_USB_PRINTF(...) rt_kprintf(__VA_ARGS__) + +* USB IP related config needs to be modified by the user according to the actual chip situation +* Implement the `usb_dc_low_level_init` function in code +* Call `USBD_IRQHandler` in the USB interrupt function and pass in `busid` +* Call `usbd_initialize` and fill in `busid` and USB IP's `reg base`. `busid` starts from 0 and cannot exceed `CONFIG_USBDEV_MAX_BUS` +* Use `scons --target=mdk5` or `scons` to compile. If using mdk, you need to use the AC6 compiler +* If the chip has cache, refer to the :ref:`usb_cache` chapter for cache modifications + +Host Configuration +-------------------------- + +* Select Enable usb host mode and press Enter +* Select USB host ip. If you're not sure which ip your chip uses, refer to the readme under the corresponding **port** directory +* Check class drivers as needed +* Choose whether to enable template demo, recommended not to use + +.. figure:: img/env2.png + +* Finally exit and save. +* Copy `cherryusb_config_template.h` file to your project directory, rename it to `usb_config.h`, add the corresponding header file path, and implement the following content: + +.. code-block:: C + + #include "rtthread.h" + + #define CONFIG_USB_PRINTF(...) rt_kprintf(__VA_ARGS__) + +* USB IP related config needs to be modified by the user according to the actual chip situation +* Implement the `usb_hc_low_level_init` function in code +* Call `USBH_IRQHandler` in the USB interrupt function and pass in `busid` +* Call `usbh_initialize` and fill in `busid` and USB IP's `reg base` and `event_handler` (can be omitted as NULL). `busid` starts from 0 and cannot exceed `CONFIG_USBHOST_MAX_BUS` +* Use `scons --target=mdk5` or `scons` to compile. If using mdk, you need to use the AC6 compiler +* For linker script modifications, refer to the :ref:`usbh_link_script` chapter +* If the chip has cache, refer to the :ref:`usb_cache` chapter for cache modifications diff --git a/docs/en/quick_start/share.rst b/docs/en/quick_start/share.rst new file mode 100755 index 00000000..e4ebdae8 --- /dev/null +++ b/docs/en/quick_start/share.rst @@ -0,0 +1,27 @@ +Developer Experience/Open Source Project Sharing +==================================================== + +- `RT-Thread-CherryUSB - RT-Thread <https://club.rt-thread.org/ask/tag/5f5f851966917b14.html?type=article>`_ + +- `[HPM-DIY]hpm6750 USB开源协议栈性能对比-cherryusb or tinyusb? <https://bbs.eeworld.com.cn/thread-1212755-1-1.html>`_ + +- `RT-Thread-CherryUSB移植笔记(一):APM32F407VGT6 DWC2移植 Port.A Full-Speed + Por.B High-SpeedRT-Thread问答社区 - RT-Thread <https://club.rt-thread.org/ask/article/3e893614c58da7aa.html>`_ + +- `华大HC32F460XXX移植cherryusb协议栈,实现USB CDC ACM_cherryusb移植教程-CSDN博客 <https://blog.csdn.net/u011404840/article/details/142180703>`_ + +- `rt-thread使用cherryusb实现虚拟串口-CSDN博客 <https://blog.csdn.net/weixin_45919462/article/details/143872583>`_ + +- `F1C100S+rtt+CherryUSB的USB HOST成功读到U盘 / 全志 SOC / WhyCan Forum(哇酷开发者社区) <https://whycan.com/t_10289.html>`_ + +- `模仿stm32标准库风格写的库文件(f1c100s/f1c200s),且已移植了rt-thread、lvgl、fatfs、cherryusb / 全志 SOC / WhyCan Forum(哇酷开发者社区) <https://whycan.com/t_10475.html>`_ + +- `printalyzer-timer: F-Stop enlarging timer and print exposure meter <https://github.com/dektronics/printalyzer-timer>`_ + +- `MiSTeryNano: Atari STE MiSTery core for the Tang Nano 20k FPGA <https://github.com/harbaum/MiSTeryNano>`_ + +- `Cherryuf2 <https://github.com/zhaqian12/Cherryuf2>`_ + +- `PicoPiFi: Driverless RNDIS USB WIFI Dongle <https://github.com/sidd-kishan/PicoPiFi>`_ + +- `phobia: Phobia Motor Controller <https://github.com/rombrew/phobia>`_ + diff --git a/docs/en/quick_start/start.rst b/docs/en/quick_start/start.rst new file mode 100755 index 00000000..a19ffe4a --- /dev/null +++ b/docs/en/quick_start/start.rst @@ -0,0 +1,52 @@ +Getting Started Guide +========================= + +First of all, welcome to the world of USB. Here you can learn various USB knowledge and CherryUSB porting, usage, advanced features, etc. However, as a newcomer, you must be quite confused because USB is difficult (actually, once you learn CherryUSB, you'll find that USB is not difficult at all). So in this situation, what should your learning path be? Here, I recommend following my learning path, as this will be most helpful for your USB growth and you won't give up midway. + +First, don't start by looking at concepts. There's an ancient saying: **"What you read on paper is always shallow; to truly understand, you must practice"**. Just looking at written materials won't teach you much. Only when you practice yourself can you gain deeper understanding of these concepts. So as a beginner, what should you do? Please follow these steps. + + +Step 1 +------------- + +You need to have learned C language, UART, and DMA - these are the basics. If you haven't learned them, please go learn them first, otherwise you'll struggle. You might ask: what's the relationship between USB and UART/DMA? I can only say two words: **equivalent**. + +Step 2 +------------- + +Download demo projects and get them running. **For slow learners, I recommend using the same chip model as the demo**. For fast learners, you can choose to port to supported chip models yourself. If you can't even get the demos running, what USB can you learn? Don't you agree? + +Step 3 +--------- + +Excellent! By this step, you can already skillfully port and run all examples. So what should you learn next? **Transactions**, **Requests**, and **Descriptors** (in your USB learning journey, you only need to know these three things; you don't need to know anything else). + +Step 4 +---------- + +First, we need to know that USB transactions include SETUP/IN/OUT, which are essentially equivalent to sending commands, sending data, and receiving data - very simple. As for the control phase, data phase, and status phase that you hear about in online discussions about enumeration, they are not transactions themselves; they are just multiple transactions representing a phase. + +Step 5 +---------- + +Then look at the **USB Enumeration** section and learn about the concept of **descriptors**. At this point, you can briefly look at what descriptors are and what types exist. You need to remember and memorize **the composition of device, configuration, interface, and endpoint descriptors**. You don't need to know anything else because everything else is fixed and can be copy-pasted later. There are enumeration captures for various devices in the group files that you can download and review. + +Step 6 +---------- + +Then you can look at what **requests** are, the composition of request structures, and what types of requests exist - just a basic understanding will suffice. Why? Because it's just an 8-byte data format. Everyone can write UART + custom protocol, and USB requests are the same, just predefined. + +Step 7 +---------- + +At this point, you should familiarize yourself with some protocol stack APIs by referring to the **API Manual** section. You also need to know what conditions constitute interrupt completion, when reception is considered complete, and when transmission is considered complete. You can refer to the **USB Knowledge Extension** section. + +Step 8 +---------- + +By this step, you're definitely very knowledgeable, and you can start working on some small functional projects. During this period, please repeatedly review the **USB Knowledge Extension** section until you truly understand it, because this content is very important and will affect the execution results of our code. + +Step 9 +---------- + +You've reached this point - you shouldn't need me anymore! Now you can look at USB concepts, USB details, and CherryUSB code flow. Then it's just consolidation, consolidation, and more consolidation. Congratulations, you've graduated! diff --git a/docs/en/quick_start/transplant.rst b/docs/en/quick_start/transplant.rst new file mode 100755 index 00000000..eefb0a7a --- /dev/null +++ b/docs/en/quick_start/transplant.rst @@ -0,0 +1,137 @@ +General Chip Porting Guide +======================================= + +This section mainly introduces the general steps and precautions for porting CherryUSB host and device protocol stacks to all chips with USB IP. Before porting, you need to **prepare a basic project that can print helloworld**. Default printing uses `printf`. If it's host mode, **you need to prepare a basic project that can execute OS scheduling normally**. + +USB Device Porting Key Points +------------------------------------- + +- Copy CherryUSB source code to the project directory and add source files and header file paths as needed. It's recommended to add all header file paths. Among them, `usbd_core.c` and `usb_dc_xxx.c` are required items. `usb_dc_xxx.c` is the USB IP DCD driver corresponding to the chip. If you don't know which USB IP your chip belongs to, refer to the readme of different USB IPs under the **port** directory. If the USB IP you're using is not supported, you'll have to implement it yourself +- Copy `cherryusb_config_template.h` file to your project directory, rename it to `usb_config.h`, and add the corresponding directory header file path +- Implement `usb_dc_low_level_init` function (this function is mainly responsible for USB clock, pin, and interrupt initialization). This function can be placed in any C file that participates in compilation. For USB clock, pin, interrupt initialization, please add them yourself according to the source code provided by your chip manufacturer. +- Call `USBD_IRQHandler` in the interrupt function and pass `busid`. If `USBD_IRQHandler` already exists in the interrupt entry of your SDK, please change the name in the USB protocol stack +- If the chip has cache, refer to the :ref:`usb_cache` section for cache modifications +- Register descriptors and call `usbd_initialize`, fill in `busid` and USB IP's `reg base`. `busid` starts from 0 and cannot exceed `CONFIG_USBDEV_MAX_BUS`. You can directly use templates under the demo directory + +USB Host Porting Key Points +------------------------------------- + +- Copy CherryUSB source code to project directory and add source files and header file paths as needed. It's recommended to add all header file paths. Among them, `usbh_core.c`, `usb_hc_xxx.c` and source files under the **osal** directory (choose corresponding source files according to different OS) are required. `usb_hc_xxx.c` is the USB IP HCD driver corresponding to the chip. If you don't know which USB IP your chip belongs to, refer to the readme of different USB IPs under the **port** directory. If the USB IP you're using is not supported, you'll have to implement it yourself +- Copy `cherryusb_config_template.h` file to your project directory, rename it to `usb_config.h`, and add the corresponding directory header file path +- Implement `usb_hc_low_level_init` function (this function is mainly responsible for USB clock, pin, and interrupt initialization). This function can be placed in any C file that participates in compilation. For USB clock, pin, interrupt initialization, please add them yourself according to the source code provided by your chip manufacturer. +- Call `usbh_initialize` and fill in `busid`, USB IP's `reg base`, and `event_handler` (can be omitted as NULL). `busid` starts from 0 and cannot exceed `CONFIG_USBHOST_MAX_BUS` +- Call `USBH_IRQHandler` in the interrupt function and pass `busid`. If `USBH_IRQHandler` already exists in the interrupt entry of your SDK, please change the name in the USB protocol stack +- Refer to the :ref:`usbh_link_script` section for linker script modifications +- If the chip has cache, refer to the :ref:`usb_cache` section for cache modifications +- Call `usbh_initialize`, fill in `busid`, USB IP's `reg base`, and `event_handler` (can be omitted as NULL). `busid` starts from 0 and cannot exceed `CONFIG_USBHOST_MAX_BUS`. For basic CDC + HID + MSC, refer to the `usb_host.c` file. For others, refer to adaptations under the **platform** directory + +.. _usbh_link_script: + +Host Linker Script Modifications +------------------------------------- + +When using the host, if you haven't modified the linker script, you will encounter `__usbh_class_info_start__` and `__usbh_class_info_end__` undefined errors. This is because the host protocol stack requires adding a section to the linker script to store class information. + +- No modification needed if using KEIL + +- If using GCC, add the following code to the linker script (needs to be placed in flash location, recommended at the end): + +.. code-block:: C + + // Add the following code to the ld file + . = ALIGN(4); + __usbh_class_info_start__ = .; + KEEP(*(.usbh_class_info)) + __usbh_class_info_end__ = .; + +GCC example: + +.. 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 + +- Segger Embedded Studio example: + +.. code-block:: C + + define block cherryusb_usbh_class_info { section .usbh_class_info }; + + define exported symbol __usbh_class_info_start__ = start of block cherryusb_usbh_class_info; + define exported symbol __usbh_class_info_end__ = end of block cherryusb_usbh_class_info + 1; + + place in AXI_SRAM { block cherryusb_usbh_class_info }; + keep { section .usbh_class_info}; + + +.. _usb_cache: + +cache Configuration Modification +-------------------------------------- + +For chips with cache functionality, the protocol stack and port will not clean or invalidate RAM in the cache region, so a non-cache RAM area needs to be used for maintenance. +`USB_NOCACHE_RAM_SECTION` macro specifies variables to be placed in non-cache RAM. By default, `USB_NOCACHE_RAM_SECTION` is defined as `__attribute__((section(".noncacheable")))`. +Therefore, users need to add a no cache RAM section in the corresponding linker script, and the section must include `.noncacheable`. + +.. note:: Note that just modifying the nocache section in the linker script is not sufficient. You also need to configure the RAM in that section to be truly nocache, which typically requires configuring MPU attributes (for ARM, refer to the stm32h7 demo). + +GCC: + +.. code-block:: C + + MEMORY + { + RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 256K - 64K + RAM_nocache (xrw) : ORIGIN = 0x20030000, LENGTH = 64K + FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 512K + } + + ._nocache_ram : + { + . = ALIGN(4); + *(.noncacheable) + } >RAM_nocache + + +SCT: + +.. code-block:: C + + LR_IROM1 0x08000000 0x00200000 { ; load region size_region + ER_IROM1 0x08000000 0x00200000 { ; load address = execution address + *.o (RESET, +First) + *(InRoot$$Sections) + .ANY (+RO) + .ANY (+XO) + } + RW_IRAM2 0x24000000 0x00070000 { ; RW data + .ANY (+RW +ZI) + } + USB_NOCACHERAM 0x24070000 0x00010000 { ; RW data + *(.noncacheable) + } + } + +ICF: + +.. code-block:: C + + define region NONCACHEABLE_RAM = [from 0x1140000 size 256K]; + place in NONCACHEABLE_RAM { section .noncacheable, section .noncacheable.init, section .noncacheable.bss }; // Noncacheable |
