Update documentation

This commit is contained in:
Travis CI User
2018-09-03 15:09:46 +00:00
commit 0c3bcdf02a
505 changed files with 21158 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
<!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="List of all items in this crate"><meta name="keywords" content="rust, rustlang, rust-lang"><title>List of all items in this crate</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></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>
</span>
<span class='in-band'>List of all items</span></h1></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_quickstart";</script><script src="../aliases.js"></script><script src="../main.js"></script><script defer src="../search-index.js"></script></body></html>

View File

@@ -0,0 +1,65 @@
<!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 `_0_minimal` mod in crate `cortex_m_quickstart`."><meta name="keywords" content="rust, rustlang, rust-lang, _0_minimal"><title>cortex_m_quickstart::examples::_0_minimal - 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'>Module _0_minimal</p><div class="sidebar-elems"><p class='location'><a href='../../index.html'>cortex_m_quickstart</a>::<wbr><a href='../index.html'>examples</a></p><script>window.sidebarCurrent = {name: '_0_minimal', ty: 'mod', relpath: '../'};</script><script defer src="../sidebar-items.js"></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_quickstart/examples/_0_minimal.rs.html#1-66' title='goto source code'>[src]</a></span><span class='in-band'>Module <a href='../../index.html'>cortex_m_quickstart</a>::<wbr><a href='../index.html'>examples</a>::<wbr><a class="mod" href=''>_0_minimal</a></span></h1><div class='docblock'><p>Minimal Cortex-M program</p>
<p>When executed this program will hit the breakpoint set in <code>main</code>.</p>
<p>All Cortex-M programs need to:</p>
<ul>
<li>
<p>Contain the <code>#![no_main]</code> and <code>#![no_std]</code> attributes. Embedded programs don't use the
standard Rust <code>main</code> interface or the Rust standard (<code>std</code>) library.</p>
</li>
<li>
<p>Define their entry point using <a href="https://docs.rs/cortex-m-rt/%7E0.5/cortex_m_rt/macro.entry.html"><code>entry!</code></a> macro.</p>
</li>
</ul>
<ul>
<li>Define their panicking behavior, i.e. what happens when <code>panic!</code> is called. The easiest way to
define a panicking behavior is to link to a <a href="https://crates.io/keywords/panic-impl">panic handler crate</a></li>
</ul>
<ul>
<li>Define the <code>HardFault</code> handler using the <a href="https://docs.rs/cortex-m-rt/%7E0.5/cortex_m_rt/macro..html"><code>exception!</code></a> macro. This handler (function) is
called when a hard fault exception is raised by the hardware.</li>
</ul>
<ul>
<li>Define a default handler using the <a href="https://docs.rs/cortex-m-rt/%7E0.5/cortex_m_rt/macro..html"><code>exception!</code></a> macro. This function will be used to handle
all interrupts and exceptions which have not been assigned a specific handler.</li>
</ul>
<pre class="rust rust-example-rendered">
<span class="attribute">#![<span class="ident">no_main</span>]</span> <span class="comment">// &lt;- IMPORTANT!</span>
<span class="attribute">#![<span class="ident">no_std</span>]</span>
<span class="kw">extern</span> <span class="kw">crate</span> <span class="ident">cortex_m</span>;
<span class="attribute">#[<span class="ident">macro_use</span>(<span class="ident">entry</span>, <span class="ident">exception</span>)]</span>
<span class="kw">extern</span> <span class="kw">crate</span> <span class="ident">cortex_m_rt</span> <span class="kw">as</span> <span class="ident">rt</span>;
<span class="comment">// makes `panic!` print messages to the host stderr using semihosting</span>
<span class="kw">extern</span> <span class="kw">crate</span> <span class="ident">panic_semihosting</span>;
<span class="kw">use</span> <span class="ident">cortex_m</span>::<span class="ident">asm</span>;
<span class="kw">use</span> <span class="ident">rt</span>::<span class="ident">ExceptionFrame</span>;
<span class="comment">// the program entry point is ...</span>
<span class="macro">entry</span><span class="macro">!</span>(<span class="ident">main</span>);
<span class="comment">// ... this never ending function</span>
<span class="kw">fn</span> <span class="ident">main</span>() <span class="op">-&gt;</span> <span class="op">!</span> {
<span class="kw">loop</span> {
<span class="ident">asm</span>::<span class="ident">bkpt</span>();
}
}
<span class="comment">// define the hard fault handler</span>
<span class="macro">exception</span><span class="macro">!</span>(<span class="ident">HardFault</span>, <span class="ident">hard_fault</span>);
<span class="kw">fn</span> <span class="ident">hard_fault</span>(<span class="ident">ef</span>: <span class="kw-2">&amp;</span><span class="ident">ExceptionFrame</span>) <span class="op">-&gt;</span> <span class="op">!</span> {
<span class="macro">panic</span><span class="macro">!</span>(<span class="string">&quot;HardFault at {:#?}&quot;</span>, <span class="ident">ef</span>);
}
<span class="comment">// define the default exception handler</span>
<span class="macro">exception</span><span class="macro">!</span>(<span class="kw-2">*</span>, <span class="ident">default_handler</span>);
<span class="kw">fn</span> <span class="ident">default_handler</span>(<span class="ident">irqn</span>: <span class="ident">i16</span>) {
<span class="macro">panic</span><span class="macro">!</span>(<span class="string">&quot;Unhandled exception (IRQn = {})&quot;</span>, <span class="ident">irqn</span>);
}</pre>
</div></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_quickstart";</script><script src="../../../aliases.js"></script><script src="../../../main.js"></script><script defer src="../../../search-index.js"></script></body></html>

View File

@@ -0,0 +1 @@
initSidebarItems({});

View File

@@ -0,0 +1,39 @@
<!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 `_1_hello` mod in crate `cortex_m_quickstart`."><meta name="keywords" content="rust, rustlang, rust-lang, _1_hello"><title>cortex_m_quickstart::examples::_1_hello - 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'>Module _1_hello</p><div class="sidebar-elems"><p class='location'><a href='../../index.html'>cortex_m_quickstart</a>::<wbr><a href='../index.html'>examples</a></p><script>window.sidebarCurrent = {name: '_1_hello', ty: 'mod', relpath: '../'};</script><script defer src="../sidebar-items.js"></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_quickstart/examples/_1_hello.rs.html#1-40' title='goto source code'>[src]</a></span><span class='in-band'>Module <a href='../../index.html'>cortex_m_quickstart</a>::<wbr><a href='../index.html'>examples</a>::<wbr><a class="mod" href=''>_1_hello</a></span></h1><div class='docblock'><p>Prints &quot;Hello, world!&quot; on the OpenOCD console using semihosting</p>
<hr />
<pre class="rust rust-example-rendered">
<span class="attribute">#![<span class="ident">no_main</span>]</span>
<span class="attribute">#![<span class="ident">no_std</span>]</span>
<span class="attribute">#[<span class="ident">macro_use</span>]</span>
<span class="kw">extern</span> <span class="kw">crate</span> <span class="ident">cortex_m_rt</span> <span class="kw">as</span> <span class="ident">rt</span>;
<span class="kw">extern</span> <span class="kw">crate</span> <span class="ident">cortex_m_semihosting</span> <span class="kw">as</span> <span class="ident">sh</span>;
<span class="kw">extern</span> <span class="kw">crate</span> <span class="ident">panic_semihosting</span>;
<span class="kw">use</span> <span class="ident">core</span>::<span class="ident">fmt</span>::<span class="ident">Write</span>;
<span class="kw">use</span> <span class="ident">rt</span>::<span class="ident">ExceptionFrame</span>;
<span class="kw">use</span> <span class="ident">sh</span>::<span class="ident">hio</span>;
<span class="macro">entry</span><span class="macro">!</span>(<span class="ident">main</span>);
<span class="kw">fn</span> <span class="ident">main</span>() <span class="op">-&gt;</span> <span class="op">!</span> {
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">stdout</span> <span class="op">=</span> <span class="ident">hio</span>::<span class="ident">hstdout</span>().<span class="ident">unwrap</span>();
<span class="macro">writeln</span><span class="macro">!</span>(<span class="ident">stdout</span>, <span class="string">&quot;Hello, world!&quot;</span>).<span class="ident">unwrap</span>();
<span class="kw">loop</span> {}
}
<span class="macro">exception</span><span class="macro">!</span>(<span class="ident">HardFault</span>, <span class="ident">hard_fault</span>);
<span class="kw">fn</span> <span class="ident">hard_fault</span>(<span class="ident">ef</span>: <span class="kw-2">&amp;</span><span class="ident">ExceptionFrame</span>) <span class="op">-&gt;</span> <span class="op">!</span> {
<span class="macro">panic</span><span class="macro">!</span>(<span class="string">&quot;HardFault at {:#?}&quot;</span>, <span class="ident">ef</span>);
}
<span class="macro">exception</span><span class="macro">!</span>(<span class="kw-2">*</span>, <span class="ident">default_handler</span>);
<span class="kw">fn</span> <span class="ident">default_handler</span>(<span class="ident">irqn</span>: <span class="ident">i16</span>) {
<span class="macro">panic</span><span class="macro">!</span>(<span class="string">&quot;Unhandled exception (IRQn = {})&quot;</span>, <span class="ident">irqn</span>);
}</pre>
</div></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_quickstart";</script><script src="../../../aliases.js"></script><script src="../../../main.js"></script><script defer src="../../../search-index.js"></script></body></html>

View File

@@ -0,0 +1 @@
initSidebarItems({});

View File

@@ -0,0 +1,50 @@
<!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 `_2_itm` mod in crate `cortex_m_quickstart`."><meta name="keywords" content="rust, rustlang, rust-lang, _2_itm"><title>cortex_m_quickstart::examples::_2_itm - 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'>Module _2_itm</p><div class="sidebar-elems"><p class='location'><a href='../../index.html'>cortex_m_quickstart</a>::<wbr><a href='../index.html'>examples</a></p><script>window.sidebarCurrent = {name: '_2_itm', ty: 'mod', relpath: '../'};</script><script defer src="../sidebar-items.js"></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_quickstart/examples/_2_itm.rs.html#1-57' title='goto source code'>[src]</a></span><span class='in-band'>Module <a href='../../index.html'>cortex_m_quickstart</a>::<wbr><a href='../index.html'>examples</a>::<wbr><a class="mod" href=''>_2_itm</a></span></h1><div class='docblock'><p>Sends &quot;Hello, world!&quot; through the ITM port 0</p>
<p>ITM is much faster than semihosting. Like 4 orders of magnitude or so.</p>
<p><strong>NOTE</strong> Cortex-M0 chips don't support ITM.</p>
<p>You'll have to connect the microcontroller's SWO pin to the SWD interface. Note that some
development boards don't provide this option.</p>
<p>You'll need <a href="https://docs.rs/itm/0.2.1/itm/"><code>itmdump</code></a> to receive the message on the host plus you'll need to uncomment two
<code>monitor</code> commands in the <code>.gdbinit</code> file.</p>
<hr />
<pre class="rust rust-example-rendered">
<span class="attribute">#![<span class="ident">no_main</span>]</span>
<span class="attribute">#![<span class="ident">no_std</span>]</span>
<span class="attribute">#[<span class="ident">macro_use</span>]</span>
<span class="kw">extern</span> <span class="kw">crate</span> <span class="ident">cortex_m</span>;
<span class="attribute">#[<span class="ident">macro_use</span>]</span>
<span class="kw">extern</span> <span class="kw">crate</span> <span class="ident">cortex_m_rt</span> <span class="kw">as</span> <span class="ident">rt</span>;
<span class="kw">extern</span> <span class="kw">crate</span> <span class="ident">panic_semihosting</span>;
<span class="kw">use</span> <span class="ident">cortex_m</span>::{<span class="ident">asm</span>, <span class="ident">Peripherals</span>};
<span class="kw">use</span> <span class="ident">rt</span>::<span class="ident">ExceptionFrame</span>;
<span class="macro">entry</span><span class="macro">!</span>(<span class="ident">main</span>);
<span class="kw">fn</span> <span class="ident">main</span>() <span class="op">-&gt;</span> <span class="op">!</span> {
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">p</span> <span class="op">=</span> <span class="ident">Peripherals</span>::<span class="ident">take</span>().<span class="ident">unwrap</span>();
<span class="kw">let</span> <span class="ident">stim</span> <span class="op">=</span> <span class="kw-2">&amp;</span><span class="kw-2">mut</span> <span class="ident">p</span>.<span class="ident">ITM</span>.<span class="ident">stim</span>[<span class="number">0</span>];
<span class="macro">iprintln</span><span class="macro">!</span>(<span class="ident">stim</span>, <span class="string">&quot;Hello, world!&quot;</span>);
<span class="kw">loop</span> {
<span class="ident">asm</span>::<span class="ident">bkpt</span>();
}
}
<span class="comment">// define the hard fault handler</span>
<span class="macro">exception</span><span class="macro">!</span>(<span class="ident">HardFault</span>, <span class="ident">hard_fault</span>);
<span class="kw">fn</span> <span class="ident">hard_fault</span>(<span class="ident">ef</span>: <span class="kw-2">&amp;</span><span class="ident">ExceptionFrame</span>) <span class="op">-&gt;</span> <span class="op">!</span> {
<span class="macro">panic</span><span class="macro">!</span>(<span class="string">&quot;HardFault at {:#?}&quot;</span>, <span class="ident">ef</span>);
}
<span class="comment">// define the default exception handler</span>
<span class="macro">exception</span><span class="macro">!</span>(<span class="kw-2">*</span>, <span class="ident">default_handler</span>);
<span class="kw">fn</span> <span class="ident">default_handler</span>(<span class="ident">irqn</span>: <span class="ident">i16</span>) {
<span class="macro">panic</span><span class="macro">!</span>(<span class="string">&quot;Unhandled exception (IRQn = {})&quot;</span>, <span class="ident">irqn</span>);
}</pre>
</div></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_quickstart";</script><script src="../../../aliases.js"></script><script src="../../../main.js"></script><script defer src="../../../search-index.js"></script></body></html>

View File

@@ -0,0 +1 @@
initSidebarItems({});

View File

@@ -0,0 +1,42 @@
<!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 `_3_panic` mod in crate `cortex_m_quickstart`."><meta name="keywords" content="rust, rustlang, rust-lang, _3_panic"><title>cortex_m_quickstart::examples::_3_panic - 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'>Module _3_panic</p><div class="sidebar-elems"><p class='location'><a href='../../index.html'>cortex_m_quickstart</a>::<wbr><a href='../index.html'>examples</a></p><script>window.sidebarCurrent = {name: '_3_panic', ty: 'mod', relpath: '../'};</script><script defer src="../sidebar-items.js"></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_quickstart/examples/_3_panic.rs.html#1-46' title='goto source code'>[src]</a></span><span class='in-band'>Module <a href='../../index.html'>cortex_m_quickstart</a>::<wbr><a href='../index.html'>examples</a>::<wbr><a class="mod" href=''>_3_panic</a></span></h1><div class='docblock'><p>Changing the panic handler</p>
<p>The easiest way to change the panic handler is to use a different <a href="https://crates.io/keywords/panic-impl">panic handler crate</a>.</p>
<hr />
<pre class="rust rust-example-rendered">
<span class="attribute">#![<span class="ident">no_main</span>]</span>
<span class="attribute">#![<span class="ident">no_std</span>]</span>
<span class="attribute">#[<span class="ident">macro_use</span>]</span>
<span class="kw">extern</span> <span class="kw">crate</span> <span class="ident">cortex_m_rt</span> <span class="kw">as</span> <span class="ident">rt</span>;
<span class="comment">// Pick one of these two panic handlers:</span>
<span class="comment">// Reports panic messages to the host stderr using semihosting</span>
<span class="kw">extern</span> <span class="kw">crate</span> <span class="ident">panic_semihosting</span>;
<span class="comment">// Logs panic messages using the ITM (Instrumentation Trace Macrocell)</span>
<span class="comment">// extern crate panic_itm;</span>
<span class="kw">use</span> <span class="ident">rt</span>::<span class="ident">ExceptionFrame</span>;
<span class="macro">entry</span><span class="macro">!</span>(<span class="ident">main</span>);
<span class="kw">fn</span> <span class="ident">main</span>() <span class="op">-&gt;</span> <span class="op">!</span> {
<span class="macro">panic</span><span class="macro">!</span>(<span class="string">&quot;Oops&quot;</span>)
}
<span class="comment">// define the hard fault handler</span>
<span class="macro">exception</span><span class="macro">!</span>(<span class="ident">HardFault</span>, <span class="ident">hard_fault</span>);
<span class="kw">fn</span> <span class="ident">hard_fault</span>(<span class="ident">ef</span>: <span class="kw-2">&amp;</span><span class="ident">ExceptionFrame</span>) <span class="op">-&gt;</span> <span class="op">!</span> {
<span class="macro">panic</span><span class="macro">!</span>(<span class="string">&quot;HardFault at {:#?}&quot;</span>, <span class="ident">ef</span>);
}
<span class="comment">// define the default exception handler</span>
<span class="macro">exception</span><span class="macro">!</span>(<span class="kw-2">*</span>, <span class="ident">default_handler</span>);
<span class="kw">fn</span> <span class="ident">default_handler</span>(<span class="ident">irqn</span>: <span class="ident">i16</span>) {
<span class="macro">panic</span><span class="macro">!</span>(<span class="string">&quot;Unhandled exception (IRQn = {})&quot;</span>, <span class="ident">irqn</span>);
}</pre>
</div></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_quickstart";</script><script src="../../../aliases.js"></script><script src="../../../main.js"></script><script defer src="../../../search-index.js"></script></body></html>

View File

@@ -0,0 +1 @@
initSidebarItems({});

View File

@@ -0,0 +1,105 @@
<!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 `_4_crash` mod in crate `cortex_m_quickstart`."><meta name="keywords" content="rust, rustlang, rust-lang, _4_crash"><title>cortex_m_quickstart::examples::_4_crash - 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'>Module _4_crash</p><div class="sidebar-elems"><p class='location'><a href='../../index.html'>cortex_m_quickstart</a>::<wbr><a href='../index.html'>examples</a></p><script>window.sidebarCurrent = {name: '_4_crash', ty: 'mod', relpath: '../'};</script><script defer src="../sidebar-items.js"></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_quickstart/examples/_4_crash.rs.html#1-117' title='goto source code'>[src]</a></span><span class='in-band'>Module <a href='../../index.html'>cortex_m_quickstart</a>::<wbr><a href='../index.html'>examples</a>::<wbr><a class="mod" href=''>_4_crash</a></span></h1><div class='docblock'><p>Debugging a crash (exception)</p>
<p>Most crash conditions trigger a hard fault exception, whose handler is defined via
<code>exception!(HardFault, ..)</code>. The <code>HardFault</code> handler has access to the exception frame, a
snapshot of the CPU registers at the moment of the exception.</p>
<p>This program crashes and the <code>HardFault</code> handler prints to the console the contents of the
<code>ExceptionFrame</code> and then triggers a breakpoint. From that breakpoint one can see the backtrace
that led to the exception.</p>
<pre><code class="language-text">(gdb) continue
Program received signal SIGTRAP, Trace/breakpoint trap.
__bkpt () at asm/bkpt.s:3
3 bkpt
(gdb) backtrace
#0 __bkpt () at asm/bkpt.s:3
#1 0x080030b4 in cortex_m::asm::bkpt () at $$/cortex-m-0.5.0/src/asm.rs:19
#2 rust_begin_unwind (args=..., file=..., line=99, col=5) at $$/panic-semihosting-0.2.0/src/lib.rs:87
#3 0x08001d06 in core::panicking::panic_fmt () at libcore/panicking.rs:71
#4 0x080004a6 in crash::hard_fault (ef=0x20004fa0) at examples/crash.rs:99
#5 0x08000548 in UserHardFault (ef=0x20004fa0) at &lt;exception macros&gt;:10
#6 0x0800093a in HardFault () at asm.s:5
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
</code></pre>
<p>In the console output one will find the state of the Program Counter (PC) register at the time
of the exception.</p>
<pre><code class="language-text">panicked at 'HardFault at ExceptionFrame {
r0: 0x2fffffff,
r1: 0x2fffffff,
r2: 0x080051d4,
r3: 0x080051d4,
r12: 0x20000000,
lr: 0x08000435,
pc: 0x08000ab6,
xpsr: 0x61000000
}', examples/crash.rs:106:5
</code></pre>
<p>This register contains the address of the instruction that caused the exception. In GDB one can
disassemble the program around this address to observe the instruction that caused the
exception.</p>
<pre><code class="language-text">(gdb) disassemble/m 0x08000ab6
Dump of assembler code for function core::ptr::read_volatile:
451 pub unsafe fn read_volatile&lt;T&gt;(src: *const T) -&gt; T {
0x08000aae &lt;+0&gt;: sub sp, #16
0x08000ab0 &lt;+2&gt;: mov r1, r0
0x08000ab2 &lt;+4&gt;: str r0, [sp, #8]
452 intrinsics::volatile_load(src)
0x08000ab4 &lt;+6&gt;: ldr r0, [sp, #8]
-&gt; 0x08000ab6 &lt;+8&gt;: ldr r0, [r0, #0]
0x08000ab8 &lt;+10&gt;: str r0, [sp, #12]
0x08000aba &lt;+12&gt;: ldr r0, [sp, #12]
0x08000abc &lt;+14&gt;: str r1, [sp, #4]
0x08000abe &lt;+16&gt;: str r0, [sp, #0]
0x08000ac0 &lt;+18&gt;: b.n 0x8000ac2 &lt;core::ptr::read_volatile+20&gt;
453 }
0x08000ac2 &lt;+20&gt;: ldr r0, [sp, #0]
0x08000ac4 &lt;+22&gt;: add sp, #16
0x08000ac6 &lt;+24&gt;: bx lr
End of assembler dump.
</code></pre>
<p><code>ldr r0, [r0, #0]</code> caused the exception. This instruction tried to load (read) a 32-bit word
from the address stored in the register <code>r0</code>. Looking again at the contents of <code>ExceptionFrame</code>
we see that the <code>r0</code> contained the address <code>0x2FFF_FFFF</code> when this instruction was executed.</p>
<hr />
<pre class="rust rust-example-rendered">
<span class="attribute">#![<span class="ident">no_main</span>]</span>
<span class="attribute">#![<span class="ident">no_std</span>]</span>
<span class="kw">extern</span> <span class="kw">crate</span> <span class="ident">cortex_m</span>;
<span class="attribute">#[<span class="ident">macro_use</span>]</span>
<span class="kw">extern</span> <span class="kw">crate</span> <span class="ident">cortex_m_rt</span> <span class="kw">as</span> <span class="ident">rt</span>;
<span class="kw">extern</span> <span class="kw">crate</span> <span class="ident">panic_semihosting</span>;
<span class="kw">use</span> <span class="ident">core</span>::<span class="ident">ptr</span>;
<span class="kw">use</span> <span class="ident">rt</span>::<span class="ident">ExceptionFrame</span>;
<span class="macro">entry</span><span class="macro">!</span>(<span class="ident">main</span>);
<span class="kw">fn</span> <span class="ident">main</span>() <span class="op">-&gt;</span> <span class="op">!</span> {
<span class="kw">unsafe</span> {
<span class="comment">// read an address outside of the RAM region; causes a HardFault exception</span>
<span class="ident">ptr</span>::<span class="ident">read_volatile</span>(<span class="number">0x2FFF_FFFF</span> <span class="kw">as</span> <span class="kw-2">*</span><span class="kw">const</span> <span class="ident">u32</span>);
}
<span class="kw">loop</span> {}
}
<span class="comment">// define the hard fault handler</span>
<span class="macro">exception</span><span class="macro">!</span>(<span class="ident">HardFault</span>, <span class="ident">hard_fault</span>);
<span class="kw">fn</span> <span class="ident">hard_fault</span>(<span class="ident">ef</span>: <span class="kw-2">&amp;</span><span class="ident">ExceptionFrame</span>) <span class="op">-&gt;</span> <span class="op">!</span> {
<span class="macro">panic</span><span class="macro">!</span>(<span class="string">&quot;HardFault at {:#?}&quot;</span>, <span class="ident">ef</span>);
}
<span class="comment">// define the default exception handler</span>
<span class="macro">exception</span><span class="macro">!</span>(<span class="kw-2">*</span>, <span class="ident">default_handler</span>);
<span class="kw">fn</span> <span class="ident">default_handler</span>(<span class="ident">irqn</span>: <span class="ident">i16</span>) {
<span class="macro">panic</span><span class="macro">!</span>(<span class="string">&quot;Unhandled exception (IRQn = {})&quot;</span>, <span class="ident">irqn</span>);
}</pre>
</div></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_quickstart";</script><script src="../../../aliases.js"></script><script src="../../../main.js"></script><script defer src="../../../search-index.js"></script></body></html>

View File

@@ -0,0 +1 @@
initSidebarItems({});

View File

@@ -0,0 +1,63 @@
<!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 `_5_exception` mod in crate `cortex_m_quickstart`."><meta name="keywords" content="rust, rustlang, rust-lang, _5_exception"><title>cortex_m_quickstart::examples::_5_exception - 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'>Module _5_exception</p><div class="sidebar-elems"><p class='location'><a href='../../index.html'>cortex_m_quickstart</a>::<wbr><a href='../index.html'>examples</a></p><script>window.sidebarCurrent = {name: '_5_exception', ty: 'mod', relpath: '../'};</script><script defer src="../sidebar-items.js"></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_quickstart/examples/_5_exception.rs.html#1-67' title='goto source code'>[src]</a></span><span class='in-band'>Module <a href='../../index.html'>cortex_m_quickstart</a>::<wbr><a href='../index.html'>examples</a>::<wbr><a class="mod" href=''>_5_exception</a></span></h1><div class='docblock'><p>Overriding an exception handler</p>
<p>You can override an exception handler using the <a href="https://docs.rs/cortex-m-rt/0.5.0/cortex_m_rt/macro.exception.html"><code>exception!</code></a> macro.</p>
<hr />
<pre class="rust rust-example-rendered">
<span class="attribute">#![<span class="ident">deny</span>(<span class="ident">unsafe_code</span>)]</span>
<span class="attribute">#![<span class="ident">no_main</span>]</span>
<span class="attribute">#![<span class="ident">no_std</span>]</span>
<span class="kw">extern</span> <span class="kw">crate</span> <span class="ident">cortex_m</span>;
<span class="attribute">#[<span class="ident">macro_use</span>]</span>
<span class="kw">extern</span> <span class="kw">crate</span> <span class="ident">cortex_m_rt</span> <span class="kw">as</span> <span class="ident">rt</span>;
<span class="kw">extern</span> <span class="kw">crate</span> <span class="ident">cortex_m_semihosting</span> <span class="kw">as</span> <span class="ident">sh</span>;
<span class="kw">extern</span> <span class="kw">crate</span> <span class="ident">panic_semihosting</span>;
<span class="kw">use</span> <span class="ident">core</span>::<span class="ident">fmt</span>::<span class="ident">Write</span>;
<span class="kw">use</span> <span class="ident">cortex_m</span>::<span class="ident">peripheral</span>::<span class="ident">syst</span>::<span class="ident">SystClkSource</span>;
<span class="kw">use</span> <span class="ident">cortex_m</span>::<span class="ident">Peripherals</span>;
<span class="kw">use</span> <span class="ident">rt</span>::<span class="ident">ExceptionFrame</span>;
<span class="kw">use</span> <span class="ident">sh</span>::<span class="ident">hio</span>::{<span class="self">self</span>, <span class="ident">HStdout</span>};
<span class="macro">entry</span><span class="macro">!</span>(<span class="ident">main</span>);
<span class="kw">fn</span> <span class="ident">main</span>() <span class="op">-&gt;</span> <span class="op">!</span> {
<span class="kw">let</span> <span class="ident">p</span> <span class="op">=</span> <span class="ident">Peripherals</span>::<span class="ident">take</span>().<span class="ident">unwrap</span>();
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">syst</span> <span class="op">=</span> <span class="ident">p</span>.<span class="ident">SYST</span>;
<span class="comment">// configures the system timer to trigger a SysTick exception every second</span>
<span class="ident">syst</span>.<span class="ident">set_clock_source</span>(<span class="ident">SystClkSource</span>::<span class="ident">Core</span>);
<span class="ident">syst</span>.<span class="ident">set_reload</span>(<span class="number">8_000_000</span>); <span class="comment">// period = 1s</span>
<span class="ident">syst</span>.<span class="ident">enable_counter</span>();
<span class="ident">syst</span>.<span class="ident">enable_interrupt</span>();
<span class="kw">loop</span> {}
}
<span class="comment">// try commenting out this line: you&#39;ll end in `default_handler` instead of in `sys_tick`</span>
<span class="macro">exception</span><span class="macro">!</span>(<span class="ident">SysTick</span>, <span class="ident">sys_tick</span>, <span class="ident">state</span>: <span class="prelude-ty">Option</span><span class="op">&lt;</span><span class="ident">HStdout</span><span class="op">&gt;</span> <span class="op">=</span> <span class="prelude-val">None</span>);
<span class="kw">fn</span> <span class="ident">sys_tick</span>(<span class="ident">state</span>: <span class="kw-2">&amp;</span><span class="kw-2">mut</span> <span class="prelude-ty">Option</span><span class="op">&lt;</span><span class="ident">HStdout</span><span class="op">&gt;</span>) {
<span class="kw">if</span> <span class="ident">state</span>.<span class="ident">is_none</span>() {
<span class="kw-2">*</span><span class="ident">state</span> <span class="op">=</span> <span class="prelude-val">Some</span>(<span class="ident">hio</span>::<span class="ident">hstdout</span>().<span class="ident">unwrap</span>());
}
<span class="kw">if</span> <span class="kw">let</span> <span class="prelude-val">Some</span>(<span class="ident">hstdout</span>) <span class="op">=</span> <span class="ident">state</span>.<span class="ident">as_mut</span>() {
<span class="ident">hstdout</span>.<span class="ident">write_str</span>(<span class="string">&quot;.&quot;</span>).<span class="ident">unwrap</span>();
}
}
<span class="macro">exception</span><span class="macro">!</span>(<span class="ident">HardFault</span>, <span class="ident">hard_fault</span>);
<span class="kw">fn</span> <span class="ident">hard_fault</span>(<span class="ident">ef</span>: <span class="kw-2">&amp;</span><span class="ident">ExceptionFrame</span>) <span class="op">-&gt;</span> <span class="op">!</span> {
<span class="macro">panic</span><span class="macro">!</span>(<span class="string">&quot;HardFault at {:#?}&quot;</span>, <span class="ident">ef</span>);
}
<span class="macro">exception</span><span class="macro">!</span>(<span class="kw-2">*</span>, <span class="ident">default_handler</span>);
<span class="kw">fn</span> <span class="ident">default_handler</span>(<span class="ident">irqn</span>: <span class="ident">i16</span>) {
<span class="macro">panic</span><span class="macro">!</span>(<span class="string">&quot;Unhandled exception (IRQn = {})&quot;</span>, <span class="ident">irqn</span>);
}</pre>
</div></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_quickstart";</script><script src="../../../aliases.js"></script><script src="../../../main.js"></script><script defer src="../../../search-index.js"></script></body></html>

View File

@@ -0,0 +1 @@
initSidebarItems({});

View File

@@ -0,0 +1,74 @@
<!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 `_6_allocator` mod in crate `cortex_m_quickstart`."><meta name="keywords" content="rust, rustlang, rust-lang, _6_allocator"><title>cortex_m_quickstart::examples::_6_allocator - 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'>Module _6_allocator</p><div class="sidebar-elems"><p class='location'><a href='../../index.html'>cortex_m_quickstart</a>::<wbr><a href='../index.html'>examples</a></p><script>window.sidebarCurrent = {name: '_6_allocator', ty: 'mod', relpath: '../'};</script><script defer src="../sidebar-items.js"></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_quickstart/examples/_6_allocator.rs.html#1-78' title='goto source code'>[src]</a></span><span class='in-band'>Module <a href='../../index.html'>cortex_m_quickstart</a>::<wbr><a href='../index.html'>examples</a>::<wbr><a class="mod" href=''>_6_allocator</a></span></h1><div class='docblock'><p>How to use the heap and a dynamic memory allocator</p>
<p>This example depends on the alloc-cortex-m crate so you'll have to add it to your Cargo.toml:</p>
<pre><code class="language-text"># or edit the Cargo.toml file manually
$ cargo add alloc-cortex-m
</code></pre>
<hr />
<pre class="rust rust-example-rendered">
<span class="attribute">#![<span class="ident">feature</span>(<span class="ident">alloc</span>)]</span>
<span class="attribute">#![<span class="ident">feature</span>(<span class="ident">global_allocator</span>)]</span>
<span class="attribute">#![<span class="ident">feature</span>(<span class="ident">lang_items</span>)]</span>
<span class="attribute">#![<span class="ident">no_main</span>]</span>
<span class="attribute">#![<span class="ident">no_std</span>]</span>
<span class="comment">// This is the allocator crate; you can use a different one</span>
<span class="kw">extern</span> <span class="kw">crate</span> <span class="ident">alloc_cortex_m</span>;
<span class="attribute">#[<span class="ident">macro_use</span>]</span>
<span class="kw">extern</span> <span class="kw">crate</span> <span class="ident">alloc</span>;
<span class="kw">extern</span> <span class="kw">crate</span> <span class="ident">cortex_m</span>;
<span class="attribute">#[<span class="ident">macro_use</span>]</span>
<span class="kw">extern</span> <span class="kw">crate</span> <span class="ident">cortex_m_rt</span> <span class="kw">as</span> <span class="ident">rt</span>;
<span class="kw">extern</span> <span class="kw">crate</span> <span class="ident">cortex_m_semihosting</span> <span class="kw">as</span> <span class="ident">sh</span>;
<span class="kw">extern</span> <span class="kw">crate</span> <span class="ident">panic_semihosting</span>;
<span class="kw">use</span> <span class="ident">core</span>::<span class="ident">fmt</span>::<span class="ident">Write</span>;
<span class="kw">use</span> <span class="ident">alloc_cortex_m</span>::<span class="ident">CortexMHeap</span>;
<span class="kw">use</span> <span class="ident">cortex_m</span>::<span class="ident">asm</span>;
<span class="kw">use</span> <span class="ident">rt</span>::<span class="ident">ExceptionFrame</span>;
<span class="kw">use</span> <span class="ident">sh</span>::<span class="ident">hio</span>;
<span class="comment">// this is the allocator the application will use</span>
<span class="attribute">#[<span class="ident">global_allocator</span>]</span>
<span class="kw">static</span> <span class="ident">ALLOCATOR</span>: <span class="ident">CortexMHeap</span> <span class="op">=</span> <span class="ident">CortexMHeap</span>::<span class="ident">empty</span>();
<span class="kw">const</span> <span class="ident">HEAP_SIZE</span>: <span class="ident">usize</span> <span class="op">=</span> <span class="number">1024</span>; <span class="comment">// in bytes</span>
<span class="macro">entry</span><span class="macro">!</span>(<span class="ident">main</span>);
<span class="kw">fn</span> <span class="ident">main</span>() <span class="op">-&gt;</span> <span class="op">!</span> {
<span class="comment">// Initialize the allocator BEFORE you use it</span>
<span class="kw">unsafe</span> { <span class="ident">ALLOCATOR</span>.<span class="ident">init</span>(<span class="ident">rt</span>::<span class="ident">heap_start</span>() <span class="kw">as</span> <span class="ident">usize</span>, <span class="ident">HEAP_SIZE</span>) }
<span class="comment">// Growable array allocated on the heap</span>
<span class="kw">let</span> <span class="ident">xs</span> <span class="op">=</span> <span class="macro">vec</span><span class="macro">!</span>[<span class="number">0</span>, <span class="number">1</span>, <span class="number">2</span>];
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">stdout</span> <span class="op">=</span> <span class="ident">hio</span>::<span class="ident">hstdout</span>().<span class="ident">unwrap</span>();
<span class="macro">writeln</span><span class="macro">!</span>(<span class="ident">stdout</span>, <span class="string">&quot;{:?}&quot;</span>, <span class="ident">xs</span>).<span class="ident">unwrap</span>();
<span class="kw">loop</span> {}
}
<span class="comment">// define what happens in an Out Of Memory (OOM) condition</span>
<span class="attribute">#[<span class="ident">lang</span> <span class="op">=</span> <span class="string">&quot;oom&quot;</span>]</span>
<span class="attribute">#[<span class="ident">no_mangle</span>]</span>
<span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">rust_oom</span>() <span class="op">-&gt;</span> <span class="op">!</span> {
<span class="ident">asm</span>::<span class="ident">bkpt</span>();
<span class="kw">loop</span> {}
}
<span class="macro">exception</span><span class="macro">!</span>(<span class="ident">HardFault</span>, <span class="ident">hard_fault</span>);
<span class="kw">fn</span> <span class="ident">hard_fault</span>(<span class="ident">ef</span>: <span class="kw-2">&amp;</span><span class="ident">ExceptionFrame</span>) <span class="op">-&gt;</span> <span class="op">!</span> {
<span class="macro">panic</span><span class="macro">!</span>(<span class="string">&quot;HardFault at {:#?}&quot;</span>, <span class="ident">ef</span>);
}
<span class="macro">exception</span><span class="macro">!</span>(<span class="kw-2">*</span>, <span class="ident">default_handler</span>);
<span class="kw">fn</span> <span class="ident">default_handler</span>(<span class="ident">irqn</span>: <span class="ident">i16</span>) {
<span class="macro">panic</span><span class="macro">!</span>(<span class="string">&quot;Unhandled exception (IRQn = {})&quot;</span>, <span class="ident">irqn</span>);
}</pre>
</div></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_quickstart";</script><script src="../../../aliases.js"></script><script src="../../../main.js"></script><script defer src="../../../search-index.js"></script></body></html>

View File

@@ -0,0 +1 @@
initSidebarItems({});

View File

@@ -0,0 +1,83 @@
<!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 `_7_device` mod in crate `cortex_m_quickstart`."><meta name="keywords" content="rust, rustlang, rust-lang, _7_device"><title>cortex_m_quickstart::examples::_7_device - 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'>Module _7_device</p><div class="sidebar-elems"><p class='location'><a href='../../index.html'>cortex_m_quickstart</a>::<wbr><a href='../index.html'>examples</a></p><script>window.sidebarCurrent = {name: '_7_device', ty: 'mod', relpath: '../'};</script><script defer src="../sidebar-items.js"></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_quickstart/examples/_7_device.rs.html#1-92' title='goto source code'>[src]</a></span><span class='in-band'>Module <a href='../../index.html'>cortex_m_quickstart</a>::<wbr><a href='../index.html'>examples</a>::<wbr><a class="mod" href=''>_7_device</a></span></h1><div class='docblock'><p>Using a device crate</p>
<p>Crates generated using <a href="https://crates.io/crates/svd2rust"><code>svd2rust</code></a> are referred to as device crates. These crates provide an
API to access the peripherals of a device.</p>
<p>Device crates also provide an <code>interrupt!</code> macro (behind the &quot;rt&quot; feature) to register interrupt
handlers.</p>
<p>This example depends on the <a href="https://crates.io/crates/stm32f103xx"><code>stm32f103xx</code></a> crate so you'll have to add it to your Cargo.toml.</p>
<pre class="rust rust-example-rendered">
$ <span class="ident">edit</span> <span class="ident">Cargo</span>.<span class="ident">toml</span> <span class="op">&amp;&amp;</span> <span class="ident">tail</span> <span class="macro-nonterminal">$</span><span class="kw">_</span>
[<span class="macro-nonterminal">dependencies</span>.<span class="ident">stm32f103xx</span>]
<span class="ident">features</span> <span class="op">=</span> [<span class="string">&quot;rt&quot;</span>]
<span class="ident">version</span> <span class="op">=</span> <span class="string">&quot;0.10.0&quot;</span></pre>
<hr />
<pre class="rust rust-example-rendered">
<span class="attribute">#![<span class="ident">no_main</span>]</span>
<span class="attribute">#![<span class="ident">no_std</span>]</span>
<span class="kw">extern</span> <span class="kw">crate</span> <span class="ident">cortex_m</span>;
<span class="attribute">#[<span class="ident">macro_use</span>]</span>
<span class="kw">extern</span> <span class="kw">crate</span> <span class="ident">cortex_m_rt</span> <span class="kw">as</span> <span class="ident">rt</span>;
<span class="kw">extern</span> <span class="kw">crate</span> <span class="ident">cortex_m_semihosting</span> <span class="kw">as</span> <span class="ident">sh</span>;
<span class="attribute">#[<span class="ident">macro_use</span>]</span>
<span class="kw">extern</span> <span class="kw">crate</span> <span class="ident">stm32f103xx</span>;
<span class="kw">extern</span> <span class="kw">crate</span> <span class="ident">panic_semihosting</span>;
<span class="kw">use</span> <span class="ident">core</span>::<span class="ident">fmt</span>::<span class="ident">Write</span>;
<span class="kw">use</span> <span class="ident">cortex_m</span>::<span class="ident">peripheral</span>::<span class="ident">syst</span>::<span class="ident">SystClkSource</span>;
<span class="kw">use</span> <span class="ident">rt</span>::<span class="ident">ExceptionFrame</span>;
<span class="kw">use</span> <span class="ident">sh</span>::<span class="ident">hio</span>::{<span class="self">self</span>, <span class="ident">HStdout</span>};
<span class="kw">use</span> <span class="ident">stm32f103xx</span>::<span class="ident">Interrupt</span>;
<span class="macro">entry</span><span class="macro">!</span>(<span class="ident">main</span>);
<span class="kw">fn</span> <span class="ident">main</span>() <span class="op">-&gt;</span> <span class="op">!</span> {
<span class="kw">let</span> <span class="ident">p</span> <span class="op">=</span> <span class="ident">cortex_m</span>::<span class="ident">Peripherals</span>::<span class="ident">take</span>().<span class="ident">unwrap</span>();
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">syst</span> <span class="op">=</span> <span class="ident">p</span>.<span class="ident">SYST</span>;
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">nvic</span> <span class="op">=</span> <span class="ident">p</span>.<span class="ident">NVIC</span>;
<span class="ident">nvic</span>.<span class="ident">enable</span>(<span class="ident">Interrupt</span>::<span class="ident">EXTI0</span>);
<span class="comment">// configure the system timer to wrap around every second</span>
<span class="ident">syst</span>.<span class="ident">set_clock_source</span>(<span class="ident">SystClkSource</span>::<span class="ident">Core</span>);
<span class="ident">syst</span>.<span class="ident">set_reload</span>(<span class="number">8_000_000</span>); <span class="comment">// 1s</span>
<span class="ident">syst</span>.<span class="ident">enable_counter</span>();
<span class="kw">loop</span> {
<span class="comment">// busy wait until the timer wraps around</span>
<span class="kw">while</span> <span class="op">!</span><span class="ident">syst</span>.<span class="ident">has_wrapped</span>() {}
<span class="comment">// trigger the `EXTI0` interrupt</span>
<span class="ident">nvic</span>.<span class="ident">set_pending</span>(<span class="ident">Interrupt</span>::<span class="ident">EXTI0</span>);
}
}
<span class="comment">// try commenting out this line: you&#39;ll end in `default_handler` instead of in `exti0`</span>
<span class="macro">interrupt</span><span class="macro">!</span>(<span class="ident">EXTI0</span>, <span class="ident">exti0</span>, <span class="ident">state</span>: <span class="prelude-ty">Option</span><span class="op">&lt;</span><span class="ident">HStdout</span><span class="op">&gt;</span> <span class="op">=</span> <span class="prelude-val">None</span>);
<span class="kw">fn</span> <span class="ident">exti0</span>(<span class="ident">state</span>: <span class="kw-2">&amp;</span><span class="kw-2">mut</span> <span class="prelude-ty">Option</span><span class="op">&lt;</span><span class="ident">HStdout</span><span class="op">&gt;</span>) {
<span class="kw">if</span> <span class="ident">state</span>.<span class="ident">is_none</span>() {
<span class="kw-2">*</span><span class="ident">state</span> <span class="op">=</span> <span class="prelude-val">Some</span>(<span class="ident">hio</span>::<span class="ident">hstdout</span>().<span class="ident">unwrap</span>());
}
<span class="kw">if</span> <span class="kw">let</span> <span class="prelude-val">Some</span>(<span class="ident">hstdout</span>) <span class="op">=</span> <span class="ident">state</span>.<span class="ident">as_mut</span>() {
<span class="ident">hstdout</span>.<span class="ident">write_str</span>(<span class="string">&quot;.&quot;</span>).<span class="ident">unwrap</span>();
}
}
<span class="macro">exception</span><span class="macro">!</span>(<span class="ident">HardFault</span>, <span class="ident">hard_fault</span>);
<span class="kw">fn</span> <span class="ident">hard_fault</span>(<span class="ident">ef</span>: <span class="kw-2">&amp;</span><span class="ident">ExceptionFrame</span>) <span class="op">-&gt;</span> <span class="op">!</span> {
<span class="macro">panic</span><span class="macro">!</span>(<span class="string">&quot;HardFault at {:#?}&quot;</span>, <span class="ident">ef</span>);
}
<span class="macro">exception</span><span class="macro">!</span>(<span class="kw-2">*</span>, <span class="ident">default_handler</span>);
<span class="kw">fn</span> <span class="ident">default_handler</span>(<span class="ident">irqn</span>: <span class="ident">i16</span>) {
<span class="macro">panic</span><span class="macro">!</span>(<span class="string">&quot;Unhandled exception (IRQn = {})&quot;</span>, <span class="ident">irqn</span>);
}</pre>
</div></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_quickstart";</script><script src="../../../aliases.js"></script><script src="../../../main.js"></script><script defer src="../../../search-index.js"></script></body></html>

View File

@@ -0,0 +1 @@
initSidebarItems({});

View File

@@ -0,0 +1,67 @@
<!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 `examples` mod in crate `cortex_m_quickstart`."><meta name="keywords" content="rust, rustlang, rust-lang, examples"><title>cortex_m_quickstart::examples - 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'>Module examples</p><div class="sidebar-elems"><div class="block items"><ul><li><a href="#modules">Modules</a></li></ul></div><p class='location'><a href='../index.html'>cortex_m_quickstart</a></p><script>window.sidebarCurrent = {name: 'examples', ty: 'mod', relpath: '../'};</script><script defer src="../sidebar-items.js"></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_quickstart/examples/mod.rs.html#1-10' title='goto source code'>[src]</a></span><span class='in-band'>Module <a href='../index.html'>cortex_m_quickstart</a>::<wbr><a class="mod" href=''>examples</a></span></h1><div class='docblock'><p>Examples sorted in increasing degree of complexity</p>
</div><h2 id='modules' class='section-header'><a href="#modules">Modules</a></h2>
<table>
<tr class=' module-item'>
<td><a class="mod" href="_0_minimal/index.html"
title='mod cortex_m_quickstart::examples::_0_minimal'>_0_minimal</a></td>
<td class='docblock-short'>
<p>Minimal Cortex-M program</p>
</td>
</tr>
<tr class=' module-item'>
<td><a class="mod" href="_1_hello/index.html"
title='mod cortex_m_quickstart::examples::_1_hello'>_1_hello</a></td>
<td class='docblock-short'>
<p>Prints &quot;Hello, world!&quot; on the OpenOCD console using semihosting</p>
</td>
</tr>
<tr class=' module-item'>
<td><a class="mod" href="_2_itm/index.html"
title='mod cortex_m_quickstart::examples::_2_itm'>_2_itm</a></td>
<td class='docblock-short'>
<p>Sends &quot;Hello, world!&quot; through the ITM port 0</p>
</td>
</tr>
<tr class=' module-item'>
<td><a class="mod" href="_3_panic/index.html"
title='mod cortex_m_quickstart::examples::_3_panic'>_3_panic</a></td>
<td class='docblock-short'>
<p>Changing the panic handler</p>
</td>
</tr>
<tr class=' module-item'>
<td><a class="mod" href="_4_crash/index.html"
title='mod cortex_m_quickstart::examples::_4_crash'>_4_crash</a></td>
<td class='docblock-short'>
<p>Debugging a crash (exception)</p>
</td>
</tr>
<tr class=' module-item'>
<td><a class="mod" href="_5_exception/index.html"
title='mod cortex_m_quickstart::examples::_5_exception'>_5_exception</a></td>
<td class='docblock-short'>
<p>Overriding an exception handler</p>
</td>
</tr>
<tr class=' module-item'>
<td><a class="mod" href="_6_allocator/index.html"
title='mod cortex_m_quickstart::examples::_6_allocator'>_6_allocator</a></td>
<td class='docblock-short'>
<p>How to use the heap and a dynamic memory allocator</p>
</td>
</tr>
<tr class=' module-item'>
<td><a class="mod" href="_7_device/index.html"
title='mod cortex_m_quickstart::examples::_7_device'>_7_device</a></td>
<td class='docblock-short'>
<p>Using a device crate</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_quickstart";</script><script src="../../aliases.js"></script><script src="../../main.js"></script><script defer src="../../search-index.js"></script></body></html>

View File

@@ -0,0 +1 @@
initSidebarItems({"mod":[["_0_minimal","Minimal Cortex-M program"],["_1_hello","Prints \"Hello, world!\" on the OpenOCD console using semihosting"],["_2_itm","Sends \"Hello, world!\" through the ITM port 0"],["_3_panic","Changing the panic handler"],["_4_crash","Debugging a crash (exception)"],["_5_exception","Overriding an exception handler"],["_6_allocator","How to use the heap and a dynamic memory allocator"],["_7_device","Using a device crate"]]});

View File

@@ -0,0 +1,276 @@
<!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_quickstart` crate."><meta name="keywords" content="rust, rustlang, rust-lang, cortex_m_quickstart"><title>cortex_m_quickstart - 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_quickstart</p><div class="sidebar-elems"><div class="block items"><ul><li><a href="#modules">Modules</a></li></ul></div><p class='location'></p><script>window.sidebarCurrent = {name: 'cortex_m_quickstart', 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_quickstart/lib.rs.html#1-342' title='goto source code'>[src]</a></span><span class='in-band'>Crate <a class="mod" href=''>cortex_m_quickstart</a></span></h1><div class='docblock'><p>A template for building applications for ARM Cortex-M microcontrollers</p>
<h1 id="dependencies" class="section-header"><a href="#dependencies">Dependencies</a></h1>
<ul>
<li>Nightly Rust toolchain from 2018-08-28 or newer: <code>rustup default nightly</code></li>
<li>Cargo <code>clone</code> subcommand: <code>cargo install cargo-clone</code></li>
<li>GDB: <code>sudo apt-get install gdb-arm-none-eabi</code> (on Ubuntu)</li>
<li>OpenOCD: <code>sudo apt-get install OpenOCD</code> (on Ubuntu)</li>
<li>[Optional] Cargo <code>add</code> subcommand: <code>cargo install cargo-edit</code></li>
</ul>
<h1 id="usage" class="section-header"><a href="#usage">Usage</a></h1>
<ol start="0">
<li>
<p>Figure out the cross compilation <em>target</em> to use.</p>
</li>
</ol>
<ul>
<li>
<p>Use <code>thumbv6m-none-eabi</code> for ARM Cortex-M0 and Cortex-M0+</p>
</li>
<li>
<p>Use <code>thumbv7m-none-eabi</code> for ARM Cortex-M3</p>
</li>
<li>
<p>Use <code>thumbv7em-none-eabi</code> for ARM Cortex-M4 and Cortex-M7 (<em>no</em> FPU support)</p>
</li>
<li>
<p>Use <code>thumbv7em-none-eabihf</code> for ARM Cortex-M4<strong>F</strong> and Cortex-M7<strong>F</strong> (<em>with</em> FPU support)</p>
</li>
</ul>
<ol>
<li>Install the <code>rust-std</code> component for your target, if you haven't done so already</li>
</ol>
<pre><code class="language-console">$ rustup target add thumbv7em-none-eabihf
</code></pre>
<ol start="2">
<li>Clone this crate</li>
</ol>
<pre><code class="language-text">$ cargo clone cortex-m-quickstart --vers 0.3.4
</code></pre>
<ol start="3">
<li>Change the crate name, author and version</li>
</ol>
<pre><code class="language-text">$ edit Cargo.toml &amp;&amp; head $_
[package]
authors = [&quot;Jorge Aparicio &lt;jorge@japaric.io&gt;&quot;]
name = &quot;demo&quot;
version = &quot;0.1.0&quot;
</code></pre>
<ol start="4">
<li>Specify the memory layout of the target device</li>
</ol>
<p><strong>NOTE</strong> board support crates sometimes provide this file for you (check the crate
documentation). If you are using one that does then remove <em>both</em> <code>memory.x</code> and <code>build.rs</code> from
the root of this crate.</p>
<pre><code class="language-text">$ cat &gt;memory.x &lt;&lt;'EOF'
MEMORY
{
/* NOTE K = KiBi = 1024 bytes */
FLASH : ORIGIN = 0x08000000, LENGTH = 256K
RAM : ORIGIN = 0x20000000, LENGTH = 40K
}
EOF
</code></pre>
<ol start="5">
<li>Optionally, set a default build target. This way you don't have to pass <code>--target</code> to each
Cargo invocation.</li>
</ol>
<pre><code class="language-text">$ cat &gt;&gt;.cargo/config &lt;&lt;'EOF'
[build]
target = &quot;thumbv7em-none-eabihf&quot;
EOF
</code></pre>
<ol start="6">
<li>Optionally, depend on a device, HAL implementation or a board support crate.</li>
</ol>
<pre><code class="language-text">$ # add a device crate, OR
$ cargo add stm32f30x
$ # add a HAL implementation crate, OR
$ cargo add stm32f30x-hal
$ # add a board support crate
$ cargo add f3
</code></pre>
<ol start="7">
<li>Write the application or start from one of the examples</li>
</ol>
<pre><code class="language-text">$ rm -r src/* &amp;&amp; cp examples/hello.rs src/main.rs
</code></pre>
<ol start="8">
<li>Build the application</li>
</ol>
<pre><code class="language-text">$ cargo build --release
$ # sanity check
$ arm-none-eabi-readelf -A target/thumbv7em-none-eabihf/release/demo
Attribute Section: aeabi
File Attributes
Tag_conformance: &quot;2.09&quot;
Tag_CPU_arch: v7E-M
Tag_CPU_arch_profile: Microcontroller
Tag_THUMB_ISA_use: Thumb-2
Tag_FP_arch: VFPv4-D16
Tag_ABI_PCS_GOT_use: direct
Tag_ABI_FP_denormal: Needed
Tag_ABI_FP_exceptions: Needed
Tag_ABI_FP_number_model: IEEE 754
Tag_ABI_align_needed: 8-byte
Tag_ABI_align_preserved: 8-byte, except leaf SP
Tag_ABI_HardFP_use: SP only
Tag_ABI_VFP_args: VFP registers
Tag_ABI_optimization_goals: Aggressive Speed
Tag_CPU_unaligned_access: v6
Tag_FP_HP_extension: Allowed
Tag_ABI_FP_16bit_format: IEEE 754
</code></pre>
<ol start="9">
<li>Flash and debug the program</li>
</ol>
<pre><code class="language-text">$ # Launch OpenOCD on a terminal
$ openocd -f (..)
</code></pre>
<pre><code class="language-text">$ # Start a debug session in another terminal
$ arm-none-eabi-gdb target/thumbv7em-none-eabihf/release/demo
</code></pre>
<p>Alternatively, you can use <code>cargo run</code> to build, flash and debug the program in a single step.</p>
<pre><code class="language-text">$ cargo run --example hello
&gt; # drops you into a GDB session
</code></pre>
<h1 id="examples" class="section-header"><a href="#examples">Examples</a></h1>
<p>Check the <a href="./examples/index.html">examples module</a></p>
<h1 id="troubleshooting" class="section-header"><a href="#troubleshooting">Troubleshooting</a></h1>
<p>This section contains fixes for common errors encountered when the
<code>cortex-m-quickstart</code> template is misused.</p>
<h2 id="used-the-standard-main-interface" class="section-header"><a href="#used-the-standard-main-interface">Used the standard <code>main</code> interface</a></h2>
<p>Error message:</p>
<pre><code class="language-text">$ cargo build
Compiling demo v0.1.0 (file:///home/japaric/tmp/demo)
error: requires `start` lang_item
</code></pre>
<p>Solution: Use <code>#![no_main]</code> and <code>entry!</code> as shown in the <a href="./examples/index.html">examples</a>.</p>
<h2 id="forgot-to-launch-an-openocd-instance" class="section-header"><a href="#forgot-to-launch-an-openocd-instance">Forgot to launch an OpenOCD instance</a></h2>
<p>Error message:</p>
<pre><code class="language-text">$ arm-none-eabi-gdb target/..
Reading symbols from hello...done.
.gdbinit:1: Error in sourced command file:
:3333: Connection timed out.
</code></pre>
<p>Solution: Launch OpenOCD on other terminal. See <a href="./index.html#usage">Usage</a> section.</p>
<h2 id="didnt-modify-the-memoryx-linker-script" class="section-header"><a href="#didnt-modify-the-memoryx-linker-script">Didn't modify the <code>memory.x</code> linker script</a></h2>
<p>Error message:</p>
<pre><code class="language-text">$ cargo build
Compiling demo v0.1.0 (file:///home/japaric/tmp/demo)
error: linking with `rust-lld` failed: exit code: 1
|
= note: &quot;rust-lld&quot; &quot;-flavor&quot; &quot;gnu&quot; &quot;-L&quot; (..)
(..)
= note: rust-lld: error: section '.vector_table' will not fit in region 'FLASH': overflowed by X bytes
rust-lld: error: section '.vector_table' will not fit in region 'FLASH': overflowed by Y bytes
(..)
</code></pre>
<p>Solution: Specify your device memory layout in the <code>memory.x</code> linker script. See <a href="./index.html#usage">Usage</a>
section.</p>
<h2 id="didnt-set-a-default-build-target-and-forgot-to-pass---target-to-cargo" class="section-header"><a href="#didnt-set-a-default-build-target-and-forgot-to-pass---target-to-cargo">Didn't set a default build target and forgot to pass <code>--target</code> to Cargo</a></h2>
<p>Error message:</p>
<pre><code class="language-text">$ cargo build
(..)
error: language item required, but not found: `eh_personality`
error: aborting due to previous error
</code></pre>
<p>Solution: Set a default build target in the <code>.cargo/config</code> file (see <a href="./index.html#usage">Usage</a> section), or call
Cargo with <code>--target</code> flag: <code>cargo build --target thumbv7em-none-eabi</code>.</p>
<h2 id="overwrote-the-original-cargoconfig-file" class="section-header"><a href="#overwrote-the-original-cargoconfig-file">Overwrote the original <code>.cargo/config</code> file</a></h2>
<p>You won't get an error message but the output binary will be empty</p>
<pre><code class="language-text">$ cargo build &amp;&amp; echo OK
OK
$ size target/thumbv7m-none-eabi/debug/app
text data bss dec hex filename
0 0 0 0 0 target/thumbv7m-none-eabi/debug/app
</code></pre>
<p>Solution: You probably overwrote the original <code>.cargo/config</code> instead of appending the default
build target (e.g. <code>cat &gt;</code> instead of <code>cat &gt;&gt;</code>). The less error prone way to fix this is to
remove the <code>.cargo</code> directory, clone a new copy of the template and then copy the <code>.cargo</code>
directory from that fresh template into your current project. Don't forget to <em>append</em> the
default build target to <code>.cargo/config</code>.</p>
<h2 id="called-openocd-with-wrong-arguments" class="section-header"><a href="#called-openocd-with-wrong-arguments">Called OpenOCD with wrong arguments</a></h2>
<p>Error message:</p>
<pre><code class="language-text">$ openocd -f ..
(..)
Error: open failed
in procedure 'init'
in procedure 'ocd_bouncer'
</code></pre>
<p>Solution: Correct the OpenOCD arguments. Check the <code>/usr/share/openocd/scripts</code> directory (exact
location varies per distribution / OS) for a list of scripts that can be used.</p>
<h2 id="forgot-to-install-the-rust-std-component" class="section-header"><a href="#forgot-to-install-the-rust-std-component">Forgot to install the <code>rust-std</code> component</a></h2>
<p>Error message:</p>
<pre><code class="language-text">$ cargo build
error[E0463]: can't find crate for `core`
|
= note: the `thumbv7m-none-eabi` target may not be installed
</code></pre>
<p>Solution: call <code>rustup target add thumbv7m-none-eabi</code> but with the name of your target</p>
<h2 id="used-an-old-nightly" class="section-header"><a href="#used-an-old-nightly">Used an old nightly</a></h2>
<p>Error message:</p>
<pre><code class="language-text">$ cargo build
Compiling cortex-m-rt v0.2.0
error[E0463]: can't find crate for `core`
|
= note: the `thumbv7em-none-eabihf` target may not be installed
error: aborting due to previous error
</code></pre>
<p>Solution: Use a more recent nightly</p>
<h2 id="used-the-stable-toolchain" class="section-header"><a href="#used-the-stable-toolchain">Used the stable toolchain</a></h2>
<p>Error message:</p>
<pre><code class="language-text">$ cargo build
error[E0463]: can't find crate for `core`
|
= note: the `thumbv7em-none-eabihf` target may not be installed
</code></pre>
<p>Solution: We are not there yet! Switch to the nightly toolchain with <code>rustup default nightly</code>.</p>
<h2 id="used-gdb-instead-of-arm-none-eabi-gdb" class="section-header"><a href="#used-gdb-instead-of-arm-none-eabi-gdb">Used <code>gdb</code> instead of <code>arm-none-eabi-gdb</code></a></h2>
<p>Error message:</p>
<pre><code class="language-text">$ gdb target/..
Reading symbols from hello...done.
warning: Architecture rejected target-supplied description
warning: Cannot convert floating-point register value to ..
value has been optimized out
Cannot write the dashboard
Traceback (most recent call last):
File &quot;&lt;string&gt;&quot;, line 353, in render
File &quot;&lt;string&gt;&quot;, line 846, in lines
gdb.error: Frame is invalid.
0x00000000 in ?? ()
semihosting is enabled
Loading section .text, size 0xd88 lma 0x8000000
Start address 0x8000000, load size 3464
.gdbinit:6: Error in sourced command file:
Remote connection closed
</code></pre>
<p>Solution: Use <code>arm-none-eabi-gdb target/..</code></p>
<h1 id="used-a-named-piped-for-itmfifo" class="section-header"><a href="#used-a-named-piped-for-itmfifo">Used a named piped for <code>itm.fifo</code></a></h1>
<p>Error message:</p>
<pre><code class="language-text">$ cargo run [--example ..]
Reading symbols from target/thumbv7em-none-eabihf/debug/cortex-m-quickstart...done.
cortex_m_rt::reset_handler ()
at $REGISTRY/cortex-m-rt-0.3.12/src/lib.rs:330
330 unsafe extern &quot;C&quot; fn reset_handler() -&gt; ! {
semihosting is enabled
Ignoring packet error, continuing...
Ignoring packet error, continuing...
</code></pre>
<p>Note that when you reach this point OpenOCD will become unresponsive and you'll have to kill it
and start a new OpenOCD process before you can invoke <code>cargo run</code> / start GDB.</p>
<p>Cause: You uncommented the <code>monitor tpiu ..</code> line in <code>.gdbinit</code> and are using a named pipe to
receive the ITM data (i.e. you ran <code>mkfifo itm.fifo</code>). This error occurs when <code>itmdump -f itm.fifo</code> (or equivalent, e.g. <code>cat itm.fifo</code>) is not running.</p>
<p>Solution: Run <code>itmdump -f itm.fifo</code> (or equivalently <code>cat itm.fifo</code>) <em>before</em> invoking <code>cargo run</code> / starting GDB. Note that sometimes <code>itmdump</code> will exit when the GDB session ends. In that
case you'll have to run <code>itmdump</code> before you start the next GDB session.</p>
<p>Alternative solution: Use a plain text file instead of a named pipe. In this scenario you omit
the <code>mkfifo itm.dump</code> command. You can use <code>itmdump</code>'s <em>follow</em> mode (-F) to get named pipe like
output.</p>
</div><h2 id='modules' class='section-header'><a href="#modules">Modules</a></h2>
<table>
<tr class=' module-item'>
<td><a class="mod" href="examples/index.html"
title='mod cortex_m_quickstart::examples'>examples</a></td>
<td class='docblock-short'>
<p>Examples sorted in increasing degree of complexity</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_quickstart";</script><script src="../aliases.js"></script><script src="../main.js"></script><script defer src="../search-index.js"></script></body></html>

View File

@@ -0,0 +1 @@
initSidebarItems({"mod":[["examples","Examples sorted in increasing degree of complexity"]]});