mirror of
https://github.com/pine64/bl_iot_sdk.git
synced 2024-09-03 21:49:43 +00:00
364 lines
20 KiB
HTML
364 lines
20 KiB
HTML
|
||
|
||
<!DOCTYPE html>
|
||
<html class="writer-html5" lang="zh" >
|
||
<head>
|
||
<meta charset="utf-8">
|
||
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
|
||
<title>4. UART_echo — BL602 IoT SDK release_bl_iot_sdk_1.6.11-1-g66bb28da 文档</title>
|
||
|
||
|
||
|
||
<link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" />
|
||
<link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
|
||
<link rel="stylesheet" href="../../_static/style.css" type="text/css" />
|
||
<link rel="stylesheet" href="../../_static/css/custom.css" type="text/css" />
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
<!--[if lt IE 9]>
|
||
<script src="../../_static/js/html5shiv.min.js"></script>
|
||
<![endif]-->
|
||
|
||
|
||
<script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script>
|
||
<script src="../../_static/jquery.js"></script>
|
||
<script src="../../_static/underscore.js"></script>
|
||
<script src="../../_static/doctools.js"></script>
|
||
<script src="../../_static/language_data.js"></script>
|
||
|
||
<script type="text/javascript" src="../../_static/js/theme.js"></script>
|
||
|
||
|
||
<link rel="index" title="索引" href="../../genindex.html" />
|
||
<link rel="search" title="搜索" href="../../search.html" />
|
||
<link rel="next" title="5. UART_ioctl" href="../demo_peripherals_uart_ioctl/uart_ioctl.html" />
|
||
<link rel="prev" title="3. GPIO" href="../demo_peripherals_gpio/GPIO.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" alt="Documentation Home"> BL602 IoT SDK
|
||
|
||
|
||
|
||
</a>
|
||
|
||
|
||
|
||
|
||
<div class="version">
|
||
release_bl_iot_sdk_1.6.11-1-g66bb28da
|
||
</div>
|
||
|
||
|
||
|
||
|
||
<div role="search">
|
||
<form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
|
||
<input type="text" name="q" placeholder="在文档中搜索" />
|
||
<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="main navigation">
|
||
|
||
|
||
|
||
|
||
|
||
|
||
<p class="caption"><span class="caption-text">Developer_Environment</span></p>
|
||
<ul>
|
||
<li class="toctree-l1"><a class="reference internal" href="../../Developer_Environment/Developer_Environment.html">1. Developer Environment</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="../../Developer_Environment/BLFlashEnv/BLFlashEnv.html">2. BLFlashEnv</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="../../Developer_Environment/freedom_studio/freedom_studio.html">3. Freedom Studio</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="../../Developer_Environment/eclipse/eclipse.html">4. Eclipse</a></li>
|
||
</ul>
|
||
<p class="caption"><span class="caption-text">Examples</span></p>
|
||
<ul class="current">
|
||
<li class="toctree-l1"><a class="reference internal" href="../helloworld/helloworld.html">1. Helloword</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="../demo_aws/aws.html">2. aws</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="../demo_peripherals_gpio/GPIO.html">3. GPIO</a></li>
|
||
<li class="toctree-l1 current"><a class="current reference internal" href="#">4. UART_echo</a><ul>
|
||
<li class="toctree-l2"><a class="reference internal" href="#id1">4.1. 总览</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="#id2">4.2. 准备及使用步骤</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="#id3">4.3. 应用实例</a></li>
|
||
</ul>
|
||
</li>
|
||
<li class="toctree-l1"><a class="reference internal" href="../demo_peripherals_uart_ioctl/uart_ioctl.html">5. UART_ioctl</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="../demo_protocols_http/http.html">6. Http client</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="../demo_protocols_httpc/httpc.html">7. Httpc client</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="../demo_storage_psm/psm.html">8. PSM</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="../demo_storage_romfs/romfs.html">9. Romfs</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="../demo_system_cli/cli.html">10. cli</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="../demo_system_fdt/fdt.html">11. FDT</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="../demo_wifi/wifi.html">12. WiFi</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="../demo_ble/ble.html">13. BLE</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="../demo_mesh/mesh.html">14. Mesh</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="../demo_blsync_ble/blsync_ble.html">15. BLSYNC-BLE</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="../sdk_app_easyflash_boottimes/easyflash_boottimes.html">16. Easyflash4 boot times</a></li>
|
||
</ul>
|
||
<p class="caption"><span class="caption-text">Components</span></p>
|
||
<ul>
|
||
<li class="toctree-l1"><a class="reference internal" href="../../Components/arch.html">1. arch</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="../../Components/Command_line/helper.html">2. helper</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="../../Components/Command_line/aos_cli.html">3. cli</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="../../Components/Hal_drv/gpio.html">4. GPIO</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="../../Components/Middleware/bloop/bloop.html">5. BLOOP</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="../../Components/Middleware/blsync/blsync.html">6. BLSYNC</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="../../Components/Middleware/dts/devicetree.html">7. device tree</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="../../Components/Middleware/log/blog.html">8. blog</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="../../Components/Middleware/security/security.html">9. Security</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="../../Components/Middleware/vfs/vfs.html">10. AOS VFS</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="../../Components/Middleware/yloop/yloop.html">11. yloop</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="../../Components/Network/httpc/httpc.html">12. HTTPC</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="../../Components/Network/https/https.html">13. HTTPS</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="../../Components/Network/tls/tls.html">14. TLS</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="../../Components/BLE/provision_WiFi/provision_WiFi.html">15. Provision_WiFi</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="../../Components/BLE/mesh/mesh.html">16. Mesh</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="../../Components/BLE/ble_stack/ble_stack.html">17. BLE</a></li>
|
||
</ul>
|
||
<p class="caption"><span class="caption-text">API</span></p>
|
||
<ul>
|
||
<li class="toctree-l1"><a class="reference internal" href="../../API/sys/cronalarms.html">1. cronalarms</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="../../API/wifi/wifi_mgmr.html">2. Wi-Fi Manager</a></li>
|
||
</ul>
|
||
|
||
|
||
|
||
</div>
|
||
|
||
</div>
|
||
</nav>
|
||
|
||
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
|
||
|
||
|
||
<nav class="wy-nav-top" aria-label="top navigation">
|
||
|
||
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
|
||
<a href="../../index.html">BL602 IoT SDK</a>
|
||
|
||
</nav>
|
||
|
||
|
||
<div class="wy-nav-content">
|
||
|
||
<div class="rst-content">
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
<div role="navigation" aria-label="breadcrumbs navigation">
|
||
|
||
<ul class="wy-breadcrumbs">
|
||
|
||
<li><a href="../../index.html" class="icon icon-home"></a> »</li>
|
||
|
||
<li><span class="section-number">4. </span>UART_echo</li>
|
||
|
||
|
||
<li class="wy-breadcrumbs-aside">
|
||
|
||
|
||
<a href="../../_sources/Examples/demo_peripherals_uart_echo/uart_echo.rst.txt" rel="nofollow"> 查看页面源码</a>
|
||
|
||
|
||
</li>
|
||
|
||
</ul>
|
||
|
||
|
||
<hr/>
|
||
</div>
|
||
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
|
||
<div itemprop="articleBody">
|
||
|
||
<div class="section" id="uart-echo">
|
||
<span id="uart-echo-index"></span><h1><span class="section-number">4. </span>UART_echo<a class="headerlink" href="#uart-echo" title="永久链接至标题">¶</a></h1>
|
||
<div class="section" id="id1">
|
||
<h2><span class="section-number">4.1. </span>总览<a class="headerlink" href="#id1" title="永久链接至标题">¶</a></h2>
|
||
<p>本示例主要介绍通过UART1将收到的数据回传给发送方的过程。</p>
|
||
</div>
|
||
<div class="section" id="id2">
|
||
<h2><span class="section-number">4.2. </span>准备及使用步骤<a class="headerlink" href="#id2" title="永久链接至标题">¶</a></h2>
|
||
<ul class="simple">
|
||
<li><p>使用之前需要准备一个 <code class="docutils literal notranslate"><span class="pre">USB转TTL</span></code> 串口线,并配置SDK目录下 <code class="docutils literal notranslate"><span class="pre">bl_iot_sdk/tools/flash_tool/bl602/device_tree/bl_factory_params_evb_40M.dts</span></code> 文件中的 <code class="docutils literal notranslate"><span class="pre">uart</span></code> ,具体配置可以参考本例。</p></li>
|
||
</ul>
|
||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">uart</span> <span class="p">{</span>
|
||
<span class="c1">#address-cells = <1>;</span>
|
||
<span class="c1">#size-cells = <1>;</span>
|
||
<span class="n">uart</span><span class="nd">@4000A000</span> <span class="p">{</span>
|
||
<span class="n">status</span> <span class="o">=</span> <span class="s2">"okay"</span><span class="p">;</span>
|
||
<span class="nb">id</span> <span class="o">=</span> <span class="o"><</span><span class="mi">0</span><span class="o">></span><span class="p">;</span>
|
||
<span class="n">compatible</span> <span class="o">=</span> <span class="s2">"bl602_uart"</span><span class="p">;</span>
|
||
<span class="n">path</span> <span class="o">=</span> <span class="s2">"/dev/ttyS0"</span><span class="p">;</span>
|
||
<span class="n">baudrate</span> <span class="o">=</span> <span class="o"><</span><span class="mi">2000000</span><span class="o">></span><span class="p">;</span>
|
||
<span class="n">pin</span> <span class="p">{</span>
|
||
<span class="n">rx</span> <span class="o">=</span> <span class="o"><</span><span class="mi">7</span><span class="o">></span><span class="p">;</span>
|
||
<span class="n">tx</span> <span class="o">=</span> <span class="o"><</span><span class="mi">16</span><span class="o">></span><span class="p">;</span>
|
||
<span class="p">};</span>
|
||
<span class="n">feature</span> <span class="p">{</span>
|
||
<span class="n">tx</span> <span class="o">=</span> <span class="s2">"okay"</span><span class="p">;</span>
|
||
<span class="n">rx</span> <span class="o">=</span> <span class="s2">"okay"</span><span class="p">;</span>
|
||
<span class="n">cts</span> <span class="o">=</span> <span class="s2">"disable"</span><span class="p">;</span>
|
||
<span class="n">rts</span> <span class="o">=</span> <span class="s2">"disable"</span><span class="p">;</span>
|
||
<span class="p">};</span>
|
||
<span class="p">};</span>
|
||
<span class="n">uart</span><span class="nd">@4000A100</span> <span class="p">{</span>
|
||
<span class="n">status</span> <span class="o">=</span> <span class="s2">"okay"</span><span class="p">;</span>
|
||
<span class="nb">id</span> <span class="o">=</span> <span class="o"><</span><span class="mi">1</span><span class="o">></span><span class="p">;</span>
|
||
<span class="n">compatible</span> <span class="o">=</span> <span class="s2">"bl602_uart"</span><span class="p">;</span>
|
||
<span class="n">path</span> <span class="o">=</span> <span class="s2">"/dev/ttyS1"</span><span class="p">;</span>
|
||
<span class="n">baudrate</span> <span class="o">=</span> <span class="o"><</span><span class="mi">115200</span><span class="o">></span><span class="p">;</span>
|
||
<span class="n">pin</span> <span class="p">{</span>
|
||
<span class="n">rx</span> <span class="o">=</span> <span class="o"><</span><span class="mi">3</span><span class="o">></span><span class="p">;</span>
|
||
<span class="n">tx</span> <span class="o">=</span> <span class="o"><</span><span class="mi">4</span><span class="o">></span><span class="p">;</span>
|
||
<span class="p">};</span>
|
||
<span class="n">feature</span> <span class="p">{</span>
|
||
<span class="n">tx</span> <span class="o">=</span> <span class="s2">"okay"</span><span class="p">;</span>
|
||
<span class="n">rx</span> <span class="o">=</span> <span class="s2">"okay"</span><span class="p">;</span>
|
||
<span class="n">cts</span> <span class="o">=</span> <span class="s2">"disable"</span><span class="p">;</span>
|
||
<span class="n">rts</span> <span class="o">=</span> <span class="s2">"disable"</span><span class="p">;</span>
|
||
<span class="p">};</span>
|
||
<span class="p">};</span>
|
||
<span class="p">};</span>
|
||
</pre></div>
|
||
</div>
|
||
<ul class="simple">
|
||
<li><p>使用步骤:</p></li>
|
||
</ul>
|
||
<blockquote>
|
||
<div><ul class="simple">
|
||
<li><p>将板子的 <code class="docutils literal notranslate"><span class="pre">gpio3</span></code> 和 <code class="docutils literal notranslate"><span class="pre">gpio4</span></code> 和 <code class="docutils literal notranslate"><span class="pre">GND</span></code> 分别与 <code class="docutils literal notranslate"><span class="pre">USB转TTL</span></code> 串口线的 <code class="docutils literal notranslate"><span class="pre">TXD</span></code> 、 <code class="docutils literal notranslate"><span class="pre">RXD</span></code> 、 <code class="docutils literal notranslate"><span class="pre">GND</span></code> 分别连接起来;</p></li>
|
||
<li><p>编译 <code class="docutils literal notranslate"><span class="pre">customer_app/sdk_app_uart_echo</span></code> 工程并下载工程;</p></li>
|
||
<li><p>打开一个串口终端窗口A(波特率为115200,用于接收和发送uart消息),打开另一个串口终端窗口B(波特率为2000000,用于打印log)。板子上电可以看到窗口A接收到 <code class="docutils literal notranslate"><span class="pre">1234567890abcdefg</span></code> ,窗口B打印的log 停止在 <code class="docutils literal notranslate"><span class="pre">send</span> <span class="pre">case</span></code> 处,在A窗口中输入 <code class="docutils literal notranslate"><span class="pre">1234567890abcdefg</span></code> (没有回显)可以在B串口看到 <code class="docutils literal notranslate"><span class="pre">recv</span> <span class="pre">case</span></code> 和 <code class="docutils literal notranslate"><span class="pre">end</span></code> 的消息,此时说明演示成功。</p></li>
|
||
</ul>
|
||
</div></blockquote>
|
||
<div class="figure align-default">
|
||
<img alt="" src="../../_images/image114.png" />
|
||
</div>
|
||
<div class="figure align-default">
|
||
<img alt="" src="../../_images/image213.png" />
|
||
</div>
|
||
</div>
|
||
<div class="section" id="id3">
|
||
<h2><span class="section-number">4.3. </span>应用实例<a class="headerlink" href="#id3" title="永久链接至标题">¶</a></h2>
|
||
<ul class="simple">
|
||
<li><p>调用 <code class="docutils literal notranslate"><span class="pre">aos_write()</span></code> 接口通过UART1给终端发送数据,并等待终端返回接收到的数据,如接收与发送的数据一致,则log口将打印UART1中收发的消息内容。</p></li>
|
||
</ul>
|
||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">aos_write</span><span class="p">(</span><span class="n">fd</span><span class="p">,</span> <span class="n">send_recv_log</span><span class="p">,</span> <span class="n">strlen</span><span class="p">(</span><span class="n">send_recv_log</span><span class="p">));</span>
|
||
<span class="n">log_step</span><span class="p">(</span><span class="n">ci_table_step_send</span><span class="p">);</span>
|
||
|
||
<span class="k">while</span> <span class="p">(</span><span class="mi">1</span><span class="p">)</span> <span class="p">{</span>
|
||
<span class="n">length</span> <span class="o">=</span> <span class="n">aos_read</span><span class="p">(</span><span class="n">fd</span><span class="p">,</span> <span class="n">buf_recv</span><span class="p">,</span> <span class="n">strlen</span><span class="p">(</span><span class="n">send_recv_log</span><span class="p">));</span>
|
||
<span class="k">if</span> <span class="p">(</span><span class="n">length</span> <span class="o">!=</span> <span class="n">strlen</span><span class="p">(</span><span class="n">send_recv_log</span><span class="p">))</span> <span class="p">{</span>
|
||
<span class="k">continue</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
<span class="k">if</span> <span class="p">(</span><span class="n">memcmp</span><span class="p">(</span><span class="n">buf_recv</span><span class="p">,</span> <span class="n">send_recv_log</span><span class="p">,</span> <span class="n">strlen</span><span class="p">(</span><span class="n">send_recv_log</span><span class="p">))</span> <span class="o">==</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span>
|
||
<span class="n">printf</span><span class="p">(</span><span class="s2">"recvbuff:</span><span class="si">%s</span><span class="se">\r\n</span><span class="s2">"</span><span class="p">,</span> <span class="n">send_recv_log</span><span class="p">);</span>
|
||
<span class="n">log_step</span><span class="p">(</span><span class="n">ci_table_step_recv</span><span class="p">);</span>
|
||
<span class="k">break</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
<span class="n">vTaskDelay</span><span class="p">(</span><span class="mi">10</span><span class="p">);</span>
|
||
<span class="p">}</span>
|
||
<span class="n">log_step</span><span class="p">(</span><span class="n">ci_table_step_end</span><span class="p">);</span>
|
||
</pre></div>
|
||
</div>
|
||
<ul class="simple">
|
||
<li><p>在 <code class="docutils literal notranslate"><span class="pre">customer_app/sdk_app_uart_echo/sdk_app_uart_echo/main.c</span></code> 中 <code class="docutils literal notranslate"><span class="pre">static</span> <span class="pre">void</span> <span class="pre">aos_loop_proc(void</span> <span class="pre">*pvParameters)</span></code> 函数里调用ci_loop_proc()函数创建 <code class="docutils literal notranslate"><span class="pre">uart_echo</span></code> 的任务。</p></li>
|
||
</ul>
|
||
</div>
|
||
</div>
|
||
|
||
|
||
</div>
|
||
|
||
</div>
|
||
<footer>
|
||
|
||
<div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
|
||
|
||
<a href="../demo_peripherals_uart_ioctl/uart_ioctl.html" class="btn btn-neutral float-right" title="5. UART_ioctl" accesskey="n" rel="next">下一页 <span class="fa fa-arrow-circle-right"></span></a>
|
||
|
||
|
||
<a href="../demo_peripherals_gpio/GPIO.html" class="btn btn-neutral float-left" title="3. GPIO" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> 上一页</a>
|
||
|
||
</div>
|
||
|
||
|
||
<hr/>
|
||
|
||
<div role="contentinfo">
|
||
<p>
|
||
|
||
© 版权所有 2020, Bouffalo Lab
|
||
|
||
</p>
|
||
</div>
|
||
|
||
|
||
|
||
利用 <a href="http://sphinx-doc.org/">Sphinx</a> 构建,使用了
|
||
|
||
<a href="https://github.com/rtfd/sphinx_rtd_theme">主题</a>
|
||
|
||
由 <a href="https://readthedocs.org">Read the Docs</a>开发.
|
||
|
||
</footer>
|
||
|
||
</div>
|
||
</div>
|
||
|
||
</section>
|
||
|
||
</div>
|
||
|
||
|
||
<script type="text/javascript">
|
||
jQuery(function () {
|
||
SphinxRtdTheme.Navigation.enable(true);
|
||
});
|
||
</script>
|
||
|
||
|
||
|
||
|
||
|
||
|
||
</body>
|
||
</html> |