Files
2018-09-03 15:09:46 +00:00

162 lines
14 KiB
HTML
Raw Permalink 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 lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="API documentation for the Rust `cortex_m_semihosting` crate."><meta name="keywords" content="rust, rustlang, rust-lang, cortex_m_semihosting"><title>cortex_m_semihosting - Rust</title><link rel="stylesheet" type="text/css" href="../normalize.css"><link rel="stylesheet" type="text/css" href="../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" type="text/css" href="../dark.css"><link rel="stylesheet" type="text/css" href="../light.css" id="themeStyle"><script src="../storage.js"></script></head><body class="rustdoc mod"><!--[if lte IE 8]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"><div class="sidebar-menu">&#9776;</div><p class='location'>Crate cortex_m_semihosting</p><div class="sidebar-elems"><div class="block items"><ul><li><a href="#modules">Modules</a></li><li><a href="#macros">Macros</a></li><li><a href="#functions">Functions</a></li></ul></div><p class='location'></p><script>window.sidebarCurrent = {name: 'cortex_m_semihosting', ty: 'mod', relpath: '../'};</script></div></nav><div class="theme-picker"><button id="theme-picker" aria-label="Pick another theme!"><img src="../brush.svg" width="18" alt="Pick another theme!"></button><div id="theme-choices"></div></div><script src="../theme.js"></script><nav class="sub"><form class="search-form js-only"><div class="search-container"><input class="search-input" name="search" autocomplete="off" placeholder="Click or press S to search, ? for more options…" type="search"><a id="settings-menu" href="../settings.html"><img src="../wheel.svg" width="18" alt="Change settings"></a></div></form></nav><section id="main" class="content"><h1 class='fqn'><span class='out-of-band'><span id='render-detail'><a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class='inner'>&#x2212;</span>]</a></span><a class='srclink' href='../src/cortex_m_semihosting/lib.rs.html#1-185' title='goto source code'>[src]</a></span><span class='in-band'>Crate <a class="mod" href=''>cortex_m_semihosting</a></span></h1><div class='docblock'><p>Semihosting for ARM Cortex-M processors</p>
<h1 id="what-is-semihosting" class="section-header"><a href="#what-is-semihosting">What is semihosting?</a></h1>
<p>&quot;Semihosting is a mechanism that enables code running on an ARM target to communicate and use
the Input/Output facilities on a host computer that is running a debugger.&quot; - ARM</p>
<h1 id="interface" class="section-header"><a href="#interface">Interface</a></h1>
<p>This crate provides implementations of
<a href="https://doc.rust-lang.org/core/fmt/trait.Write.html"><code>core::fmt::Write</code></a>, so you can use it,
in conjunction with
<a href="https://doc.rust-lang.org/core/macro.format_args.html"><code>core::format_args!</code></a> or the <a href="https://doc.rust-lang.org/core/macro.write.html"><code>write!</code> macro</a>, for user-friendly construction and printing of formatted strings.</p>
<p>Since semihosting operations are modeled as <a href="https://en.wikipedia.org/wiki/System_call">system calls</a>, this crate exposes an untyped
<code>syscall!</code> interface just like the <a href="https://crates.io/crates/sc"><code>sc</code></a> crate does.</p>
<h1 id="forewarning" class="section-header"><a href="#forewarning">Forewarning</a></h1>
<p>Semihosting operations are <em>very</em> slow. Like, each WRITE operation can take hundreds of
milliseconds.</p>
<h1 id="example" class="section-header"><a href="#example">Example</a></h1><h2 id="using-hiohstdout" class="section-header"><a href="#using-hiohstdout">Using <code>hio::HStdout</code></a></h2>
<p>This example will demonstrate how to print formatted strings.</p>
<pre class="rust rust-example-rendered">
<span class="kw">extern</span> <span class="kw">crate</span> <span class="ident">cortex_m_semihosting</span>;
<span class="kw">use</span> <span class="ident">cortex_m_semihosting</span>::<span class="ident">hio</span>;
<span class="kw">use</span> <span class="ident">core</span>::<span class="ident">fmt</span>::<span class="ident">Write</span>;
<span class="comment">// This function will be called by the application</span>
<span class="kw">fn</span> <span class="ident">print</span>() <span class="op">-&gt;</span> <span class="prelude-ty">Result</span><span class="op">&lt;</span>(), <span class="ident">core</span>::<span class="ident">fmt</span>::<span class="ident">Error</span><span class="op">&gt;</span> {
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">stdout</span> <span class="op">=</span> <span class="kw">match</span> <span class="ident">hio</span>::<span class="ident">hstdout</span>() {
<span class="prelude-val">Ok</span>(<span class="ident">fd</span>) <span class="op">=&gt;</span> <span class="ident">fd</span>,
<span class="prelude-val">Err</span>(()) <span class="op">=&gt;</span> <span class="kw">return</span> <span class="prelude-val">Err</span>(<span class="ident">core</span>::<span class="ident">fmt</span>::<span class="ident">Error</span>),
};
<span class="kw">let</span> <span class="ident">language</span> <span class="op">=</span> <span class="string">&quot;Rust&quot;</span>;
<span class="kw">let</span> <span class="ident">ranking</span> <span class="op">=</span> <span class="number">1</span>;
<span class="macro">write</span><span class="macro">!</span>(<span class="ident">stdout</span>, <span class="string">&quot;{} on embedded is #{}!&quot;</span>, <span class="ident">language</span>, <span class="ident">ranking</span>)<span class="question-mark">?</span>;
<span class="prelude-val">Ok</span>(())
}</pre>
<p>On the host side:</p>
<pre><code class="language-text">$ openocd -f $INTERFACE -f $TARGET -l /tmp/openocd.log
Open On-Chip Debugger 0.9.0 (2016-04-27-23:18)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
# the command will block at this point
</code></pre>
<p>The OpenOCD logs will be redirected to <code>/tmp/openocd.log</code>. You can view those logs in &quot;real
time&quot; using <code>tail</code></p>
<pre><code class="language-text">$ tail -f /tmp/openocd.log
Info : Unable to match requested speed 1000 kHz, using 950 kHz
Info : Unable to match requested speed 1000 kHz, using 950 kHz
Info : clock speed 950 kHz
Info : STLINK v1 JTAG v11 API v2 SWIM v0 VID 0x0483 PID 0x3744
Info : using stlink api v2
Info : nrf51.cpu: hardware has 4 breakpoints, 2 watchpoints
</code></pre>
<p>Alternatively you could omit the <code>-l</code> flag from the <code>openocd</code> call, and the <code>tail -f</code> command
but the OpenOCD output will have intermingled in it logs from its normal operation.</p>
<p>Then, we run the program:</p>
<pre><code class="language-text">$ arm-none-eabi-gdb hello-world
(gdb) # Connect to OpenOCD
(gdb) target remote :3333
(gdb) # Enable OpenOCD's semihosting support
(gdb) monitor arm semihosting enable
(gdb) # Flash the program
(gdb) load
(gdb) # Run the program
(gdb) continue
</code></pre>
<p>And you'll see the output under OpenOCD's terminal</p>
<pre><code class="language-text"># openocd -f $INTERFACE -f $TARGET -l /tmp/openocd.log
(..)
Rust on embedded is #1!
</code></pre>
<h2 id="using-the-syscall-interface" class="section-header"><a href="#using-the-syscall-interface">Using the syscall interface</a></h2>
<p>This example will show how to print &quot;Hello, world!&quot; on the host.</p>
<p>Target program:</p>
<pre class="rust rust-example-rendered">
<span class="kw">extern</span> <span class="kw">crate</span> <span class="ident">cortex_m_semihosting</span>;
<span class="comment">// This function will be called by the application</span>
<span class="kw">fn</span> <span class="ident">print</span>() {
<span class="comment">// File descriptor (on the host)</span>
<span class="kw">const</span> <span class="ident">STDOUT</span>: <span class="ident">usize</span> <span class="op">=</span> <span class="number">1</span>; <span class="comment">// NOTE the host stdout may not always be fd 1</span>
<span class="kw">static</span> <span class="ident">MSG</span>: <span class="kw-2">&amp;</span><span class="lifetime">&#39;static</span> [<span class="ident">u8</span>] <span class="op">=</span> <span class="string">b&quot;Hello, world!\n&quot;</span>;
<span class="comment">// Signature: fn write(fd: usize, ptr: *const u8, len: usize) -&gt; usize</span>
<span class="kw">let</span> <span class="ident">r</span> <span class="op">=</span> <span class="kw">unsafe</span> { <span class="macro">syscall</span><span class="macro">!</span>(<span class="ident">WRITE</span>, <span class="ident">STDOUT</span>, <span class="ident">MSG</span>.<span class="ident">as_ptr</span>(), <span class="ident">MSG</span>.<span class="ident">len</span>()) };
}</pre>
<p>Output and monitoring proceed as in the above example.</p>
<h1 id="optional-features" class="section-header"><a href="#optional-features">Optional features</a></h1><h2 id="inline-asm" class="section-header"><a href="#inline-asm"><code>inline-asm</code></a></h2>
<p>When this feature is enabled semihosting is implemented using inline assembly (<code>asm!</code>) and
compiling this crate requires nightly.</p>
<p>When this feature is disabled semihosting is implemented using FFI calls into an external
assembly file and compiling this crate works on stable and beta.</p>
<h1 id="reference" class="section-header"><a href="#reference">Reference</a></h1>
<p>For documentation about the semihosting operations, check:</p>
<p>'Chapter 8 - Semihosting' of the <a href="http://infocenter.arm.com/help/topic/com.arm.doc.dui0471e/DUI0471E_developing_for_arm_processors.pdf">'ARM Compiler toolchain Version 5.0'</a>
manual.</p>
</div><h2 id='modules' class='section-header'><a href="#modules">Modules</a></h2>
<table>
<tr class=' module-item'>
<td><a class="mod" href="debug/index.html"
title='mod cortex_m_semihosting::debug'>debug</a></td>
<td class='docblock-short'>
<p>Interacting with debugging agent</p>
</td>
</tr>
<tr class=' module-item'>
<td><a class="mod" href="hio/index.html"
title='mod cortex_m_semihosting::hio'>hio</a></td>
<td class='docblock-short'>
<p>Host I/O</p>
</td>
</tr>
<tr class=' module-item'>
<td><a class="mod" href="nr/index.html"
title='mod cortex_m_semihosting::nr'>nr</a></td>
<td class='docblock-short'>
<p>Semihosting operations</p>
</td>
</tr></table><h2 id='macros' class='section-header'><a href="#macros">Macros</a></h2>
<table>
<tr class=' module-item'>
<td><a class="macro" href="macro.syscall.html"
title='macro cortex_m_semihosting::syscall'>syscall</a></td>
<td class='docblock-short'>
<p>Variable argument version of <code>syscall</code></p>
</td>
</tr>
<tr class=' module-item'>
<td><a class="macro" href="macro.syscall1.html"
title='macro cortex_m_semihosting::syscall1'>syscall1</a></td>
<td class='docblock-short'>
<p>Macro version of <code>syscall1</code></p>
</td>
</tr></table><h2 id='functions' class='section-header'><a href="#functions">Functions</a></h2>
<table>
<tr class=' module-item'>
<td><a class="fn" href="fn.syscall.html"
title='fn cortex_m_semihosting::syscall'>syscall</a><a title='unsafe function' href='#'><sup></sup></a></td>
<td class='docblock-short'>
<p>Performs a semihosting operation, takes a pointer to an argument block</p>
</td>
</tr>
<tr class=' module-item'>
<td><a class="fn" href="fn.syscall1.html"
title='fn cortex_m_semihosting::syscall1'>syscall1</a><a title='unsafe function' href='#'><sup></sup></a></td>
<td class='docblock-short'>
<p>Performs a semihosting operation, takes one integer as an argument</p>
</td>
</tr></table></section><section id="search" class="content hidden"></section><section class="footer"></section><aside id="help" class="hidden"><div><h1 class="hidden">Help</h1><div class="shortcuts"><h2>Keyboard Shortcuts</h2><dl><dt><kbd>?</kbd></dt><dd>Show this help dialog</dd><dt><kbd>S</kbd></dt><dd>Focus the search field</dd><dt><kbd></kbd></dt><dd>Move up in search results</dd><dt><kbd></kbd></dt><dd>Move down in search results</dd><dt><kbd></kbd></dt><dd>Switch tab</dd><dt><kbd>&#9166;</kbd></dt><dd>Go to active search result</dd><dt><kbd>+</kbd></dt><dd>Expand all sections</dd><dt><kbd>-</kbd></dt><dd>Collapse all sections</dd></dl></div><div class="infos"><h2>Search Tricks</h2><p>Prefix searches with a type followed by a colon (e.g. <code>fn:</code>) to restrict the search to a given type.</p><p>Accepted types are: <code>fn</code>, <code>mod</code>, <code>struct</code>, <code>enum</code>, <code>trait</code>, <code>type</code>, <code>macro</code>, and <code>const</code>.</p><p>Search functions by type signature (e.g. <code>vec -> usize</code> or <code>* -> vec</code>)</p><p>Search multiple things at once by splitting your query with comma (e.g. <code>str,u8</code> or <code>String,struct:Vec,test</code>)</p></div></div></aside><script>window.rootPath = "../";window.currentCrate = "cortex_m_semihosting";</script><script src="../aliases.js"></script><script src="../main.js"></script><script defer src="../search-index.js"></script></body></html>