271 lines
19 KiB
HTML
271 lines
19 KiB
HTML
<!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 `peripheral` mod in crate `cortex_m`."><meta name="keywords" content="rust, rustlang, rust-lang, peripheral"><title>cortex_m::peripheral - 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">☰</div><p class='location'>Module peripheral</p><div class="sidebar-elems"><div class="block items"><ul><li><a href="#modules">Modules</a></li><li><a href="#structs">Structs</a></li></ul></div><p class='location'><a href='../index.html'>cortex_m</a></p><script>window.sidebarCurrent = {name: 'peripheral', 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'>−</span>]</a></span><a class='srclink' href='../../src/cortex_m/peripheral/mod.rs.html#1-501' title='goto source code'>[src]</a></span><span class='in-band'>Module <a href='../index.html'>cortex_m</a>::<wbr><a class="mod" href=''>peripheral</a></span></h1><div class='docblock'><p>Core peripherals</p>
|
||
<h1 id="api" class="section-header"><a href="#api">API</a></h1>
|
||
<p>To use (most of) the peripheral API first you must get an <em>instance</em> of the peripheral. All the
|
||
core peripherals are modeled as singletons (there can only ever be, at most, one instance of any
|
||
one of them at any given point in time) and the only way to get an instance of them is through
|
||
the <a href="struct.Peripherals.html#method.take"><code>Peripherals::take</code></a> method.</p>
|
||
|
||
<pre class="rust rust-example-rendered">
|
||
<span class="kw">extern</span> <span class="kw">crate</span> <span class="ident">cortex_m</span>;
|
||
|
||
<span class="kw">use</span> <span class="ident">cortex_m</span>::<span class="ident">peripheral</span>::<span class="ident">Peripherals</span>;
|
||
|
||
<span class="kw">fn</span> <span class="ident">main</span>() {
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">peripherals</span> <span class="op">=</span> <span class="ident">Peripherals</span>::<span class="ident">take</span>().<span class="ident">unwrap</span>();
|
||
<span class="ident">peripherals</span>.<span class="ident">DWT</span>.<span class="ident">enable_cycle_counter</span>();
|
||
}</pre>
|
||
<p>This method can only be successfully called <em>once</em> -- this is why the method returns an
|
||
<code>Option</code>. Subsequent calls to the method will result in a <code>None</code> value being returned.</p>
|
||
|
||
<pre class="rust rust-example-rendered">
|
||
<span class="kw">extern</span> <span class="kw">crate</span> <span class="ident">cortex_m</span>;
|
||
|
||
<span class="kw">use</span> <span class="ident">cortex_m</span>::<span class="ident">peripheral</span>::<span class="ident">Peripherals</span>;
|
||
|
||
<span class="kw">fn</span> <span class="ident">main</span>() {
|
||
<span class="kw">let</span> <span class="ident">ok</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">panics</span> <span class="op">=</span> <span class="ident">Peripherals</span>::<span class="ident">take</span>().<span class="ident">unwrap</span>();
|
||
}</pre>
|
||
<p>A part of the peripheral API doesn't require access to a peripheral instance. This part of the
|
||
API is provided as static methods on the peripheral types. One example is the
|
||
<a href="struct.DWT.html#method.get_cycle_count"><code>DWT::get_cycle_count</code></a> method.</p>
|
||
|
||
<pre class="rust rust-example-rendered">
|
||
<span class="kw">extern</span> <span class="kw">crate</span> <span class="ident">cortex_m</span>;
|
||
|
||
<span class="kw">use</span> <span class="ident">cortex_m</span>::<span class="ident">peripheral</span>::{<span class="ident">DWT</span>, <span class="ident">Peripherals</span>};
|
||
|
||
<span class="kw">fn</span> <span class="ident">main</span>() {
|
||
{
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">peripherals</span> <span class="op">=</span> <span class="ident">Peripherals</span>::<span class="ident">take</span>().<span class="ident">unwrap</span>();
|
||
<span class="ident">peripherals</span>.<span class="ident">DWT</span>.<span class="ident">enable_cycle_counter</span>();
|
||
} <span class="comment">// all the peripheral singletons are destroyed here</span>
|
||
|
||
<span class="comment">// but this method can be called without a DWT instance</span>
|
||
<span class="kw">let</span> <span class="ident">cyccnt</span> <span class="op">=</span> <span class="ident">DWT</span>::<span class="ident">get_cycle_count</span>();
|
||
}</pre>
|
||
<p>The singleton property can be <em>unsafely</em> bypassed using the <code>ptr</code> static method which is
|
||
available on all the peripheral types. This method is a useful building block for implementing
|
||
safe higher level abstractions.</p>
|
||
|
||
<pre class="rust rust-example-rendered">
|
||
<span class="kw">extern</span> <span class="kw">crate</span> <span class="ident">cortex_m</span>;
|
||
|
||
<span class="kw">use</span> <span class="ident">cortex_m</span>::<span class="ident">peripheral</span>::{<span class="ident">DWT</span>, <span class="ident">Peripherals</span>};
|
||
|
||
<span class="kw">fn</span> <span class="ident">main</span>() {
|
||
{
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">peripherals</span> <span class="op">=</span> <span class="ident">Peripherals</span>::<span class="ident">take</span>().<span class="ident">unwrap</span>();
|
||
<span class="ident">peripherals</span>.<span class="ident">DWT</span>.<span class="ident">enable_cycle_counter</span>();
|
||
} <span class="comment">// all the peripheral singletons are destroyed here</span>
|
||
|
||
<span class="comment">// actually safe because this is an atomic read with no side effects</span>
|
||
<span class="kw">let</span> <span class="ident">cyccnt</span> <span class="op">=</span> <span class="kw">unsafe</span> { (<span class="kw-2">*</span><span class="ident">DWT</span>::<span class="ident">ptr</span>()).<span class="ident">cyccnt</span>.<span class="ident">read</span>() };
|
||
}</pre>
|
||
<h1 id="references" class="section-header"><a href="#references">References</a></h1>
|
||
<ul>
|
||
<li>ARMv7-M Architecture Reference Manual (Issue E.b) - Chapter B3</li>
|
||
</ul>
|
||
</div><h2 id='modules' class='section-header'><a href="#modules">Modules</a></h2>
|
||
<table>
|
||
<tr class=' module-item'>
|
||
<td><a class="mod" href="cbp/index.html"
|
||
title='mod cortex_m::peripheral::cbp'>cbp</a></td>
|
||
<td class='docblock-short'>
|
||
<p>Cache and branch predictor maintenance operations</p>
|
||
|
||
</td>
|
||
</tr>
|
||
<tr class=' module-item'>
|
||
<td><a class="mod" href="cpuid/index.html"
|
||
title='mod cortex_m::peripheral::cpuid'>cpuid</a></td>
|
||
<td class='docblock-short'>
|
||
<p>CPUID</p>
|
||
|
||
</td>
|
||
</tr>
|
||
<tr class=' module-item'>
|
||
<td><a class="mod" href="dcb/index.html"
|
||
title='mod cortex_m::peripheral::dcb'>dcb</a></td>
|
||
<td class='docblock-short'>
|
||
<p>Debug Control Block</p>
|
||
|
||
</td>
|
||
</tr>
|
||
<tr class=' module-item'>
|
||
<td><a class="mod" href="dwt/index.html"
|
||
title='mod cortex_m::peripheral::dwt'>dwt</a></td>
|
||
<td class='docblock-short'>
|
||
<p>Data Watchpoint and Trace unit</p>
|
||
|
||
</td>
|
||
</tr>
|
||
<tr class=' module-item'>
|
||
<td><a class="mod" href="fpb/index.html"
|
||
title='mod cortex_m::peripheral::fpb'>fpb</a></td>
|
||
<td class='docblock-short'>
|
||
<p>Flash Patch and Breakpoint unit</p>
|
||
|
||
</td>
|
||
</tr>
|
||
<tr class=' module-item'>
|
||
<td><a class="mod" href="fpu/index.html"
|
||
title='mod cortex_m::peripheral::fpu'>fpu</a></td>
|
||
<td class='docblock-short'>
|
||
<p>Floating Point Unit</p>
|
||
|
||
</td>
|
||
</tr>
|
||
<tr class=' module-item'>
|
||
<td><a class="mod" href="itm/index.html"
|
||
title='mod cortex_m::peripheral::itm'>itm</a></td>
|
||
<td class='docblock-short'>
|
||
<p>Instrumentation Trace Macrocell</p>
|
||
|
||
</td>
|
||
</tr>
|
||
<tr class=' module-item'>
|
||
<td><a class="mod" href="mpu/index.html"
|
||
title='mod cortex_m::peripheral::mpu'>mpu</a></td>
|
||
<td class='docblock-short'>
|
||
<p>Memory Protection Unit</p>
|
||
|
||
</td>
|
||
</tr>
|
||
<tr class=' module-item'>
|
||
<td><a class="mod" href="nvic/index.html"
|
||
title='mod cortex_m::peripheral::nvic'>nvic</a></td>
|
||
<td class='docblock-short'>
|
||
<p>Nested Vector Interrupt Controller</p>
|
||
|
||
</td>
|
||
</tr>
|
||
<tr class=' module-item'>
|
||
<td><a class="mod" href="scb/index.html"
|
||
title='mod cortex_m::peripheral::scb'>scb</a></td>
|
||
<td class='docblock-short'>
|
||
<p>System Control Block</p>
|
||
|
||
</td>
|
||
</tr>
|
||
<tr class=' module-item'>
|
||
<td><a class="mod" href="syst/index.html"
|
||
title='mod cortex_m::peripheral::syst'>syst</a></td>
|
||
<td class='docblock-short'>
|
||
<p>SysTick: System Timer</p>
|
||
|
||
</td>
|
||
</tr>
|
||
<tr class=' module-item'>
|
||
<td><a class="mod" href="tpiu/index.html"
|
||
title='mod cortex_m::peripheral::tpiu'>tpiu</a></td>
|
||
<td class='docblock-short'>
|
||
<p>Trace Port Interface Unit;</p>
|
||
|
||
</td>
|
||
</tr></table><h2 id='structs' class='section-header'><a href="#structs">Structs</a></h2>
|
||
<table>
|
||
<tr class=' module-item'>
|
||
<td><a class="struct" href="struct.CBP.html"
|
||
title='struct cortex_m::peripheral::CBP'>CBP</a></td>
|
||
<td class='docblock-short'>
|
||
<p>Cache and branch predictor maintenance operations</p>
|
||
|
||
</td>
|
||
</tr>
|
||
<tr class=' module-item'>
|
||
<td><a class="struct" href="struct.CPUID.html"
|
||
title='struct cortex_m::peripheral::CPUID'>CPUID</a></td>
|
||
<td class='docblock-short'>
|
||
<p>CPUID</p>
|
||
|
||
</td>
|
||
</tr>
|
||
<tr class=' module-item'>
|
||
<td><a class="struct" href="struct.DCB.html"
|
||
title='struct cortex_m::peripheral::DCB'>DCB</a></td>
|
||
<td class='docblock-short'>
|
||
<p>Debug Control Block</p>
|
||
|
||
</td>
|
||
</tr>
|
||
<tr class=' module-item'>
|
||
<td><a class="struct" href="struct.DWT.html"
|
||
title='struct cortex_m::peripheral::DWT'>DWT</a></td>
|
||
<td class='docblock-short'>
|
||
<p>Data Watchpoint and Trace unit</p>
|
||
|
||
</td>
|
||
</tr>
|
||
<tr class=' module-item'>
|
||
<td><a class="struct" href="struct.FPB.html"
|
||
title='struct cortex_m::peripheral::FPB'>FPB</a></td>
|
||
<td class='docblock-short'>
|
||
<p>Flash Patch and Breakpoint unit</p>
|
||
|
||
</td>
|
||
</tr>
|
||
<tr class=' module-item'>
|
||
<td><a class="struct" href="struct.FPU.html"
|
||
title='struct cortex_m::peripheral::FPU'>FPU</a></td>
|
||
<td class='docblock-short'>
|
||
<p>Floating Point Unit</p>
|
||
|
||
</td>
|
||
</tr>
|
||
<tr class=' module-item'>
|
||
<td><a class="struct" href="struct.ITM.html"
|
||
title='struct cortex_m::peripheral::ITM'>ITM</a></td>
|
||
<td class='docblock-short'>
|
||
<p>Instrumentation Trace Macrocell</p>
|
||
|
||
</td>
|
||
</tr>
|
||
<tr class=' module-item'>
|
||
<td><a class="struct" href="struct.MPU.html"
|
||
title='struct cortex_m::peripheral::MPU'>MPU</a></td>
|
||
<td class='docblock-short'>
|
||
<p>Memory Protection Unit</p>
|
||
|
||
</td>
|
||
</tr>
|
||
<tr class=' module-item'>
|
||
<td><a class="struct" href="struct.NVIC.html"
|
||
title='struct cortex_m::peripheral::NVIC'>NVIC</a></td>
|
||
<td class='docblock-short'>
|
||
<p>Nested Vector Interrupt Controller</p>
|
||
|
||
</td>
|
||
</tr>
|
||
<tr class=' module-item'>
|
||
<td><a class="struct" href="struct.Peripherals.html"
|
||
title='struct cortex_m::peripheral::Peripherals'>Peripherals</a></td>
|
||
<td class='docblock-short'>
|
||
<p>Core peripherals</p>
|
||
|
||
</td>
|
||
</tr>
|
||
<tr class=' module-item'>
|
||
<td><a class="struct" href="struct.SCB.html"
|
||
title='struct cortex_m::peripheral::SCB'>SCB</a></td>
|
||
<td class='docblock-short'>
|
||
<p>System Control Block</p>
|
||
|
||
</td>
|
||
</tr>
|
||
<tr class=' module-item'>
|
||
<td><a class="struct" href="struct.SYST.html"
|
||
title='struct cortex_m::peripheral::SYST'>SYST</a></td>
|
||
<td class='docblock-short'>
|
||
<p>SysTick: System Timer</p>
|
||
|
||
</td>
|
||
</tr>
|
||
<tr class=' module-item'>
|
||
<td><a class="struct" href="struct.TPIU.html"
|
||
title='struct cortex_m::peripheral::TPIU'>TPIU</a></td>
|
||
<td class='docblock-short'>
|
||
<p>Trace Port Interface Unit</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>⏎</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";</script><script src="../../aliases.js"></script><script src="../../main.js"></script><script defer src="../../search-index.js"></script></body></html> |