]> begriffs open source - cmsis/blob - v6.0.0/Core_A/startup_c_pg.html
Update documentation for branch main
[cmsis] / v6.0.0 / Core_A / startup_c_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-A): Startup File startup_&lt;Device&gt;.c</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-A)
44    &#160;<span id="projectnumber"><script type="text/javascript">
45      <!--
46      writeHeader.call(this);
47      writeVersionDropdown.call(this, "CMSIS-Core (Cortex-A)");
48      //-->
49     </script>
50    </span>
51    </div>
52    <div id="projectbrief">CMSIS-Core support for Cortex-A 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('startup_c_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">Startup File startup_&lt;Device&gt;.c </div></div>
128 </div><!--header-->
129 <div class="contents">
130 <div class="textblock"><p>The <a class="el" href="startup_c_pg.html">Startup File startup_&lt;Device&gt;.c</a> contains:</p><ul>
131 <li>Exception vectors of the Cortex-A Processor with weak functions that implement default routines.</li>
132 <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>
133 <li>The setup values for the various stack pointers, i.e. per exceptional mode and main stack.</li>
134 </ul>
135 <p>The file exists for each supported toolchain and is the only tool-chain specific CMSIS file.</p>
136 <h1><a class="anchor" id="startup_c_sec"></a>
137 startup_Device.c Template File</h1>
138 <p>An Arm Compiler specific startup file for an Armv7-A processor like Cortex-A9 is shown below. The files for other compiler vendors differ slightly in the syntax, but not in the overall structure.</p>
139 <pre class="fragment">/******************************************************************************
140  * @file     startup_&lt;Device&gt;.c
141  * @brief    CMSIS Cortex-A Device Startup
142  * @version  V1.00
143  * @date     10. January 2018
144  ******************************************************************************/
145 /*
146  * Copyright (c) 2009-2018 Arm Limited. All rights reserved.
147  *
148  * SPDX-License-Identifier: Apache-2.0
149  *
150  * Licensed under the Apache License, Version 2.0 (the License); you may
151  * not use this file except in compliance with the License.
152  * You may obtain a copy of the License at
153  *
154  * www.apache.org/licenses/LICENSE-2.0
155  *
156  * Unless required by applicable law or agreed to in writing, software
157  * distributed under the License is distributed on an AS IS BASIS, WITHOUT
158  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
159  * See the License for the specific language governing permissions and
160  * limitations under the License.
161  */
162
163 #include "&lt;Device&gt;.h" /* ToDo: replace '&lt;Device&gt;' with your device name */
164
165 /*----------------------------------------------------------------------------
166   Definitions
167  *----------------------------------------------------------------------------*/
168 #define USR_MODE 0x10            // User mode
169 #define FIQ_MODE 0x11            // Fast Interrupt Request mode
170 #define IRQ_MODE 0x12            // Interrupt Request mode
171 #define SVC_MODE 0x13            // Supervisor mode
172 #define ABT_MODE 0x17            // Abort mode
173 #define UND_MODE 0x1B            // Undefined Instruction mode
174 #define SYS_MODE 0x1F            // System mode
175
176 /*----------------------------------------------------------------------------
177   Internal References
178  *----------------------------------------------------------------------------*/
179 void Vectors       (void) __attribute__ ((section("RESET")));
180 void Reset_Handler (void);
181
182 /*----------------------------------------------------------------------------
183   Exception / Interrupt Handler
184  *----------------------------------------------------------------------------*/
185 void Undef_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
186 void SVC_Handler   (void) __attribute__ ((weak, alias("Default_Handler")));
187 void PAbt_Handler  (void) __attribute__ ((weak, alias("Default_Handler")));
188 void DAbt_Handler  (void) __attribute__ ((weak, alias("Default_Handler")));
189 void IRQ_Handler   (void) __attribute__ ((weak, alias("Default_Handler")));
190 void FIQ_Handler   (void) __attribute__ ((weak, alias("Default_Handler")));
191
192 /*----------------------------------------------------------------------------
193   Exception / Interrupt Vector Table
194  *----------------------------------------------------------------------------*/
195 __ASM void Vectors(void) {
196   IMPORT Undef_Handler
197   IMPORT SVC_Handler
198   IMPORT PAbt_Handler
199   IMPORT DAbt_Handler
200   IMPORT IRQ_Handler
201   IMPORT FIQ_Handler
202   LDR    PC, =Reset_Handler
203   LDR    PC, =Undef_Handler
204   LDR    PC, =SVC_Handler
205   LDR    PC, =PAbt_Handler
206   LDR    PC, =DAbt_Handler
207   NOP
208   LDR    PC, =IRQ_Handler
209   LDR    PC, =FIQ_Handler
210 }
211
212 /*----------------------------------------------------------------------------
213   Reset Handler called on controller reset
214  *----------------------------------------------------------------------------*/
215 __ASM void Reset_Handler(void) {
216
217   // Mask interrupts
218   CPSID   if                           
219
220   // Put any cores other than 0 to sleep
221   MRC     p15, 0, R0, c0, c0, 5       // Read MPIDR
222   ANDS    R0, R0, #3
223 goToSleep
224   WFINE
225   BNE     goToSleep
226
227   // Reset SCTLR Settings
228   MRC     p15, 0, R0, c1, c0, 0       // Read CP15 System Control register
229   BIC     R0, R0, #(0x1 &lt;&lt; 12)        // Clear I bit 12 to disable I Cache
230   BIC     R0, R0, #(0x1 &lt;&lt;  2)        // Clear C bit  2 to disable D Cache
231   BIC     R0, R0, #0x1                // Clear M bit  0 to disable MMU
232   BIC     R0, R0, #(0x1 &lt;&lt; 11)        // Clear Z bit 11 to disable branch prediction
233   BIC     R0, R0, #(0x1 &lt;&lt; 13)        // Clear V bit 13 to disable hivecs
234   MCR     p15, 0, R0, c1, c0, 0       // Write value back to CP15 System Control register
235   ISB
236
237   // Configure ACTLR
238   MRC     p15, 0, r0, c1, c0, 1       // Read CP15 Auxiliary Control Register
239   ORR     r0, r0, #(1 &lt;&lt;  1)          // Enable L2 prefetch hint (UNK/WI since r4p1)
240   MCR     p15, 0, r0, c1, c0, 1       // Write CP15 Auxiliary Control Register
241
242   // Set Vector Base Address Register (VBAR) to point to this application's vector table
243   LDR    R0, =Vectors
244   MCR    p15, 0, R0, c12, c0, 0
245
246   // Setup Stack for each exceptional mode
247   IMPORT |Image$$FIQ_STACK$$ZI$$Limit|
248   IMPORT |Image$$IRQ_STACK$$ZI$$Limit|
249   IMPORT |Image$$SVC_STACK$$ZI$$Limit|
250   IMPORT |Image$$ABT_STACK$$ZI$$Limit|
251   IMPORT |Image$$UND_STACK$$ZI$$Limit|
252   IMPORT |Image$$ARM_LIB_STACK$$ZI$$Limit|
253   CPS    #0x11
254   LDR    SP, =|Image$$FIQ_STACK$$ZI$$Limit|
255   CPS    #0x12
256   LDR    SP, =|Image$$IRQ_STACK$$ZI$$Limit|
257   CPS    #0x13
258   LDR    SP, =|Image$$SVC_STACK$$ZI$$Limit|
259   CPS    #0x17
260   LDR    SP, =|Image$$ABT_STACK$$ZI$$Limit|
261   CPS    #0x1B
262   LDR    SP, =|Image$$UND_STACK$$ZI$$Limit|
263   CPS    #0x1F
264   LDR    SP, =|Image$$ARM_LIB_STACK$$ZI$$Limit|
265
266   // Call SystemInit
267   IMPORT SystemInit
268   BL     SystemInit
269
270   // Unmask interrupts
271   CPSIE  if
272
273   // Call __main
274   IMPORT __main
275   BL     __main
276 }
277
278 /*----------------------------------------------------------------------------
279   Default Handler for Exceptions / Interrupts
280  *----------------------------------------------------------------------------*/
281 void Default_Handler(void) {
282   while(1);
283 }
284 </pre> </div></div><!-- contents -->
285 </div><!-- PageDoc -->
286 </div><!-- doc-content -->
287 <!-- start footer part -->
288 <div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
289   <ul>
290     <li class="footer">
291       <script type="text/javascript">
292         <!--
293         writeFooter.call(this);
294         //-->
295       </script> 
296     </li>
297   </ul>
298 </div>
299 </body>
300 </html>