]> begriffs open source - cmsis/blob - main/Core/using_pg.html
Update documentation for branch main
[cmsis] / main / Core / using_pg.html
1 <!-- HTML header for doxygen 1.9.6-->
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
4 <head>
5 <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
6 <meta http-equiv="X-UA-Compatible" content="IE=11"/>
7 <meta name="viewport" content="width=device-width, initial-scale=1"/>
8 <title>CMSIS-Core (Cortex-M): Using CMSIS-Core</title>
9 <link href="doxygen.css" rel="stylesheet" type="text/css" />
10 <script type="text/javascript" src="jquery.js"></script>
11 <script type="text/javascript" src="dynsections.js"></script>
12 <script type="text/javascript" src="tabs.js"></script>
13 <script type="text/javascript" src="footer.js"></script>
14 <script type="text/javascript" src="navtree.js"></script>
15 <link href="navtree.css" rel="stylesheet" type="text/css"/>
16 <script type="text/javascript" src="resize.js"></script>
17 <script type="text/javascript" src="navtreedata.js"></script>
18 <script type="text/javascript" src="navtree.js"></script>
19 <link href="search/search.css" rel="stylesheet" type="text/css"/>
20 <script type="text/javascript" src="search/searchdata.js"></script>
21 <script type="text/javascript" src="search/search.js"></script>
22 <script type="text/javascript">
23 /* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
24   $(document).ready(function() { init_search(); });
25 /* @license-end */
26 </script>
27 <script type="text/javascript" src="darkmode_toggle.js"></script>
28 <link href="extra_stylesheet.css" rel="stylesheet" type="text/css"/>
29 <link href="extra_navtree.css" rel="stylesheet" type="text/css"/>
30 <link href="extra_search.css" rel="stylesheet" type="text/css"/>
31 <link href="extra_tabs.css" rel="stylesheet" type="text/css"/>
32 <link href="version.css" rel="stylesheet" type="text/css"/>
33 <script type="text/javascript" src="../../version.js"></script>
34 </head>
35 <body>
36 <div id="top"><!-- do not remove this div, it is closed by doxygen! -->
37 <div id="titlearea">
38 <table cellspacing="0" cellpadding="0">
39  <tbody>
40  <tr style="height: 55px;">
41   <td id="projectlogo" style="padding: 1.5em;"><img alt="Logo" src="cmsis_logo_white_small.png"/></td>
42   <td style="padding-left: 1em; padding-bottom: 1em;padding-top: 1em;">
43    <div id="projectname">CMSIS-Core (Cortex-M)
44    &#160;<span id="projectnumber"><script type="text/javascript">
45      <!--
46      writeHeader.call(this);
47      writeVersionDropdown.call(this, "CMSIS-Core (Cortex-M)");
48      //-->
49     </script>
50    </span>
51    </div>
52    <div id="projectbrief">CMSIS-Core support for Cortex-M processor-based devices</div>
53   </td>
54    <td>        <div id="MSearchBox" class="MSearchBoxInactive">
55         <span class="left">
56           <span id="MSearchSelect"                onmouseover="return searchBox.OnSearchSelectShow()"                onmouseout="return searchBox.OnSearchSelectHide()">&#160;</span>
57           <input type="text" id="MSearchField" value="" placeholder="Search" accesskey="S"
58                onfocus="searchBox.OnSearchFieldFocus(true)" 
59                onblur="searchBox.OnSearchFieldFocus(false)" 
60                onkeyup="searchBox.OnSearchFieldChange(event)"/>
61           </span><span class="right">
62             <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.svg" alt=""/></a>
63           </span>
64         </div>
65 </td>
66   <!--END !PROJECT_NAME-->
67  </tr>
68  </tbody>
69 </table>
70 </div>
71 <!-- end header part -->
72 <div id="CMSISnav" class="tabs1">
73   <ul class="tablist">
74     <script type="text/javascript">
75       writeComponentTabs.call(this);
76     </script>
77   </ul>
78 </div>
79 <script type="text/javascript">
80   writeSubComponentTabs.call(this);
81 </script>
82 <!-- Generated by Doxygen 1.9.6 -->
83 <script type="text/javascript">
84 /* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
85 var searchBox = new SearchBox("searchBox", "search/",'.html');
86 /* @license-end */
87 </script>
88 </div><!-- top -->
89 <div id="side-nav" class="ui-resizable side-nav-resizable">
90   <div id="nav-tree">
91     <div id="nav-tree-contents">
92       <div id="nav-sync" class="sync"></div>
93     </div>
94   </div>
95   <div id="splitbar" style="-moz-user-select:none;" 
96        class="ui-resizable-handle">
97   </div>
98 </div>
99 <script type="text/javascript">
100 /* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
101 $(document).ready(function(){initNavTree('using_pg.html',''); initResizable(); });
102 /* @license-end */
103 </script>
104 <div id="doc-content">
105 <!-- window showing the filter options -->
106 <div id="MSearchSelectWindow"
107      onmouseover="return searchBox.OnSearchSelectShow()"
108      onmouseout="return searchBox.OnSearchSelectHide()"
109      onkeydown="return searchBox.OnSearchSelectKey(event)">
110 </div>
111
112 <!-- iframe showing the search results (closed by default) -->
113 <div id="MSearchResultsWindow">
114 <div id="MSearchResults">
115 <div class="SRPage">
116 <div id="SRIndex">
117 <div id="SRResults"></div>
118 <div class="SRStatus" id="Loading">Loading...</div>
119 <div class="SRStatus" id="Searching">Searching...</div>
120 <div class="SRStatus" id="NoMatches">No Matches</div>
121 </div>
122 </div>
123 </div>
124 </div>
125
126 <div><div class="header">
127   <div class="headertitle"><div class="title">Using CMSIS-Core </div></div>
128 </div><!--header-->
129 <div class="contents">
130 <div class="toc"><h3>Table of Contents</h3>
131 <ul><li class="level1"><a href="#using_packs">Usage in CMSIS-Packs</a></li>
132 <li class="level1"><a href="#usage_examples">Usage Examples</a><ul><li class="level2"><a href="#using_basic">Basic CMSIS Example</a></li>
133 <li class="level2"><a href="#using_vtor">Using Interrupt Vector Remap</a></li>
134 <li class="level2"><a href="#using_arm">Use generic Arm Devices</a></li>
135 <li class="level2"><a href="#using_ARM_Lib_sec">Create generic libraries</a></li>
136 </ul>
137 </li>
138 </ul>
139 </div>
140 <div class="textblock"><p><a class="anchor" id="md_src_using"></a></p>
141 <p>To use the CMSIS-Core (Cortex-M) in an embedded software project at the following <a class="el" href="cmsis_device_files.html">CMSIS-Core Device Files</a> need to be added to the application:</p>
142 <ul>
143 <li><a class="el" href="startup_c_pg.html">Startup File startup_&lt;Device&gt;.c</a> with reset handler and exception vectors.</li>
144 <li><a class="el" href="system_c_pg.html">System Configuration Files system_&lt;Device&gt;.c and system_&lt;Device&gt;.h</a> with general device configuration (i.e. for clock and BUS setup).</li>
145 <li><a class="el" href="device_h_pg.html">Device Header File &lt;Device.h&gt;</a> gives access to processor core and all peripherals.</li>
146 </ul>
147 <div class="image">
148 <img src="CMSIS_CORE_Files_USER.png" alt=""/>
149 <div class="caption">
150 Using CMSIS-Core (Cortex-M) in a project</div></div>
151     <p>The <a class="el" href="startup_c_pg.html">Startup File startup_&lt;Device&gt;.c</a> is executed after reset and calls <code><a class="el" href="group__system__init__gr.html#ga93f514700ccf00d08dbdcff7f1224eb2" title="Function to Initialize the system.">SystemInit()</a></code> in the reset hander. After the system initialization the control is transferred to the C/C++ run-time library which performs initialization and calls the <code>main</code> function in the user code. In addition the <a class="el" href="startup_c_pg.html">Startup File startup_&lt;Device&gt;.c</a> contains all exception and interrupt vectors and implements a default function for every interrupt. It may also contain stack and heap configurations for the user application.</p>
152 <p>The <a class="el" href="system_c_pg.html">System Configuration Files system_&lt;Device&gt;.c and system_&lt;Device&gt;.h</a> performs the setup for the processor clock. The variable <a class="el" href="group__system__init__gr.html#gaa3cd3e43291e81e795d642b79b6088e6">SystemCoreClock</a> indicates the CPU clock speed. In addition the file may contain functions for the memory BUS setup and clock re-configuration.</p>
153 <blockquote class="doxtable">
154 <p>&zwj;<b>Note</b></p><ul>
155 <li>The files <a class="el" href="startup_c_pg.html">Startup File startup_&lt;Device&gt;.c</a> and <a class="el" href="system_c_pg.html">System Configuration Files system_&lt;Device&gt;.c and system_&lt;Device&gt;.h</a> may require application specific adaptations and therefore should be copied into the application project folder prior configuration. </li>
156 </ul>
157 </blockquote>
158 <p>The <a class="el" href="device_h_pg.html">Device Header File &lt;Device.h&gt;</a> provides access to the following device-specific functionalities:</p>
159 <ul>
160 <li><a class="el" href="group__peripheral__gr.html">Peripheral Access</a> provides a standardized register layout for all peripherals. Optionally functions for device-specific peripherals may be available.</li>
161 <li><a class="el" href="group__NVIC__gr.html">Interrupts and Exceptions (NVIC)</a> can be accessed with standardized symbols and functions for the Nested Interrupt Vector Controller (NVIC) are provided.</li>
162 <li><a class="el" href="group__intrinsic__CPU__gr.html">Intrinsic Functions for CPU Instructions</a> allow to access special instructions, for example for activating sleep mode or the NOP instruction.</li>
163 <li><a class="el" href="group__intrinsic__SIMD__gr.html">Intrinsic Functions for SIMD Instructions</a> provide access to the DSP-oriented instructions.</li>
164 <li><a class="el" href="group__SysTick__gr.html">Systick Timer (SYSTICK)</a> function to configure and start a periodic timer interrupt.</li>
165 <li><a class="el" href="group__ITM__Debug__gr.html">Debug Access</a> are functions that allow printf-style I/O via the CoreSight Debug Unit and ITM communication.</li>
166 </ul>
167 <h1><a class="anchor" id="using_packs"></a>
168 Usage in CMSIS-Packs</h1>
169 <p>The easiest way to use CMSIS-Core in a project is with CMSIS Packs.</p>
170 <p>The <a class="el" href="cmsis_device_files.html">CMSIS-Core Device Files</a> are typically provided in a <a href="https://open-cmsis-pack.github.io/Open-CMSIS-Pack-Spec/main/html/cp_PackTutorial.html#createPack_DFP">CMSIS Device Family Pack (DFP)</a> that is maintained by the chip vendor for the target device family. The list of public CMSIS packs (including DFPs) can be found at <a href="https://www.keil.arm.com/packs/">keil.arm.com/packs</a>.</p>
171 <p>A Device Family Pack (DFP) usually has a requirement for using the <b>CMSIS:CORE</b> component from the <a href="../General/cmsis_pack.html">CMSIS Software pack</a> that contains the <a class="el" href="cmsis_core_files.html#cmsis_standard_files">CMSIS-Core Standard Files</a>. In such case the CMSIS Software pack needs to be installed as well.</p>
172 <p>The files <a class="el" href="startup_c_pg.html">Startup File startup_&lt;Device&gt;.c</a> and <a class="el" href="system_c_pg.html">System Configuration Files system_&lt;Device&gt;.c and system_&lt;Device&gt;.h</a> are typically provided in the DFP as part of <b>Device</b> class in the <b>Startup</b> group and are defined as configuration files, meaning they are copied from the pack into a project folder and can be modifed there if necessary.</p>
173 <p>The use of <a class="el" href="device_h_pg.html">Device Header File &lt;Device.h&gt;</a> can be abstracted with the <code>#define CMSIS_header_file</code> provided in <a href="https://open-cmsis-pack.github.io/Open-CMSIS-Pack-Spec/main/html/cp_Packs.html#cp_RTECompH">RTE_Components.h</a>. This allows to have uniform include code in the application independent of the target device.</p>
174 <div class="fragment"><div class="line"><span class="preprocessor">#include &quot;RTE_Components.h&quot;</span>                      <span class="comment">// include information about project configuration</span></div>
175 <div class="line"><span class="preprocessor">#include CMSIS_device_header                     </span><span class="comment">// include &lt;Device&gt;.h file</span></div>
176 </div><!-- fragment --><p>Thereafter, the functions described under <a href="modules.html">API Reference</a> can be used in the application.</p>
177 <p>For example, the following files are provided by the STM32F10x device family pack:</p>
178 <table class="markdownTable">
179 <tr class="markdownTableHead">
180 <th class="markdownTableHeadLeft">File   </th><th class="markdownTableHeadLeft">Description    </th></tr>
181 <tr class="markdownTableRowOdd">
182 <td class="markdownTableBodyLeft">".\Device\Source\ARM\startup_stm32f10x_cl.s"   </td><td class="markdownTableBodyLeft"><a class="el" href="startup_c_pg.html">Startup File startup_&lt;Device&gt;.c</a> for the STM32F10x device variants    </td></tr>
183 <tr class="markdownTableRowEven">
184 <td class="markdownTableBodyLeft">".\Device\Source\system_stmf10x.c"   </td><td class="markdownTableBodyLeft"><a class="el" href="system_c_pg.html">System Configuration Files system_&lt;Device&gt;.c and system_&lt;Device&gt;.h</a> for the STM32F10x device families    </td></tr>
185 <tr class="markdownTableRowOdd">
186 <td class="markdownTableBodyLeft">".\Device\Include\stm32f10x.h"   </td><td class="markdownTableBodyLeft"><a class="el" href="device_h_pg.html">Device Header File &lt;Device.h&gt;</a> for the STM32F10x device families   </td></tr>
187 </table>
188 <p><a class="el" href="cmsis_files_dfps.html">Delivery in CMSIS-Packs</a> provides more information on how CMSIS-Core files can be delivered in CMSIS Packs.</p>
189 <h1><a class="anchor" id="usage_examples"></a>
190 Usage Examples</h1>
191 <p><b>Examples</b></p>
192 <ul>
193 <li><a class="el" href="using_pg.html#using_basic">Basic CMSIS Example</a> is a simple example that shows the usage of the CMSIS layer.</li>
194 <li><a class="el" href="using_pg.html#using_vtor">Using Interrupt Vector Remap</a> shows how to remap the interrupt vector table.</li>
195 <li><a class="el" href="using_pg.html#using_arm">Use generic Arm Devices</a> explains how to use CMSIS-Core (Cortex-M) for Arm processors.</li>
196 <li><a class="el" href="using_pg.html#using_ARM_Lib_sec">Create generic libraries</a> explains how to create libraries that support various Cortex-M cores.</li>
197 </ul>
198 <p>Also see <a class="el" href="using_TrustZone_pg.html">Using TrustZone for Armv8-M</a> that details CMSIS-Core support for Arm TrusZone operation on Cortex-M.</p>
199 <h2><a class="anchor" id="using_basic"></a>
200 Basic CMSIS Example</h2>
201 <p>A typical example for using the CMSIS layer is provided below. The example is based on a STM32F10x Device.</p>
202 <div class="fragment"><div class="line"><span class="preprocessor">#include &lt;stm32f10x.h&gt;</span>                           <span class="comment">// File name depends on device used</span></div>
203 <div class="line"> </div>
204 <div class="line">uint32_t <span class="keyword">volatile</span> msTicks;                       <span class="comment">// Counter for millisecond Interval</span></div>
205 <div class="line"> </div>
206 <div class="line"><span class="keywordtype">void</span> SysTick_Handler (<span class="keywordtype">void</span>) {                    <span class="comment">// SysTick Interrupt Handler</span></div>
207 <div class="line">  msTicks++;                                     <span class="comment">// Increment Counter</span></div>
208 <div class="line">}</div>
209 <div class="line"> </div>
210 <div class="line"><span class="keywordtype">void</span> WaitForTick (<span class="keywordtype">void</span>)  {</div>
211 <div class="line">  uint32_t curTicks;</div>
212 <div class="line"> </div>
213 <div class="line">  curTicks = msTicks;                            <span class="comment">// Save Current SysTick Value</span></div>
214 <div class="line">  <span class="keywordflow">while</span> (msTicks == curTicks)  {                 <span class="comment">// Wait for next SysTick Interrupt</span></div>
215 <div class="line">    <a class="code hl_function" href="group__intrinsic__CPU__gr.html#gad3efec76c3bfa2b8528ded530386c563">__WFE</a> ();                                    <span class="comment">// Power-Down until next Event/Interrupt</span></div>
216 <div class="line">  }</div>
217 <div class="line">}</div>
218 <div class="line"> </div>
219 <div class="line"><span class="keywordtype">void</span> TIM1_UP_IRQHandler (<span class="keywordtype">void</span>) {                 <span class="comment">// Timer Interrupt Handler</span></div>
220 <div class="line">  ;                                              <span class="comment">// Add user code here</span></div>
221 <div class="line">}</div>
222 <div class="line"> </div>
223 <div class="line"><span class="keywordtype">void</span> timer1_init(<span class="keywordtype">int</span> frequency) {                <span class="comment">// Set up Timer (device specific)</span></div>
224 <div class="line">  <a class="code hl_function" href="group__NVIC__gr.html#ga5bb7f43ad92937c039dee3d36c3c2798">NVIC_SetPriority</a> (TIM1_UP_IRQn, 1);            <span class="comment">// Set Timer priority</span></div>
225 <div class="line">  <a class="code hl_function" href="group__NVIC__gr.html#ga530ad9fda2ed1c8b70e439ecfe80591f">NVIC_EnableIRQ</a> (TIM1_UP_IRQn);                 <span class="comment">// Enable Timer Interrupt</span></div>
226 <div class="line">}</div>
227 <div class="line"> </div>
228 <div class="line"> </div>
229 <div class="line"><span class="keywordtype">void</span> Device_Initialization (<span class="keywordtype">void</span>)  {             <span class="comment">// Configure &amp; Initialize MCU</span></div>
230 <div class="line">  <span class="keywordflow">if</span> (<a class="code hl_function" href="group__SysTick__gr.html#gabe47de40e9b0ad465b752297a9d9f427">SysTick_Config</a> (<a class="code hl_variable" href="group__system__init__gr.html#gaa3cd3e43291e81e795d642b79b6088e6">SystemCoreClock</a> / 1000)) { <span class="comment">// SysTick 1mSec</span></div>
231 <div class="line">       : <span class="comment">// Handle Error </span></div>
232 <div class="line">  }</div>
233 <div class="line">  timer1_init ();                                <span class="comment">// setup device-specific timer</span></div>
234 <div class="line">}</div>
235 <div class="line"> </div>
236 <div class="line"> </div>
237 <div class="line"><span class="comment">// The processor clock is initialized by CMSIS startup + system file</span></div>
238 <div class="line"><span class="keywordtype">void</span> main (<span class="keywordtype">void</span>) {                               <span class="comment">// user application starts here</span></div>
239 <div class="line">  Device_Initialization ();                      <span class="comment">// Configure &amp; Initialize MCU</span></div>
240 <div class="line">  <span class="keywordflow">while</span> (1)  {                                   <span class="comment">// Endless Loop (the Super-Loop)</span></div>
241 <div class="line">    <a class="code hl_function" href="group__Core__Register__gr.html#gaeb8e5f7564a8ea23678fe3c987b04013">__disable_irq</a> ();                            <span class="comment">// Disable all interrupts</span></div>
242 <div class="line">    Get_InputValues ();                          <span class="comment">// Read Values</span></div>
243 <div class="line">    <a class="code hl_function" href="group__Core__Register__gr.html#ga0f98dfbd252b89d12564472dbeba9c27">__enable_irq</a> ();                             <span class="comment">// Enable all interrupts </span></div>
244 <div class="line">    Calculation_Response ();                     <span class="comment">// Calculate Results</span></div>
245 <div class="line">    Output_Response ();                          <span class="comment">// Output Results</span></div>
246 <div class="line">    WaitForTick ();                              <span class="comment">// Synchronize to SysTick Timer</span></div>
247 <div class="line">  }</div>
248 <div class="line">}</div>
249 <div class="ttc" id="agroup__Core__Register__gr_html_ga0f98dfbd252b89d12564472dbeba9c27"><div class="ttname"><a href="group__Core__Register__gr.html#ga0f98dfbd252b89d12564472dbeba9c27">__enable_irq</a></div><div class="ttdeci">void __enable_irq(void)</div><div class="ttdoc">Globally enables interrupts and configurable fault handlers.</div></div>
250 <div class="ttc" id="agroup__Core__Register__gr_html_gaeb8e5f7564a8ea23678fe3c987b04013"><div class="ttname"><a href="group__Core__Register__gr.html#gaeb8e5f7564a8ea23678fe3c987b04013">__disable_irq</a></div><div class="ttdeci">void __disable_irq(void)</div><div class="ttdoc">Globally disables interrupts and configurable fault handlers.</div></div>
251 <div class="ttc" id="agroup__NVIC__gr_html_ga530ad9fda2ed1c8b70e439ecfe80591f"><div class="ttname"><a href="group__NVIC__gr.html#ga530ad9fda2ed1c8b70e439ecfe80591f">NVIC_EnableIRQ</a></div><div class="ttdeci">void NVIC_EnableIRQ(IRQn_Type IRQn)</div><div class="ttdoc">Enable a device specific interrupt.</div></div>
252 <div class="ttc" id="agroup__NVIC__gr_html_ga5bb7f43ad92937c039dee3d36c3c2798"><div class="ttname"><a href="group__NVIC__gr.html#ga5bb7f43ad92937c039dee3d36c3c2798">NVIC_SetPriority</a></div><div class="ttdeci">void NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority)</div><div class="ttdoc">Set the priority for an interrupt.</div></div>
253 <div class="ttc" id="agroup__SysTick__gr_html_gabe47de40e9b0ad465b752297a9d9f427"><div class="ttname"><a href="group__SysTick__gr.html#gabe47de40e9b0ad465b752297a9d9f427">SysTick_Config</a></div><div class="ttdeci">uint32_t SysTick_Config(uint32_t ticks)</div><div class="ttdoc">System Tick Timer Configuration.</div></div>
254 <div class="ttc" id="agroup__intrinsic__CPU__gr_html_gad3efec76c3bfa2b8528ded530386c563"><div class="ttname"><a href="group__intrinsic__CPU__gr.html#gad3efec76c3bfa2b8528ded530386c563">__WFE</a></div><div class="ttdeci">void __WFE(void)</div><div class="ttdoc">Wait For Event.</div></div>
255 <div class="ttc" id="agroup__system__init__gr_html_gaa3cd3e43291e81e795d642b79b6088e6"><div class="ttname"><a href="group__system__init__gr.html#gaa3cd3e43291e81e795d642b79b6088e6">SystemCoreClock</a></div><div class="ttdeci">uint32_t SystemCoreClock</div><div class="ttdoc">Variable to hold the system core clock value.</div><div class="ttdef"><b>Definition:</b> ref_system_init.txt:68</div></div>
256 </div><!-- fragment --><h2><a class="anchor" id="using_vtor"></a>
257 Using Interrupt Vector Remap</h2>
258 <p>Most Cortex-M processors provide VTOR register for remapping interrupt vectors. The following example shows a typical use case where the interrupt vectors are copied to RAM and the <code>SysTick_Handler</code> is replaced.</p>
259 <div class="fragment"><div class="line"><span class="preprocessor">#include &quot;ARMCM3.h&quot;</span>                     <span class="comment">// Device header</span></div>
260 <div class="line"> </div>
261 <div class="line"><span class="preprocessor">#define VECTORTABLE_SIZE        (240)    </span><span class="comment">/* size of the used vector tables    */</span><span class="preprocessor"></span></div>
262 <div class="line">                                         <span class="comment">/* see startup file startup_ARMCM3.c */</span></div>
263 <div class="line"><span class="preprocessor">#define VECTORTABLE_ALIGNMENT   (0x100U) </span><span class="comment">/* 16 Cortex + 32 ARMCM3 = 48 words  */</span><span class="preprocessor"></span></div>
264 <div class="line">                                         <span class="comment">/* next power of 2 = 256             */</span></div>
265 <div class="line"> </div>
266 <div class="line"><span class="comment">/* externals from startup_ARMCM3.c */</span></div>
267 <div class="line"><span class="keyword">extern</span> uint32_t <a class="code hl_define" href="group__compiler__conntrol__gr.html#gab94ebeb20055f1848d7b707d3c7cfc5d">__VECTOR_TABLE</a>[VECTORTABLE_SIZE];        <span class="comment">/* vector table ROM  */</span></div>
268 <div class="line"> </div>
269 <div class="line"><span class="comment">/* new vector table in RAM, same size as vector table in ROM */</span></div>
270 <div class="line">uint32_t vectorTable_RAM[VECTORTABLE_SIZE] __attribute__(( aligned (VECTORTABLE_ALIGNMENT) ));</div>
271 <div class="line"> </div>
272 <div class="line"> </div>
273 <div class="line"><span class="comment">/*----------------------------------------------------------------------------</span></div>
274 <div class="line"><span class="comment">  SysTick_Handler</span></div>
275 <div class="line"><span class="comment"> *----------------------------------------------------------------------------*/</span></div>
276 <div class="line"><span class="keyword">volatile</span> uint32_t msTicks = 0;                        <span class="comment">/* counts 1ms timeTicks */</span></div>
277 <div class="line"><span class="keywordtype">void</span> SysTick_Handler(<span class="keywordtype">void</span>) {</div>
278 <div class="line">  msTicks++;                                             <span class="comment">/* increment counter */</span></div>
279 <div class="line">}</div>
280 <div class="line"> </div>
281 <div class="line"><span class="comment">/*----------------------------------------------------------------------------</span></div>
282 <div class="line"><span class="comment">  SysTick_Handler (RAM)</span></div>
283 <div class="line"><span class="comment"> *----------------------------------------------------------------------------*/</span></div>
284 <div class="line"><span class="keyword">volatile</span> uint32_t msTicks_RAM = 0;                    <span class="comment">/* counts 1ms timeTicks */</span></div>
285 <div class="line"><span class="keywordtype">void</span> SysTick_Handler_RAM(<span class="keywordtype">void</span>) {</div>
286 <div class="line">  msTicks_RAM++;                                      <span class="comment">/* increment counter */</span></div>
287 <div class="line">}</div>
288 <div class="line"> </div>
289 <div class="line"><span class="comment">/*----------------------------------------------------------------------------</span></div>
290 <div class="line"><span class="comment">  MAIN function</span></div>
291 <div class="line"><span class="comment"> *----------------------------------------------------------------------------*/</span></div>
292 <div class="line"><span class="keywordtype">int</span> main (<span class="keywordtype">void</span>) {</div>
293 <div class="line">  uint32_t i;</div>
294 <div class="line">   </div>
295 <div class="line">  <span class="keywordflow">for</span> (i = 0; i &lt; VECTORTABLE_SIZE; i++) {</div>
296 <div class="line">    vectorTable_RAM[i] = <a class="code hl_define" href="group__compiler__conntrol__gr.html#gab94ebeb20055f1848d7b707d3c7cfc5d">__VECTOR_TABLE</a>[i];       <span class="comment">/* copy vector table to RAM */</span></div>
297 <div class="line">  }</div>
298 <div class="line">                                                   <span class="comment">/* replace SysTick Handler */</span></div>
299 <div class="line">  vectorTable_RAM[<a class="code hl_enumvalue" href="group__NVIC__gr.html#gga7e1129cd8a196f4284d41db3e82ad5c8a6dbff8f8543325f3474cbae2446776e7">SysTick_IRQn</a> + 16] = (uint32_t)SysTick_Handler_RAM;</div>
300 <div class="line">  </div>
301 <div class="line">  <span class="comment">/* relocate vector table */</span> </div>
302 <div class="line">  <a class="code hl_function" href="group__Core__Register__gr.html#gaeb8e5f7564a8ea23678fe3c987b04013">__disable_irq</a>();</div>
303 <div class="line">    SCB-&gt;VTOR = (uint32_t)&amp;vectorTable_RAM;</div>
304 <div class="line">  <a class="code hl_function" href="group__intrinsic__CPU__gr.html#gacb2a8ca6eae1ba4b31161578b720c199">__DSB</a>();</div>
305 <div class="line">  <a class="code hl_function" href="group__Core__Register__gr.html#ga0f98dfbd252b89d12564472dbeba9c27">__enable_irq</a>();</div>
306 <div class="line"> </div>
307 <div class="line">  <a class="code hl_function" href="group__system__init__gr.html#gae0c36a9591fe6e9c45ecb21a794f0f0f">SystemCoreClockUpdate</a>();                        <span class="comment">/* Get Core Clock Frequency */</span></div>
308 <div class="line">  <a class="code hl_function" href="group__SysTick__gr.html#gabe47de40e9b0ad465b752297a9d9f427">SysTick_Config</a>(<a class="code hl_variable" href="group__system__init__gr.html#gaa3cd3e43291e81e795d642b79b6088e6">SystemCoreClock</a> / 1000ul); <span class="comment">/* Setup SysTick Timer for 1 msec */</span></div>
309 <div class="line">   </div>
310 <div class="line">  <span class="keywordflow">while</span>(1);</div>
311 <div class="line">}</div>
312 <div class="ttc" id="agroup__NVIC__gr_html_gga7e1129cd8a196f4284d41db3e82ad5c8a6dbff8f8543325f3474cbae2446776e7"><div class="ttname"><a href="group__NVIC__gr.html#gga7e1129cd8a196f4284d41db3e82ad5c8a6dbff8f8543325f3474cbae2446776e7">SysTick_IRQn</a></div><div class="ttdeci">@ SysTick_IRQn</div><div class="ttdoc">Exception 15: System Tick Interrupt.</div><div class="ttdef"><b>Definition:</b> ref_nvic.txt:398</div></div>
313 <div class="ttc" id="agroup__compiler__conntrol__gr_html_gab94ebeb20055f1848d7b707d3c7cfc5d"><div class="ttname"><a href="group__compiler__conntrol__gr.html#gab94ebeb20055f1848d7b707d3c7cfc5d">__VECTOR_TABLE</a></div><div class="ttdeci">#define __VECTOR_TABLE</div><div class="ttdoc">Symbol name used for the (static) interrupt vector table.</div><div class="ttdef"><b>Definition:</b> ref_compiler_ctrl.txt:520</div></div>
314 <div class="ttc" id="agroup__intrinsic__CPU__gr_html_gacb2a8ca6eae1ba4b31161578b720c199"><div class="ttname"><a href="group__intrinsic__CPU__gr.html#gacb2a8ca6eae1ba4b31161578b720c199">__DSB</a></div><div class="ttdeci">void __DSB(void)</div><div class="ttdoc">Data Synchronization Barrier.</div></div>
315 <div class="ttc" id="agroup__system__init__gr_html_gae0c36a9591fe6e9c45ecb21a794f0f0f"><div class="ttname"><a href="group__system__init__gr.html#gae0c36a9591fe6e9c45ecb21a794f0f0f">SystemCoreClockUpdate</a></div><div class="ttdeci">void SystemCoreClockUpdate(void)</div><div class="ttdoc">Function to update the variable SystemCoreClock.</div></div>
316 </div><!-- fragment --><h2><a class="anchor" id="using_arm"></a>
317 Use generic Arm Devices</h2>
318 <p>Test and example projects of many software components have a need for implementations that are independent from specific device vendors but still have adaptations for various Arm Cortex-M cores to benefit from their architectural differenceis.</p>
319 <p>The <a href="https://github.com/ARM-software/Cortex_DFP">Cortex_DFP pack</a> provides generic device definitions for standard Arm Cortex-M cores and contains corresponding <a class="el" href="cmsis_device_files.html">CMSIS-Core Device Files</a>. These generic Arm devices can be used as a target for embedded programs, with execution, for example, on processor simulation models.</p>
320 <p>Validation suits and example projects for such components as <a href="../DSP/index.html">CMSIS-DSP</a>, <a href="../RTOS2/index.html">CMSIS-RTOS</a> and <a href="index.html">CMSIS-Core</a> itself use that approach already.</p>
321 <h2><a class="anchor" id="using_ARM_Lib_sec"></a>
322 Create generic libraries</h2>
323 <p>The CMSIS Processor and Core Peripheral files allow also to create generic libraries. The <a href="../DSP/index.html">CMSIS-DSP libraries</a> are an example for such a generic library.</p>
324 <p>To build a generic Library set the define <code>__CMSIS_GENERIC</code> and include the relevant <code>core_&lt;cpu&gt;.h</code> CMSIS CPU &amp; Core Access header file for the processor.</p>
325 <p>The define <code>__CMSIS_GENERIC</code> disables device-dependent features such as the <b>SysTick</b> timer and the <b>Interrupt System</b>.</p>
326 <p>Refer to <a class="el" href="device_h_pg.html#core_config_sect">Configuration of the Processor and Core Peripherals</a> for a list of the available <code>core_&lt;cpu&gt;.h</code> header files.</p>
327 <p><b>Example:</b></p>
328 <p>The following code section shows the usage of the <code>core_&lt;cpu&gt;.h</code> header files to build a generic library for Cortex-M0, Cortex-M3, Cortex-M4, or Cortex-M7 devices.</p>
329 <p>To select the processor, the source code uses the defines <code>CORTEX_M7</code>, <code>CORTEX_M4</code>, <code>CORTEX_M3</code>, <code>CORTEX_M0</code>, or <code>CORTEX_M0PLUS</code>. One of these defines needs to be provided on the compiler command line. By using this header file, the source code can access the correct implementations for <a class="el" href="group__Core__Register__gr.html">Core Register Access</a>, <a class="el" href="group__intrinsic__CPU__gr.html">Intrinsic Functions for CPU Instructions</a>, <a class="el" href="group__intrinsic__SIMD__gr.html">Intrinsic Functions for SIMD Instructions</a>, and <a class="el" href="group__ITM__Debug__gr.html">Debug Access</a>.</p>
330 <div class="fragment"><div class="line"><span class="preprocessor">#define __CMSIS_GENERIC              </span><span class="comment">/* disable NVIC and Systick functions */</span><span class="preprocessor"></span></div>
331 <div class="line"> </div>
332 <div class="line"><span class="preprocessor">#if defined (CORTEX_M7)</span></div>
333 <div class="line"><span class="preprocessor">  #include &quot;core_cm7.h&quot;</span></div>
334 <div class="line"><span class="preprocessor">#elif defined (CORTEX_M4)</span></div>
335 <div class="line"><span class="preprocessor">  #include &quot;core_cm4.h&quot;</span></div>
336 <div class="line"><span class="preprocessor">#elif defined (CORTEX_M3)</span></div>
337 <div class="line"><span class="preprocessor">  #include &quot;core_cm3.h&quot;</span></div>
338 <div class="line"><span class="preprocessor">#elif defined (CORTEX_M0)</span></div>
339 <div class="line"><span class="preprocessor">  #include &quot;core_cm0.h&quot;</span></div>
340 <div class="line"><span class="preprocessor">#elif defined (CORTEX_M0PLUS)</span></div>
341 <div class="line"><span class="preprocessor">  #include &quot;core_cm0plus.h&quot;</span></div>
342 <div class="line"><span class="preprocessor">#else</span></div>
343 <div class="line"><span class="preprocessor">  #error &quot;Processor not specified or unsupported.&quot;</span></div>
344 <div class="line"><span class="preprocessor">#endif</span></div>
345 </div><!-- fragment --> </div></div><!-- contents -->
346 </div><!-- PageDoc -->
347 </div><!-- doc-content -->
348 <!-- start footer part -->
349 <div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
350   <ul>
351     <li class="footer">
352       <script type="text/javascript">
353         <!--
354         writeFooter.call(this);
355         //-->
356       </script> 
357     </li>
358   </ul>
359 </div>
360 </body>
361 </html>