startup_c_pg.html 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
  5. <meta http-equiv="X-UA-Compatible" content="IE=9"/>
  6. <title>Startup File startup_&lt;device&gt;.c</title>
  7. <title>CMSIS-Core (Cortex-M): Startup File startup_&lt;device&gt;.c</title>
  8. <link href="tabs.css" rel="stylesheet" type="text/css"/>
  9. <link href="cmsis.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="printComponentTabs.js"></script>
  13. <link href="navtree.css" rel="stylesheet" type="text/css"/>
  14. <script type="text/javascript" src="resize.js"></script>
  15. <script type="text/javascript" src="navtree.js"></script>
  16. <script type="text/javascript">
  17. $(document).ready(initResizable);
  18. $(window).load(resizeHeight);
  19. </script>
  20. <link href="search/search.css" rel="stylesheet" type="text/css"/>
  21. <script type="text/javascript" src="search/search.js"></script>
  22. <script type="text/javascript">
  23. $(document).ready(function() { searchBox.OnSelectItem(0); });
  24. </script>
  25. </head>
  26. <body>
  27. <div id="top"><!-- do not remove this div, it is closed by doxygen! -->
  28. <div id="titlearea">
  29. <table cellspacing="0" cellpadding="0">
  30. <tbody>
  31. <tr style="height: 46px;">
  32. <td id="projectlogo"><img alt="Logo" src="CMSIS_Logo_Final.png"/></td>
  33. <td style="padding-left: 0.5em;">
  34. <div id="projectname">CMSIS-Core (Cortex-M)
  35. &#160;<span id="projectnumber">Version 5.4.0</span>
  36. </div>
  37. <div id="projectbrief">CMSIS-Core support for Cortex-M processor-based devices</div>
  38. </td>
  39. </tr>
  40. </tbody>
  41. </table>
  42. </div>
  43. <!-- end header part -->
  44. <div id="CMSISnav" class="tabs1">
  45. <ul class="tablist">
  46. <script type="text/javascript">
  47. <!--
  48. writeComponentTabs.call(this);
  49. //-->
  50. </script>
  51. </ul>
  52. </div>
  53. <!-- Generated by Doxygen 1.8.6 -->
  54. <script type="text/javascript">
  55. var searchBox = new SearchBox("searchBox", "search",false,'Search');
  56. </script>
  57. <div id="navrow1" class="tabs">
  58. <ul class="tablist">
  59. <li><a href="index.html"><span>Main&#160;Page</span></a></li>
  60. <li class="current"><a href="pages.html"><span>Usage&#160;and&#160;Description</span></a></li>
  61. <li><a href="modules.html"><span>Reference</span></a></li>
  62. <li>
  63. <div id="MSearchBox" class="MSearchBoxInactive">
  64. <span class="left">
  65. <img id="MSearchSelect" src="search/mag_sel.png"
  66. onmouseover="return searchBox.OnSearchSelectShow()"
  67. onmouseout="return searchBox.OnSearchSelectHide()"
  68. alt=""/>
  69. <input type="text" id="MSearchField" value="Search" accesskey="S"
  70. onfocus="searchBox.OnSearchFieldFocus(true)"
  71. onblur="searchBox.OnSearchFieldFocus(false)"
  72. onkeyup="searchBox.OnSearchFieldChange(event)"/>
  73. </span><span class="right">
  74. <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
  75. </span>
  76. </div>
  77. </li>
  78. </ul>
  79. </div>
  80. </div><!-- top -->
  81. <div id="side-nav" class="ui-resizable side-nav-resizable">
  82. <div id="nav-tree">
  83. <div id="nav-tree-contents">
  84. <div id="nav-sync" class="sync"></div>
  85. </div>
  86. </div>
  87. <div id="splitbar" style="-moz-user-select:none;"
  88. class="ui-resizable-handle">
  89. </div>
  90. </div>
  91. <script type="text/javascript">
  92. $(document).ready(function(){initNavTree('startup_c_pg.html','');});
  93. </script>
  94. <div id="doc-content">
  95. <!-- window showing the filter options -->
  96. <div id="MSearchSelectWindow"
  97. onmouseover="return searchBox.OnSearchSelectShow()"
  98. onmouseout="return searchBox.OnSearchSelectHide()"
  99. onkeydown="return searchBox.OnSearchSelectKey(event)">
  100. <a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Data Structures</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Groups</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark">&#160;</span>Pages</a></div>
  101. <!-- iframe showing the search results (closed by default) -->
  102. <div id="MSearchResultsWindow">
  103. <iframe src="javascript:void(0)" frameborder="0"
  104. name="MSearchResults" id="MSearchResults">
  105. </iframe>
  106. </div>
  107. <div class="header">
  108. <div class="headertitle">
  109. <div class="title">Startup File startup_&lt;device&gt;.c </div> </div>
  110. </div><!--header-->
  111. <div class="contents">
  112. <div class="textblock"><p>The <a class="el" href="startup_c_pg.html">Startup File startup_&lt;device&gt;.c</a> contains:</p>
  113. <ul>
  114. <li>The reset handler which is executed after CPU reset and typically calls the <a class="el" href="group__system__init__gr.html#ga93f514700ccf00d08dbdcff7f1224eb2">SystemInit</a> function.</li>
  115. <li>The setup values for the Main Stack Pointer (MSP).</li>
  116. <li>Exception vectors of the Cortex-M Processor with weak functions that implement default routines.</li>
  117. <li>Interrupt vectors that are device specific with weak functions that implement default routines.</li>
  118. </ul>
  119. <p>The file exists for each supported toolchain and is the only tool-chain specific CMSIS file.</p>
  120. <p>To adapt the file to a new device only the interrupt vector table needs to be extended with the device-specific interrupt handlers. The naming convention for the interrupt handler names are &lt;interrupt_name&gt;_IRQHandler. This table needs to be consistent with <a class="el" href="group__NVIC__gr.html#ga7e1129cd8a196f4284d41db3e82ad5c8">IRQn_Type</a> that defines all the IRQ numbers for each interrupt.</p>
  121. <p><b>Example:</b> </p>
  122. <p>The following example shows the extension of the interrupt vector table for the LPC1100 device family.</p>
  123. <div class="fragment"><div class="line"><span class="comment">/*----------------------------------------------------------------------------</span></div>
  124. <div class="line"><span class="comment"> Exception / Interrupt Handler</span></div>
  125. <div class="line"><span class="comment"> *----------------------------------------------------------------------------*/</span></div>
  126. <div class="line"><span class="comment">/* Exceptions */</span></div>
  127. <div class="line"><span class="keywordtype">void</span> WAKEUP0_IRQHandler (<span class="keywordtype">void</span>) __attribute__ ((weak, alias(&quot;Default_Handler&quot;)));</div>
  128. <div class="line"><span class="keywordtype">void</span> WAKEUP1_IRQHandler (<span class="keywordtype">void</span>) __attribute__ ((weak, alias(&quot;Default_Handler&quot;)));</div>
  129. <div class="line"><span class="keywordtype">void</span> WAKEUP2_IRQHandler (<span class="keywordtype">void</span>) __attribute__ ((weak, alias(&quot;Default_Handler&quot;)));</div>
  130. <div class="line"><span class="comment">// :</span></div>
  131. <div class="line"><span class="comment">// :</span></div>
  132. <div class="line"><span class="keywordtype">void</span> EINT1_IRQHandler (<span class="keywordtype">void</span>) __attribute__ ((weak, alias(&quot;Default_Handler&quot;)));</div>
  133. <div class="line"><span class="keywordtype">void</span> EINT2_IRQHandler (<span class="keywordtype">void</span>) __attribute__ ((weak, alias(&quot;Default_Handler&quot;)));</div>
  134. <div class="line"><span class="comment">// :</span></div>
  135. <div class="line"><span class="comment">// :</span></div>
  136. <div class="line"></div>
  137. <div class="line"><span class="comment">/*----------------------------------------------------------------------------</span></div>
  138. <div class="line"><span class="comment"> Exception / Interrupt Vector table</span></div>
  139. <div class="line"><span class="comment"> *----------------------------------------------------------------------------*/</span></div>
  140. <div class="line">extern const pFunc __VECTOR_TABLE[240];</div>
  141. <div class="line"> const pFunc __VECTOR_TABLE[240] <a class="code" href="group__compiler__conntrol__gr.html#ga4f65c96effa79fbd610fea43ee7d745b">__VECTOR_TABLE_ATTRIBUTE</a> = {</div>
  142. <div class="line"> (pFunc)(&amp;<a class="code" href="group__compiler__conntrol__gr.html#ga1002e751427b1189f92787d4e4eef965">__INITIAL_SP</a>), <span class="comment">/* Initial Stack Pointer */</span></div>
  143. <div class="line"> Reset_Handler, <span class="comment">/* Reset Handler */</span></div>
  144. <div class="line"> NMI_Handler, <span class="comment">/* -14 NMI Handler */</span></div>
  145. <div class="line"> HardFault_Handler, <span class="comment">/* -13 Hard Fault Handler */</span></div>
  146. <div class="line"> MemManage_Handler, <span class="comment">/* -12 MPU Fault Handler */</span></div>
  147. <div class="line"> BusFault_Handler, <span class="comment">/* -11 Bus Fault Handler */</span></div>
  148. <div class="line"> UsageFault_Handler, <span class="comment">/* -10 Usage Fault Handler */</span></div>
  149. <div class="line"> 0, <span class="comment">/* Reserved */</span></div>
  150. <div class="line"> 0, <span class="comment">/* Reserved */</span></div>
  151. <div class="line"> 0, <span class="comment">/* Reserved */</span></div>
  152. <div class="line"> 0, <span class="comment">/* Reserved */</span></div>
  153. <div class="line"> SVC_Handler, <span class="comment">/* -5 SVCall Handler */</span></div>
  154. <div class="line"> DebugMon_Handler, <span class="comment">/* -4 Debug Monitor Handler */</span></div>
  155. <div class="line"> 0, <span class="comment">/* Reserved */</span></div>
  156. <div class="line"> PendSV_Handler, <span class="comment">/* -2 PendSV Handler */</span></div>
  157. <div class="line"> SysTick_Handler, <span class="comment">/* -1 SysTick Handler */</span></div>
  158. <div class="line"></div>
  159. <div class="line"> <span class="comment">/* Interrupts */</span></div>
  160. <div class="line"> WAKEUP0_IRQHandler, <span class="comment">/* 0 Wakeup PIO0.0 */</span></div>
  161. <div class="line"> WAKEUP1_IRQHandler, <span class="comment">/* 1 Wakeup PIO0.1 */</span></div>
  162. <div class="line"> WAKEUP2_IRQHandler, <span class="comment">/* 2 Wakeup PIO0.2 */</span></div>
  163. <div class="line"> <span class="comment">// :</span></div>
  164. <div class="line"> <span class="comment">// :</span></div>
  165. <div class="line"> EINT1_IRQHandler, <span class="comment">/* 30 PIO INT1 */</span></div>
  166. <div class="line"> EINT2_IRQHandler, <span class="comment">/* 31 PIO INT2 */</span></div>
  167. <div class="line"> <span class="comment">// :</span></div>
  168. <div class="line"> <span class="comment">// :</span></div>
  169. <div class="line">};</div>
  170. </div><!-- fragment --><h1><a class="anchor" id="startup_c_sec"></a>
  171. startup_Device.c Template File</h1>
  172. <p>A compiler agnostic <a class="el" href="startup_c_pg.html#startup_c_sec">startup_Device.c Template File</a> for an Armv7-M processor like Cortex-M3 is shown below. The C startup file relys on certain compiler specific preprocessor defines specified in CMSIS compiler headers:</p>
  173. <ul>
  174. <li><a class="el" href="group__compiler__conntrol__gr.html#ga1002e751427b1189f92787d4e4eef965">__INITIAL_SP</a></li>
  175. <li><a class="el" href="group__compiler__conntrol__gr.html#ga84b0bad4aa39632d3faea46aa1e102a8">__STACK_LIMIT</a></li>
  176. <li><a class="el" href="group__compiler__conntrol__gr.html#ga72db8b026c5e100254080fefabd9fd88">__PROGRAM_START</a></li>
  177. <li><a class="el" href="group__compiler__conntrol__gr.html#gab94ebeb20055f1848d7b707d3c7cfc5d">__VECTOR_TABLE</a></li>
  178. <li><a class="el" href="group__compiler__conntrol__gr.html#ga4f65c96effa79fbd610fea43ee7d745b">__VECTOR_TABLE_ATTRIBUTE</a></li>
  179. </ul>
  180. <pre class="fragment">/******************************************************************************
  181. * @file startup_Device.c
  182. * @brief CMSIS-Core(M) Device Startup File for &lt;Device&gt;
  183. * @version V2.0.0
  184. * @date 20. May 2019
  185. ******************************************************************************/
  186. /*
  187. * Copyright (c) 2009-2019 Arm Limited. All rights reserved.
  188. *
  189. * SPDX-License-Identifier: Apache-2.0
  190. *
  191. * Licensed under the Apache License, Version 2.0 (the License); you may
  192. * not use this file except in compliance with the License.
  193. * You may obtain a copy of the License at
  194. *
  195. * www.apache.org/licenses/LICENSE-2.0
  196. *
  197. * Unless required by applicable law or agreed to in writing, software
  198. * distributed under the License is distributed on an AS IS BASIS, WITHOUT
  199. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  200. * See the License for the specific language governing permissions and
  201. * limitations under the License.
  202. */
  203. #include "&lt;Device&gt;.h"
  204. /*----------------------------------------------------------------------------
  205. Exception / Interrupt Handler Function Prototype
  206. *----------------------------------------------------------------------------*/
  207. typedef void( *pFunc )( void );
  208. /*----------------------------------------------------------------------------
  209. External References
  210. *----------------------------------------------------------------------------*/
  211. extern uint32_t __INITIAL_SP;
  212. extern __NO_RETURN void __PROGRAM_START(void);
  213. /*----------------------------------------------------------------------------
  214. Internal References
  215. *----------------------------------------------------------------------------*/
  216. void __NO_RETURN Default_Handler(void);
  217. void __NO_RETURN Reset_Handler (void);
  218. /*----------------------------------------------------------------------------
  219. Exception / Interrupt Handler
  220. *----------------------------------------------------------------------------*/
  221. /* Exceptions */
  222. void NMI_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
  223. void HardFault_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
  224. void MemManage_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
  225. void BusFault_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
  226. void UsageFault_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
  227. void SVC_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
  228. void DebugMon_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
  229. void PendSV_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
  230. void SysTick_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
  231. void Interrupt0_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
  232. void Interrupt1_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
  233. void Interrupt2_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
  234. void Interrupt3_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
  235. void Interrupt4_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
  236. void Interrupt5_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
  237. void Interrupt6_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
  238. void Interrupt7_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
  239. void Interrupt8_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
  240. void Interrupt9_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
  241. /*----------------------------------------------------------------------------
  242. Exception / Interrupt Vector table
  243. *----------------------------------------------------------------------------*/
  244. extern const pFunc __VECTOR_TABLE[240];
  245. const pFunc __VECTOR_TABLE[240] __VECTOR_TABLE_ATTRIBUTE = {
  246. (pFunc)(&amp;__INITIAL_SP), /* Initial Stack Pointer */
  247. Reset_Handler, /* Reset Handler */
  248. NMI_Handler, /* -14 NMI Handler */
  249. HardFault_Handler, /* -13 Hard Fault Handler */
  250. MemManage_Handler, /* -12 MPU Fault Handler */
  251. BusFault_Handler, /* -11 Bus Fault Handler */
  252. UsageFault_Handler, /* -10 Usage Fault Handler */
  253. 0, /* Reserved */
  254. 0, /* Reserved */
  255. 0, /* Reserved */
  256. 0, /* Reserved */
  257. SVC_Handler, /* -5 SVCall Handler */
  258. DebugMon_Handler, /* -4 Debug Monitor Handler */
  259. 0, /* Reserved */
  260. PendSV_Handler, /* -2 PendSV Handler */
  261. SysTick_Handler, /* -1 SysTick Handler */
  262. /* Interrupts */
  263. Interrupt0_Handler, /* 0 Interrupt 0 */
  264. Interrupt1_Handler, /* 1 Interrupt 1 */
  265. Interrupt2_Handler, /* 2 Interrupt 2 */
  266. Interrupt3_Handler, /* 3 Interrupt 3 */
  267. Interrupt4_Handler, /* 4 Interrupt 4 */
  268. Interrupt5_Handler, /* 5 Interrupt 5 */
  269. Interrupt6_Handler, /* 6 Interrupt 6 */
  270. Interrupt7_Handler, /* 7 Interrupt 7 */
  271. Interrupt8_Handler, /* 8 Interrupt 8 */
  272. Interrupt9_Handler /* 9 Interrupt 9 */
  273. /* Interrupts 10 .. 223 are left out */
  274. };
  275. /*----------------------------------------------------------------------------
  276. Reset Handler called on controller reset
  277. *----------------------------------------------------------------------------*/
  278. void Reset_Handler(void)
  279. {
  280. SystemInit(); /* CMSIS System Initialization */
  281. __PROGRAM_START(); /* Enter PreMain (C library entry point) */
  282. }
  283. /*----------------------------------------------------------------------------
  284. Default Handler for Exceptions / Interrupts
  285. *----------------------------------------------------------------------------*/
  286. void Default_Handler(void)
  287. {
  288. while(1);
  289. }
  290. </pre> </div></div><!-- contents -->
  291. </div><!-- doc-content -->
  292. <!-- start footer part -->
  293. <div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  294. <ul>
  295. <li class="navelem"><a class="el" href="templates_pg.html">CMSIS-Core Device Templates</a></li>
  296. <li class="footer">Generated on Thu Apr 9 2020 15:49:07 for CMSIS-Core (Cortex-M) Version 5.4.0 by Arm Ltd. All rights reserved.
  297. <!--
  298. <a href="http://www.doxygen.org/index.html">
  299. <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.6
  300. -->
  301. </li>
  302. </ul>
  303. </div>
  304. </body>
  305. </html>