Files
CherryUSB/quick_start/demo.html

663 lines
35 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!DOCTYPE html>
<html class="writer-html5" lang="en" data-content_root="../">
<head>
<meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>基于现有 demo 快速验证 &mdash; CherryUSB 1.6.0 documentation</title>
<link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=80d5e7a1" />
<link rel="stylesheet" type="text/css" href="../_static/css/theme.css?v=9edc463e" />
<script src="../_static/jquery.js?v=5d32c60e"></script>
<script src="../_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
<script src="../_static/documentation_options.js?v=72d88caf"></script>
<script src="../_static/doctools.js?v=9a2dae69"></script>
<script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
<script src="../_static/js/theme.js"></script>
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<link rel="next" title="芯片通用移植指南" href="transplant.html" />
<link rel="prev" title="入门必看" href="start.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="../index.html" class="icon icon-home">
CherryUSB
</a>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" aria-label="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu">
<p class="caption" role="heading"><span class="caption-text">快速上手</span></p>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="start.html">入门必看</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">基于现有 demo 快速验证</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#bouffalolab-sdk">基于 bouffalolab 系列芯片(官方 SDK 支持)</a></li>
<li class="toctree-l2"><a class="reference internal" href="#hpmicro-sdk">基于 HPMicro 系列芯片(官方 SDK 支持)</a></li>
<li class="toctree-l2"><a class="reference internal" href="#esp32s2-s3-p4-sdk">基于 esp32s2/s3/p4 系列芯片(官方 SDK 支持)</a></li>
<li class="toctree-l2"><a class="reference internal" href="#phytium-sdk">基于 Phytium 系列芯片(官方 SDK 支持)</a></li>
<li class="toctree-l2"><a class="reference internal" href="#essemi-sdk">基于 Essemi 系列芯片(官方 SDK 支持)</a></li>
<li class="toctree-l2"><a class="reference internal" href="#artinchip-sdk">基于 Artinchip 系列芯片(官方 SDK 支持)</a></li>
<li class="toctree-l2"><a class="reference internal" href="#kendryte-canmv-k230-sdk">基于 Kendryte canmv-k230 系列(官方 SDK 支持)</a></li>
<li class="toctree-l2"><a class="reference internal" href="#nxp-mcx">基于 NXP MCX 系列芯片</a></li>
<li class="toctree-l2"><a class="reference internal" href="#sifli-sf32-sdk">基于 SiFli SF32 系列芯片(官方 SDK 支持)</a></li>
<li class="toctree-l2"><a class="reference internal" href="#rp2040-rp2035-sdk">基于 RP2040/RP2035 芯片(官方 SDK 即将支持)</a></li>
<li class="toctree-l2"><a class="reference internal" href="#actionstech">基于 Actionstech 系列芯片</a></li>
<li class="toctree-l2"><a class="reference internal" href="#st">基于 ST 系列芯片</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#usb-device">USB Device 移植要点</a></li>
<li class="toctree-l3"><a class="reference internal" href="#usb-host">USB Host 移植要点</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="transplant.html">芯片通用移植指南</a></li>
<li class="toctree-l1"><a class="reference internal" href="rtthread.html">基于 RT-Thread 软件包开发指南</a></li>
<li class="toctree-l1"><a class="reference internal" href="q%26a.html">Q &amp; A</a></li>
<li class="toctree-l1"><a class="reference internal" href="migration.html">部分改动迁移指南</a></li>
<li class="toctree-l1"><a class="reference internal" href="share.html">开发者经验/开源项目分享</a></li>
<li class="toctree-l1"><a class="reference internal" href="opensource.html">官方开源项目分享</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">USB 基本知识点</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../usb/usb2.0_basic.html">USB 基本概念(2.0 为主)</a></li>
<li class="toctree-l1"><a class="reference internal" href="../usb/usb3.0_basic.html">USB 基本概念(3.0 为主)</a></li>
<li class="toctree-l1"><a class="reference internal" href="../usb/usb_desc.html">USB 描述符</a></li>
<li class="toctree-l1"><a class="reference internal" href="../usb/usb_request.html">USB 设备请求</a></li>
<li class="toctree-l1"><a class="reference internal" href="../usb/usb_enum.html">USB 枚举</a></li>
<li class="toctree-l1"><a class="reference internal" href="../usb/usb_ext.html">USB 知识点拓展</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">API 手册</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../api/api_device.html">设备协议栈</a></li>
<li class="toctree-l1"><a class="reference internal" href="../api/api_host.html">主机协议栈</a></li>
<li class="toctree-l1"><a class="reference internal" href="../api/api_port.html">主从驱动</a></li>
<li class="toctree-l1"><a class="reference internal" href="../api/api_config.html">USB CONFIG 说明</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">Class 指南</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../class/class_cdc.html">CDC</a></li>
<li class="toctree-l1"><a class="reference internal" href="../class/class_hid.html">HID</a></li>
<li class="toctree-l1"><a class="reference internal" href="../class/class_msc.html">MSC</a></li>
<li class="toctree-l1"><a class="reference internal" href="../class/class_audio.html">UAC</a></li>
<li class="toctree-l1"><a class="reference internal" href="../class/class_video.html">UVC</a></li>
<li class="toctree-l1"><a class="reference internal" href="../class/winusb.html">WINUSB</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">例程</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../demo/usbd_cdc_acm.html">CDC ACM Device</a></li>
<li class="toctree-l1"><a class="reference internal" href="../demo/usbd_hid.html">HID Device</a></li>
<li class="toctree-l1"><a class="reference internal" href="../demo/usbd_msc.html">MSC Device</a></li>
<li class="toctree-l1"><a class="reference internal" href="../demo/usbd_audiov1.html">AudioV1 Device</a></li>
<li class="toctree-l1"><a class="reference internal" href="../demo/usbd_audiov2.html">AudioV2 Device</a></li>
<li class="toctree-l1"><a class="reference internal" href="../demo/usbd_video.html">USB Video Device</a></li>
<li class="toctree-l1"><a class="reference internal" href="../demo/usbd_winusb.html">WinUSB Device</a></li>
<li class="toctree-l1"><a class="reference internal" href="../demo/usbd_webusb.html">WebUSB Device</a></li>
<li class="toctree-l1"><a class="reference internal" href="../demo/usbd_rndis.html">CDC RNDIS Device</a></li>
<li class="toctree-l1"><a class="reference internal" href="../demo/usbd_ecm.html">CDC ECM Device</a></li>
<li class="toctree-l1"><a class="reference internal" href="../demo/usbd_adb.html">ADB Device</a></li>
<li class="toctree-l1"><a class="reference internal" href="../demo/usbd_mtp.html">MTP Device</a></li>
<li class="toctree-l1"><a class="reference internal" href="../demo/usbh_serial.html">Serial Host</a></li>
<li class="toctree-l1"><a class="reference internal" href="../demo/usbh_hid.html">HID Host</a></li>
<li class="toctree-l1"><a class="reference internal" href="../demo/usbh_msc.html">MSC Host</a></li>
<li class="toctree-l1"><a class="reference internal" href="../demo/usbh_net.html">Network Host</a></li>
<li class="toctree-l1"><a class="reference internal" href="../demo/usbh_bluetooth.html">BTBLE Host</a></li>
<li class="toctree-l1"><a class="reference internal" href="../demo/usbh_wifi.html">WIFI Host</a></li>
<li class="toctree-l1"><a class="reference internal" href="../demo/usbh_audio.html">Audio Host</a></li>
<li class="toctree-l1"><a class="reference internal" href="../demo/usbh_video.html">Video Host</a></li>
<li class="toctree-l1"><a class="reference internal" href="../demo/usb_otg.html">USB OTG</a></li>
<li class="toctree-l1"><a class="reference internal" href="../demo/usbd_vendor.html">Vendor Device 驱动编写</a></li>
<li class="toctree-l1"><a class="reference internal" href="../demo/usbh_vendor.html">Vendor Host 驱动编写</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">USBIP 介绍</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../usbip/ohci.html">OHCI</a></li>
<li class="toctree-l1"><a class="reference internal" href="../usbip/ehci.html">EHCI</a></li>
<li class="toctree-l1"><a class="reference internal" href="../usbip/xhci.html">XHCI</a></li>
<li class="toctree-l1"><a class="reference internal" href="../usbip/chipidea.html">CHIPIDEA</a></li>
<li class="toctree-l1"><a class="reference internal" href="../usbip/dwc2.html">DWC2</a></li>
<li class="toctree-l1"><a class="reference internal" href="../usbip/musb.html">MUSB</a></li>
<li class="toctree-l1"><a class="reference internal" href="../usbip/fotg210.html">FOTG210</a></li>
<li class="toctree-l1"><a class="reference internal" href="../usbip/cdns2.html">CDNS2</a></li>
<li class="toctree-l1"><a class="reference internal" href="../usbip/cdns3.html">CDNS3</a></li>
<li class="toctree-l1"><a class="reference internal" href="../usbip/dwc3.html">DWC3</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">工具使用</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../tools/index.html">chryusb_configurator</a></li>
<li class="toctree-l1"><a class="reference internal" href="../tools/index.html#usb-protocol-suite">力科 USB Protocol Suite</a></li>
<li class="toctree-l1"><a class="reference internal" href="../tools/index.html#wireshark">Wireshark</a></li>
<li class="toctree-l1"><a class="reference internal" href="../tools/index.html#audacity">Audacity</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">版本说明</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../version.html">版本说明</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">性能展示</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../show/index.html">性能展示</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">商业支持</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../support/index.html">商业支持</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" >
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../index.html">CherryUSB</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="Page navigation">
<ul class="wy-breadcrumbs">
<li><a href="../index.html" class="icon icon-home" aria-label="Home"></a></li>
<li class="breadcrumb-item active">基于现有 demo 快速验证</li>
<li class="wy-breadcrumbs-aside">
<a href="../_sources/quick_start/demo.rst.txt" rel="nofollow"> View page source</a>
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<section id="demo">
<h1>基于现有 demo 快速验证<a class="headerlink" href="#demo" title="Link to this heading"></a></h1>
<p>在学习 USB 或者是学习 CherryUSB 代码之前,我们需要先基于现有的 demo 进行快速验证,为什么?是为了提升对 USB 的兴趣,能有信心进行下一步的动作,如果 demo 都跑不起来,或者自己摸索写代码,或者先看 USB 基本概念,结果看到最后,
发现一点都看不懂,概念好多,根本记不住,从而丧失对 USB 的兴趣。因此,先跑 demo 非常重要。下面我将给大家罗列目前支持的 demo 仓库。</p>
<section id="bouffalolab-sdk">
<h2>基于 bouffalolab 系列芯片(官方 SDK 支持)<a class="headerlink" href="#bouffalolab-sdk" title="Link to this heading"></a></h2>
<table class="docutils align-default">
<colgroup>
<col style="width: 33.3%" />
<col style="width: 33.3%" />
<col style="width: 33.3%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>Repo url</p></th>
<th class="head"><p>USB IP</p></th>
<th class="head"><p>Version</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p><a class="reference external" href="https://github.com/CherryUSB/cherryusb_bouffalolab">https://github.com/CherryUSB/cherryusb_bouffalolab</a></p></td>
<td><p>FOTG210</p></td>
<td><p>less than latest</p></td>
</tr>
</tbody>
</table>
</section>
<section id="hpmicro-sdk">
<h2>基于 HPMicro 系列芯片(官方 SDK 支持)<a class="headerlink" href="#hpmicro-sdk" title="Link to this heading"></a></h2>
<table class="docutils align-default">
<colgroup>
<col style="width: 33.3%" />
<col style="width: 33.3%" />
<col style="width: 33.3%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>Repo url</p></th>
<th class="head"><p>USB IP</p></th>
<th class="head"><p>Version</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p><a class="reference external" href="https://github.com/CherryUSB/cherryusb_hpmicro">https://github.com/CherryUSB/cherryusb_hpmicro</a></p></td>
<td><p>CHIPIDEA</p></td>
<td><p>less than latest</p></td>
</tr>
</tbody>
</table>
</section>
<section id="esp32s2-s3-p4-sdk">
<h2>基于 esp32s2/s3/p4 系列芯片(官方 SDK 支持)<a class="headerlink" href="#esp32s2-s3-p4-sdk" title="Link to this heading"></a></h2>
<table class="docutils align-default">
<colgroup>
<col style="width: 33.3%" />
<col style="width: 33.3%" />
<col style="width: 33.3%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>Repo url</p></th>
<th class="head"><p>USB IP</p></th>
<th class="head"><p>Version</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p><a class="reference external" href="https://github.com/CherryUSB/cherryusb_esp32">https://github.com/CherryUSB/cherryusb_esp32</a></p></td>
<td><p>DWC2</p></td>
<td><p>less than latest</p></td>
</tr>
</tbody>
</table>
<p>默认 demo 采用组件库安装的形式,在 <a class="reference external" href="https://components.espressif.com/">https://components.espressif.com/</a> 中搜索 cherryusb 即可。也可使用官方 idf 仓库下的 cherryusb demo。</p>
<p>ESP-Registry 可以参考官方文档,推荐使用 vscode + esp-idf 的开发环境。</p>
<ul class="simple">
<li><p>ctrl + shift + p 选择 ESP-IDF 欢迎界面,然后选择 Component mananger</p></li>
</ul>
<figure class="align-default">
<img alt="../_images/esp1.png" src="../_images/esp1.png" />
</figure>
<ul class="simple">
<li><p>找到 cherryusb 并安装</p></li>
</ul>
<figure class="align-default">
<img alt="../_images/esp2.png" src="../_images/esp2.png" />
</figure>
<ul class="simple">
<li><p>打开 menuconfig并打开 cherryusb 的配置,根据实际情况选择主机或者从机模式</p></li>
</ul>
<figure class="align-default">
<img alt="../_images/esp3.png" src="../_images/esp3.png" />
</figure>
<figure class="align-default">
<img alt="../_images/esp4.png" src="../_images/esp4.png" />
</figure>
</section>
<section id="phytium-sdk">
<h2>基于 Phytium 系列芯片(官方 SDK 支持)<a class="headerlink" href="#phytium-sdk" title="Link to this heading"></a></h2>
<table class="docutils align-default">
<colgroup>
<col style="width: 33.3%" />
<col style="width: 33.3%" />
<col style="width: 33.3%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>Repo url</p></th>
<th class="head"><p>USB IP</p></th>
<th class="head"><p>Version</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p><a class="reference external" href="https://gitee.com/phytium_embedded/phytium-free-rtos-sdk">https://gitee.com/phytium_embedded/phytium-free-rtos-sdk</a></p></td>
<td><p>PUSB2/XHCI</p></td>
<td><p>equal to v1.4.0</p></td>
</tr>
</tbody>
</table>
</section>
<section id="essemi-sdk">
<h2>基于 Essemi 系列芯片(官方 SDK 支持)<a class="headerlink" href="#essemi-sdk" title="Link to this heading"></a></h2>
<table class="docutils align-default">
<colgroup>
<col style="width: 33.3%" />
<col style="width: 33.3%" />
<col style="width: 33.3%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>Repo url</p></th>
<th class="head"><p>USB IP</p></th>
<th class="head"><p>Version</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p><a class="reference external" href="https://github.com/CherryUSB/cherryusb_es32">https://github.com/CherryUSB/cherryusb_es32</a></p></td>
<td><p>MUSB</p></td>
<td><p>less than latest</p></td>
</tr>
</tbody>
</table>
</section>
<section id="artinchip-sdk">
<h2>基于 Artinchip 系列芯片(官方 SDK 支持)<a class="headerlink" href="#artinchip-sdk" title="Link to this heading"></a></h2>
<table class="docutils align-default">
<colgroup>
<col style="width: 33.3%" />
<col style="width: 33.3%" />
<col style="width: 33.3%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>Repo url</p></th>
<th class="head"><p>USB IP</p></th>
<th class="head"><p>Version</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p><a class="reference external" href="https://gitee.com/artinchip/luban-lite">https://gitee.com/artinchip/luban-lite</a></p></td>
<td><p>AIC/EHCI/OHCI</p></td>
<td><p>less than latest</p></td>
</tr>
</tbody>
</table>
</section>
<section id="kendryte-canmv-k230-sdk">
<h2>基于 Kendryte canmv-k230 系列(官方 SDK 支持)<a class="headerlink" href="#kendryte-canmv-k230-sdk" title="Link to this heading"></a></h2>
<table class="docutils align-default">
<colgroup>
<col style="width: 33.3%" />
<col style="width: 33.3%" />
<col style="width: 33.3%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>Repo url</p></th>
<th class="head"><p>USB IP</p></th>
<th class="head"><p>Version</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p><a class="reference external" href="https://github.com/CherryUSB/k230_sdk">https://github.com/CherryUSB/k230_sdk</a></p></td>
<td><p>DWC2</p></td>
<td><p>less than latest</p></td>
</tr>
</tbody>
</table>
</section>
<section id="nxp-mcx">
<h2>基于 NXP MCX 系列芯片<a class="headerlink" href="#nxp-mcx" title="Link to this heading"></a></h2>
<table class="docutils align-default">
<colgroup>
<col style="width: 33.3%" />
<col style="width: 33.3%" />
<col style="width: 33.3%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>Repo url</p></th>
<th class="head"><p>USB IP</p></th>
<th class="head"><p>Version</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p><a class="reference external" href="https://github.com/CherryUSB/cherryusb_mcx">https://github.com/CherryUSB/cherryusb_mcx</a> <a class="reference external" href="https://github.com/RT-Thread/rt-thread/tree/master/bsp/nxp/mcx">https://github.com/RT-Thread/rt-thread/tree/master/bsp/nxp/mcx</a></p></td>
<td><p>CHIPIDEA/kinetis</p></td>
<td><p>less than latest</p></td>
</tr>
</tbody>
</table>
</section>
<section id="sifli-sf32-sdk">
<h2>基于 SiFli SF32 系列芯片(官方 SDK 支持)<a class="headerlink" href="#sifli-sf32-sdk" title="Link to this heading"></a></h2>
<table class="docutils align-default">
<colgroup>
<col style="width: 33.3%" />
<col style="width: 33.3%" />
<col style="width: 33.3%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>Repo url</p></th>
<th class="head"><p>USB IP</p></th>
<th class="head"><p>Version</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p><a class="reference external" href="https://github.com/OpenSiFli/SiFli-SDK">https://github.com/OpenSiFli/SiFli-SDK</a></p></td>
<td><p>MUSB</p></td>
<td><p>less than latest</p></td>
</tr>
</tbody>
</table>
</section>
<section id="rp2040-rp2035-sdk">
<h2>基于 RP2040/RP2035 芯片(官方 SDK 即将支持)<a class="headerlink" href="#rp2040-rp2035-sdk" title="Link to this heading"></a></h2>
<table class="docutils align-default">
<colgroup>
<col style="width: 33.3%" />
<col style="width: 33.3%" />
<col style="width: 33.3%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>Repo url</p></th>
<th class="head"><p>USB IP</p></th>
<th class="head"><p>Version</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p><a class="reference external" href="https://github.com/CherryUSB/pico-examples">https://github.com/CherryUSB/pico-examples</a> <a class="reference external" href="https://github.com/CherryUSB/pico-sdk">https://github.com/CherryUSB/pico-sdk</a></p></td>
<td><p>RP2040</p></td>
<td><p>less than latest</p></td>
</tr>
</tbody>
</table>
</section>
<section id="actionstech">
<h2>基于 Actionstech 系列芯片<a class="headerlink" href="#actionstech" title="Link to this heading"></a></h2>
<p>Not opensource</p>
</section>
<section id="st">
<h2>基于 ST 系列芯片<a class="headerlink" href="#st" title="Link to this heading"></a></h2>
<table class="docutils align-default">
<colgroup>
<col style="width: 33.3%" />
<col style="width: 33.3%" />
<col style="width: 33.3%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>Repo url</p></th>
<th class="head"><p>USB IP</p></th>
<th class="head"><p>Version</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p><a class="reference external" href="https://github.com/CherryUSB/cherryusb_stm32">https://github.com/CherryUSB/cherryusb_stm32</a></p></td>
<td><p>DWC2/FSDEV</p></td>
<td><p>less than latest</p></td>
</tr>
</tbody>
</table>
<p>默认提供以下 demo 工程:</p>
<ul class="simple">
<li><p>F103 使用 fsdev ip</p></li>
<li><p>F429 主从使用 USB1, 引脚 pb14/pb15, 默认从机没有开启 DMA 模式</p></li>
<li><p>H7 设备使用 USB0, 引脚 pa11/pa12没有开 DMA 模式。主机使用 USB1 ,引脚 pb14/pb15并且需要做 nocache 处理</p></li>
</ul>
<p>demo 底下提供了 <strong>stm32xxx.ioc</strong> 文件,双击打开,点击 <strong>Generate Code</strong> 即可。</p>
<div class="admonition caution">
<p class="admonition-title">Caution</p>
<p>生成完以后,请使用 git reset 功能将被覆盖的 <cite>main.c</cite><cite>stm32xxx_it.c</cite> 文件撤回,禁止被 cubemx 覆盖。</p>
</div>
<p>涵盖 F1/F4/H7其余芯片基本类似不再赘述具体区别有</p>
<ul class="simple">
<li><p>usb ip 区别F1使用 fsdevF4/H7使用 dwc2</p></li>
<li><p>dwc2 ip 区别: USB0 (引脚是 PA11/PA12) 和 USB1 (引脚是 PB14/PB15), 其中 USB1 默认全速可以接外部PHY 形成高速主机,并且带 dma 功能</p></li>
<li><p>F4 无 cacheH7 有 cache</p></li>
</ul>
<p>如果是 STM32F7/STM32H7 这种带 cache 功能,需要将 usb 使用到的 ram 定位到 no cache ram 区域。举例如下</p>
<div class="highlight-C notranslate"><div class="highlight"><pre><span></span><span class="n">cpu_mpu_config</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="w"> </span><span class="n">MPU_Normal_NonCache</span><span class="p">,</span><span class="w"> </span><span class="mh">0x24070000</span><span class="p">,</span><span class="w"> </span><span class="n">MPU_REGION_SIZE_64KB</span><span class="p">);</span>
</pre></div>
</div>
<p>对应 keil 中的 sct 脚本修改:</p>
<div class="highlight-C notranslate"><div class="highlight"><pre><span></span><span class="n">LR_IROM1</span><span class="w"> </span><span class="mh">0x08000000</span><span class="w"> </span><span class="mh">0x00200000</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="p">;</span><span class="w"> </span><span class="n">load</span><span class="w"> </span><span class="n">region</span><span class="w"> </span><span class="n">size_region</span>
<span class="n">ER_IROM1</span><span class="w"> </span><span class="mh">0x08000000</span><span class="w"> </span><span class="mh">0x00200000</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="p">;</span><span class="w"> </span><span class="n">load</span><span class="w"> </span><span class="n">address</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">execution</span><span class="w"> </span><span class="n">address</span>
<span class="o">*</span><span class="p">.</span><span class="n">o</span><span class="w"> </span><span class="p">(</span><span class="n">RESET</span><span class="p">,</span><span class="w"> </span><span class="o">+</span><span class="n">First</span><span class="p">)</span>
<span class="o">*</span><span class="p">(</span><span class="n">InRoot$$Sections</span><span class="p">)</span>
<span class="p">.</span><span class="n">ANY</span><span class="w"> </span><span class="p">(</span><span class="o">+</span><span class="n">RO</span><span class="p">)</span>
<span class="p">.</span><span class="n">ANY</span><span class="w"> </span><span class="p">(</span><span class="o">+</span><span class="n">XO</span><span class="p">)</span>
<span class="p">}</span>
<span class="n">RW_IRAM2</span><span class="w"> </span><span class="mh">0x24000000</span><span class="w"> </span><span class="mh">0x00070000</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="p">;</span><span class="w"> </span><span class="n">RW</span><span class="w"> </span><span class="n">data</span>
<span class="p">.</span><span class="n">ANY</span><span class="w"> </span><span class="p">(</span><span class="o">+</span><span class="n">RW</span><span class="w"> </span><span class="o">+</span><span class="n">ZI</span><span class="p">)</span>
<span class="p">}</span>
<span class="n">USB_NOCACHERAM</span><span class="w"> </span><span class="mh">0x24070000</span><span class="w"> </span><span class="mh">0x00010000</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="p">;</span><span class="w"> </span><span class="n">RW</span><span class="w"> </span><span class="n">data</span>
<span class="o">*</span><span class="p">(.</span><span class="n">noncacheable</span><span class="p">)</span>
<span class="p">}</span>
<span class="p">}</span>
</pre></div>
</div>
<section id="usb-device">
<h3>USB Device 移植要点<a class="headerlink" href="#usb-device" title="Link to this heading"></a></h3>
<ul class="simple">
<li><p>使用 <strong>stm32cubemx</strong> 创建工程,配置基本的 RCC、UART (作为log使用)</p></li>
</ul>
<figure class="align-default">
<img alt="../_images/stm32_1.png" src="../_images/stm32_1.png" />
</figure>
<figure class="align-default">
<img alt="../_images/stm32_2.png" src="../_images/stm32_2.png" />
</figure>
<ul class="simple">
<li><p>如果使用 fsdev ip勾选 <strong>USB</strong> 。如果使用 dwc2 ip勾选 <strong>USB_OTG_FS</strong> 或者勾选 <strong>USB_OTG_HS</strong>。开启 USB 中断,其他配置对我们没用,代码中不会使用任何 st 的 usb 库。</p></li>
</ul>
<figure class="align-default">
<img alt="../_images/stm32_3_1.png" src="../_images/stm32_3_1.png" />
</figure>
<figure class="align-default">
<img alt="../_images/stm32_3_2.png" src="../_images/stm32_3_2.png" />
</figure>
<ul class="simple">
<li><p>配置 usb clock 为 48M</p></li>
</ul>
<figure class="align-default">
<img alt="../_images/stm32_4_1.png" src="../_images/stm32_4_1.png" />
</figure>
<figure class="align-default">
<img alt="../_images/stm32_4_2.png" src="../_images/stm32_4_2.png" />
</figure>
<ul class="simple">
<li><p>选择好工程,这里我们选择 keil设置好 stack 和 heap如果使用 msc 可以推荐设置大点,然后点击 <strong>Generate Code</strong></p></li>
</ul>
<figure class="align-default">
<img alt="../_images/stm32_5.png" src="../_images/stm32_5.png" />
</figure>
<ul class="simple">
<li><p>添加 CherryUSB 必须要的源码( <strong>usbd_core.c</strong><strong>dwc2/usb_dc_dwc2.c</strong> 或者是 <strong>fsdev/usb_dc_fsdev.c</strong> ,以及想要使用的 class 驱动,可以将对应的 class template 添加方便测试。</p></li>
</ul>
<figure class="align-default">
<img alt="../_images/stm32_6.png" src="../_images/stm32_6.png" />
</figure>
<ul class="simple">
<li><p>头文件该加的加</p></li>
</ul>
<figure class="align-default">
<img alt="../_images/stm32_7.png" src="../_images/stm32_7.png" />
</figure>
<ul class="simple">
<li><p>复制一份 <strong>cherryusb_config_template.h</strong>,放到 <cite>Core/Inc</cite> 目录下,并命名为 <cite>usb_config.h</cite></p></li>
</ul>
<figure class="align-default">
<img alt="../_images/stm32_8.png" src="../_images/stm32_8.png" />
</figure>
<ul class="simple">
<li><p>如果使用 fsdev ipV1.5.0 开始需要增加 <strong>fsdev/usb_glue_st.c</strong><cite>usb_config.h</cite> 中实现以下宏,具体数值不同芯片不一样:</p></li>
</ul>
<div class="highlight-C notranslate"><div class="highlight"><pre><span></span><span class="cp">#define CONFIG_USBDEV_FSDEV_PMA_ACCESS 2</span>
</pre></div>
</div>
<ul class="simple">
<li><p>编译器推荐使用 <strong>AC6</strong>。勾选 <strong>Microlib</strong>,并实现 <strong>printf</strong> ,方便后续查看 log。</p></li>
</ul>
<figure class="align-default">
<img alt="../_images/stm32_10.png" src="../_images/stm32_10.png" />
</figure>
<figure class="align-default">
<img alt="../_images/stm32_11.png" src="../_images/stm32_11.png" />
</figure>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>以下两个步骤从 V1.5.0 开始不再需要,<strong>fsdev/usb_glue_st.c</strong>, <strong>dwc2/usb_glue_st.c</strong> 文件中已经实现</p>
</div>
<ul class="simple">
<li><p>拷贝 <strong>xxx_msp.c</strong> 中的 <strong>HAL_PCD_MspInit</strong> 函数中的内容到 <strong>usb_dc_low_level_init</strong> 函数中,屏蔽 st 生成的 usb 初始化</p></li>
</ul>
<figure class="align-default">
<img alt="../_images/stm32_12.png" src="../_images/stm32_12.png" />
</figure>
<figure class="align-default">
<img alt="../_images/stm32_14.png" src="../_images/stm32_14.png" />
</figure>
<ul class="simple">
<li><p>在中断函数中调用 <cite>USBD_IRQHandler</cite>,并传入 <cite>busid</cite></p></li>
</ul>
<figure class="align-default">
<img alt="../_images/stm32_13.png" src="../_images/stm32_13.png" />
</figure>
<ul class="simple">
<li><p>如果芯片带 cachecache 修改参考 <a class="reference internal" href="transplant.html#usb-cache"><span class="std std-ref">cache 配置修改</span></a> 章节</p></li>
<li><p>调用 template 的内容初始化,并填入 <cite>busid</cite> 和 USB IP 的 <cite>reg base</cite> <cite>busid</cite> 从 0 开始,不能超过 <cite>CONFIG_USBDEV_MAX_BUS</cite></p></li>
</ul>
<figure class="align-default">
<img alt="../_images/stm32_15.png" src="../_images/stm32_15.png" />
</figure>
</section>
<section id="usb-host">
<h3>USB Host 移植要点<a class="headerlink" href="#usb-host" title="Link to this heading"></a></h3>
<p>前面 6 步与 Device 一样。需要注意host 驱动只支持带 dma 的 hs port (引脚是 PB14/PB15),所以 fs port (引脚是 PA11/PA12)不做支持(没有 dma 你玩什么主机)。</p>
<ul class="simple">
<li><p>添加 CherryUSB 必须要的源码( <strong>usbh_core.c</strong><strong>usbh_hub.c</strong><strong>usb_hc_dwc2.c</strong><strong>usb_glue_st.c</strong> 以及 <strong>osal</strong> 目录下的适配层文件),以及想要使用的 class 驱动,并且可以将对应的 <strong>usb host.c</strong> 添加方便测试。</p></li>
</ul>
<figure class="align-default">
<img alt="../_images/stm32_16.png" src="../_images/stm32_16.png" />
</figure>
<ul class="simple">
<li><p>编译器推荐使用 <strong>AC6</strong>。勾选 <strong>Microlib</strong>,并实现 <strong>printf</strong> ,方便后续查看 log。</p></li>
</ul>
<figure class="align-default">
<img alt="../_images/stm32_10.png" src="../_images/stm32_10.png" />
</figure>
<figure class="align-default">
<img alt="../_images/stm32_11.png" src="../_images/stm32_11.png" />
</figure>
<ul class="simple">
<li><p>复制一份 <strong>cherryusb_config_template.h</strong>,放到 <cite>Core/Inc</cite> 目录下,并命名为 <cite>usb_config.h</cite></p></li>
</ul>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>以下两个步骤从 V1.5.0 开始不再需要,<strong>fsdev/usb_glue_st.c</strong>, <strong>dwc2/usb_glue_st.c</strong> 文件中已经实现</p>
</div>
<ul class="simple">
<li><p>拷贝 <strong>xxx_msp.c</strong> 中的 <cite>HAL_HCD_MspInit</cite> 函数中的内容到 <cite>usb_hc_low_level_init</cite> 函数中,屏蔽 st 生成的 usb 初始化</p></li>
<li><p>在中断函数中调用 <cite>USBH_IRQHandler</cite>,并传入 <cite>busid</cite></p></li>
</ul>
<figure class="align-default">
<img alt="../_images/stm32_19.png" src="../_images/stm32_19.png" />
</figure>
<ul class="simple">
<li><p>链接脚本修改参考 <a class="reference internal" href="transplant.html#usbh-link-script"><span class="std std-ref">主机链接脚本修改</span></a> 章节</p></li>
<li><p>如果芯片带 cachecache 修改参考 <a class="reference internal" href="transplant.html#usb-cache"><span class="std std-ref">cache 配置修改</span></a> 章节</p></li>
<li><p>调用 <cite>usbh_initialize</cite> 并填入 <cite>busid</cite> 和 USB IP 的 <cite>reg base</cite> 还有 <cite>event_handler</cite> 可缺省为NULL <cite>busid</cite> 从 0 开始,不能超过 <cite>CONFIG_USBHOST_MAX_BUS</cite></p></li>
<li><p>启动线程</p></li>
</ul>
<figure class="align-default">
<img alt="../_images/stm32_18.png" src="../_images/stm32_18.png" />
</figure>
</section>
</section>
</section>
</div>
</div>
<footer><div class="rst-footer-buttons" role="navigation" aria-label="Footer">
<a href="start.html" class="btn btn-neutral float-left" title="入门必看" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
<a href="transplant.html" class="btn btn-neutral float-right" title="芯片通用移植指南" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
</div>
<hr/>
<div role="contentinfo">
<p>&#169; Copyright 2022 ~ 2026, sakumisu.</p>
</div>
Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a
<a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a>
provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script>
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>