]> git.piffa.net Git - arduino/blob - sheets/gyro/GY-52 Three-axis gyroscope sending data /Three-axis gyroscope sending data/GY-52 Test program/STM32-CODE/serial port output MPU-3050/serial/Libraries/CMSIS/Core/Documentation/CMSIS_Core.htm
first commit
[arduino] / sheets / gyro / GY-52 Three-axis gyroscope sending data / Three-axis gyroscope sending data / GY-52 Test program / STM32-CODE / serial port output MPU-3050 / serial / Libraries / CMSIS / Core / Documentation / CMSIS_Core.htm
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">\r
2 <html xmlns:p="urn:schemas-microsoft-com:office:powerpoint" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office"><head>\r
3   \r
4   <title>CMSIS: Cortex Microcontroller Software Interface Standard</title><meta http-equiv="Content-Type" content="text/html; charset=windows-1252">\r
5   <meta name="ProgId" content="FrontPage.Editor.Document">\r
6   <style>\r
7 <!--\r
8 /*-----------------------------------------------------------Keil Software CHM Style Sheet\r
9 -----------------------------------------------------------*/\r
10 body { color: #000000; background-color: #FFFFFF; font-size: 75%; font-family: Verdana, Arial, 'Sans Serif' }\r
11 a:link { color: #0000FF; text-decoration: underline }\r
12 a:visited { color: #0000FF; text-decoration: underline }\r
13 a:active { color: #FF0000; text-decoration: underline }\r
14 a:hover { color: #FF0000; text-decoration: underline }\r
15 h1 { font-family: Verdana; font-size: 18pt; color: #000080; font-weight: bold; text-align: Center; margin-right: 3 }\r
16 h2 { font-family: Verdana; font-size: 14pt; color: #000080; font-weight: bold; background-color: #CCCCCC; margin-top: 24; margin-bottom: 3; padding: 6 }\r
17 h3 { font-family: Verdana; font-size: 10pt; font-weight: bold; background-color: #CCCCCC; margin-top: 24; margin-bottom: 3; padding: 6 }\r
18 pre { font-family: Courier New; font-size: 10pt; background-color: #CCFFCC; margin-left: 24; margin-right: 24 }\r
19 ul { list-style-type: square; margin-top: 6pt; margin-bottom: 0 }\r
20 ol { margin-top: 6pt; margin-bottom: 0 }\r
21 li { clear: both; margin-bottom: 6pt }\r
22 table { font-size: 100%; border-width: 0; padding: 0 }\r
23 th { color: #FFFFFF; background-color: #000080; text-align: left; vertical-align: bottom; padding-right: 6pt }\r
24 tr { text-align: left; vertical-align: top }\r
25 td { text-align: left; vertical-align: top; padding-right: 6pt }\r
26 .ToolT { font-size: 8pt; color: #808080 }\r
27 .TinyT { font-size: 8pt; text-align: Center }\r
28 code { color: #000000; background-color: #E0E0E0; font-family: 'Courier New', Courier; line-height: 120%; font-style: normal }\r
29 /*-----------------------------------------------------------Notes\r
30 -----------------------------------------------------------*/\r
31 p.note { font-weight: bold; clear: both; margin-bottom: 3pt; padding-top: 6pt }\r
32 /*-----------------------------------------------------------Expanding/Contracting Divisions\r
33 -----------------------------------------------------------*/\r
34 #expand { text-decoration: none; margin-bottom: 3pt }\r
35 img.expand { border-style: none; border-width: medium }\r
36 div.expand { display: none; margin-left: 9pt; margin-top: 0 }\r
37 /*-----------------------------------------------------------Where List Tags\r
38 -----------------------------------------------------------*/\r
39 p.wh { font-weight: bold; clear: both; margin-top: 6pt; margin-bottom: 3pt }\r
40 table.wh { width: 100% }\r
41 td.whItem { white-space: nowrap; font-style: italic; padding-right: 6pt; padding-bottom: 6pt }\r
42 td.whDesc { padding-bottom: 6pt }\r
43 /*-----------------------------------------------------------Keil Table Tags\r
44 -----------------------------------------------------------*/\r
45 table.kt { width: 100%; border: 1pt solid #000000 }\r
46 th.kt { white-space: nowrap; border-bottom: 1pt solid #000000; padding-left: 6pt; padding-right: 6pt; padding-top: 4pt; padding-bottom: 4pt }\r
47 tr.kt { }\r
48 td.kt { color: #000000; background-color: #E0E0E0; border-top: 1pt solid #A0A0A0; padding-left: 6pt; padding-right: 6pt; padding-top: 2pt; padding-bottom: 2pt }\r
49 /*----------------------------------------------------------------------------------------------------------------------*/\r
50     .style1 {\r
51         background-color: #E0E0E0;\r
52 }\r
53 .O\r
54         {color:#1D315B;\r
55         font-size:149%;}\r
56     -->\r
57   </style></head>\r
58 <body>\r
59 <h1>Cortex Microcontroller Software Interface Standard</h1>\r
60 \r
61 <p align="center">This file describes the Cortex Microcontroller Software Interface Standard (CMSIS).</p>\r
62 <p align="center">Version: 1.20 - 22. May 2009</p>\r
63 \r
64 <p class="TinyT">Information in this file, the accompany manuals, and software is<br>\r
65                  Copyright © ARM Ltd.<br>All rights reserved.\r
66 </p>\r
67 \r
68 <hr>\r
69 \r
70 <p><span style="FONT-WEIGHT: bold">Revision History</span></p>\r
71 <ul>\r
72         <li>Version 1.00: initial release. </li>\r
73         <li>Version 1.01: added __LDREX<em>x</em>, __STREX<em>x</em>, and __CLREX.</li>\r
74         <li>Version 1.02: added Cortex-M0. </li>\r
75         <li>Version 1.10: second review. </li>\r
76         <li>Version 1.20: third review. </li>\r
77 </ul>\r
78 \r
79 <hr>\r
80 \r
81 <h2>Contents</h2>\r
82 \r
83 <ol>\r
84   <li class="LI2"><a href="#1">About</a></li>\r
85   <li class="LI2"><a href="#2">Coding Rules and Conventions</a></li>\r
86   <li class="LI2"><a href="#3">CMSIS Files</a></li>\r
87   <li class="LI2"><a href="#4">Core Peripheral Access Layer</a></li>\r
88   <li class="LI2"><a href="#5">CMSIS Example</a></li>\r
89 </ol>\r
90 \r
91 <h2><a name="1"></a>About</h2>\r
92 \r
93 <p>\r
94   The <strong>Cortex Microcontroller Software Interface Standard (CMSIS)</strong> answers the challenges\r
95   that are faced when software components are deployed to physical microcontroller devices based on a\r
96   Cortex-M0 / Cortex-M1 or Cortex-M3 processor. The CMSIS will be also expanded to future Cortex-M \r
97   processor cores (the term Cortex-Mx is used to indicate that). The CMSIS is defined in close co-operation\r
98   with various silicon and software vendors and provides a common approach to interface to peripherals, \r
99   real-time operating systems, and middleware components.\r
100 </p>\r
101 \r
102 <p>ARM provides as part of the CMSIS the following software layers that are\r
103 available for various compiler implementations:</p>\r
104 <ul>\r
105   <li><strong>Core Peripheral Access Layer</strong>: contains name definitions, \r
106     address definitions and helper functions to\r
107     access core registers and peripherals. It defines also an device\r
108     independent interface for RTOS Kernels that includes debug channel\r
109     definitions.</li>\r
110   <li><strong>Middleware Access Layer:</strong> provides common methods to\r
111     access peripherals for the software industry. The Middleware Access Layer\r
112     is adapted by the Silicon Vendor for the device specific peripherals used\r
113     by middleware components. The middleware access layer is currently in \r
114         development and not yet part of this documentation</li>\r
115 </ul>\r
116 \r
117 <p>These software layers are expanded by Silicon partners with:</p>\r
118 <ul>\r
119   <li><strong>Device Peripheral Access Layer</strong>: provides definitions\r
120     for all device peripherals</li>\r
121   <li><strong>Access Functions for Peripherals (optional)</strong>: provides\r
122     additional helper functions for peripherals</li>\r
123 </ul>\r
124 \r
125 <p>CMSIS defines for a Cortex-Mx Microcontroller System:</p>\r
126 <ul>\r
127   <li style="text-align: left;">A common way to access peripheral registers\r
128     and a common way to define exception vectors.</li>\r
129   <li style="text-align: left;">The register names of the <strong>Core\r
130     Peripherals</strong> and<strong> </strong>the names of the <strong>Core\r
131     Exception Vectors</strong>.</li>\r
132   <li>An device independent interface for RTOS Kernels including a debug\r
133     channel.</li>\r
134   <li style="text-align: left;">Interfaces for middleware components (TCP/IP\r
135     Stack, Flash File System).</li>\r
136 </ul>\r
137 \r
138 <p>\r
139   By using CMSIS compliant software components, the user can easier re-use template code. \r
140   CMSIS is intended to enable the combination of software components from multiple middleware vendors.\r
141 </p>\r
142 \r
143 <h2><a name="2"></a>Coding Rules and Conventions</h2>\r
144 \r
145 <p>\r
146   The following section describes the coding rules and conventions used in the CMSIS \r
147   implementation. It contains also information about data types and version number information.\r
148 </p>\r
149 \r
150 <h3>Essentials</h3>\r
151 <ul>\r
152   <li>The CMSIS C code conforms to MISRA 2004 rules. In case of MISRA violations, \r
153       there are disable and enable sequences for PC-LINT inserted.</li>\r
154   <li>ANSI standard data types defined in the ANSI C header file\r
155     <strong>&lt;stdint.h&gt;</strong> are used.</li>\r
156   <li>#define constants that include expressions must be enclosed by\r
157     parenthesis.</li>\r
158   <li>Variables and parameters have a complete data type.</li>\r
159   <li>All functions in the <strong>Core Peripheral Access Layer</strong> are\r
160     re-entrant.</li>\r
161   <li>The <strong>Core Peripheral Access Layer</strong> has no blocking code\r
162     (which means that wait/query loops are done at other software layers such as \r
163     the <strong>Middleware Access Layer</strong>).</li>\r
164   <li>For each exception/interrupt there is definition for:\r
165   <ul>\r
166     <li>an exception/interrupt handler with the postfix <strong>_Handler </strong>\r
167         (for exceptions) or <strong>_IRQHandler</strong> (for interrupts).</li>\r
168     <li>a default exception/interrupt handler (weak definition) that contains an endless loop.</li>\r
169     <li>a #define of the interrupt number with the postfix <strong>_IRQn</strong>.</li>\r
170   </ul></li>\r
171 </ul>\r
172 \r
173 <h3>Recommendations</h3>\r
174 \r
175 <p>The CMSIS recommends the following conventions for identifiers.</p>\r
176 <ul>\r
177   <li><strong>CAPITAL</strong> names to identify Core Registers, Peripheral Registers, and CPU Instructions.</li>\r
178   <li><strong>CamelCase</strong> names to identify peripherals access functions and interrupts.</li>\r
179   <li><strong>PERIPHERAL_</strong> prefix to identify functions that belong to specify peripherals.</li>\r
180   <li><strong>Doxygen</strong> comments for all functions are included as described under <strong>Function Comments</strong> below.</li>\r
181 </ul>\r
182 \r
183 <b>Comments</b>\r
184 \r
185 <ul>\r
186   <li>Comments use the ANSI C90 style (<em>/* comment */</em>) or C++ style \r
187   (<em>// comment</em>). It is assumed that the programming tools support today \r
188         consistently the C++ comment style.</li>\r
189   <li><strong>Function Comments</strong> provide for each function the following information:\r
190   <ul>\r
191     <li>one-line brief function overview.</li>\r
192     <li>detailed parameter explanation.</li>\r
193     <li>detailed information about return values.</li>\r
194     <li>detailed description of the actual function.</li>\r
195   </ul>\r
196   <p><b>Doxygen Example:</b></p>\r
197   <pre>\r
198 /** \r
199  * @brief  Enable Interrupt in NVIC Interrupt Controller\r
200  * @param  IRQn  interrupt number that specifies the interrupt\r
201  * @return none.\r
202  * Enable the specified interrupt in the NVIC Interrupt Controller.\r
203  * Other settings of the interrupt such as priority are not affected.\r
204  */</pre>\r
205   </li>\r
206 </ul>\r
207 \r
208 <h3>Data Types and IO Type Qualifiers</h3>\r
209 \r
210 <p>\r
211   The <strong>Cortex-Mx HAL</strong> uses the standard types from the standard ANSI C header file\r
212   <strong>&lt;stdint.h&gt;</strong>. <strong>IO Type Qualifiers</strong> are used to specify the access\r
213   to peripheral variables. IO Type Qualifiers are indented to be used for automatic generation of \r
214   debug information of peripheral registers.\r
215 </p>\r
216 \r
217 <table class="kt" border="0" cellpadding="0" cellspacing="0">\r
218   <tbody>\r
219     <tr>\r
220       <th class="kt" nowrap="nowrap">IO Type Qualifier</th>\r
221       <th class="kt">#define</th>\r
222       <th class="kt">Description</th>\r
223     </tr>\r
224     <tr>\r
225       <td class="kt" nowrap="nowrap">__I</td>\r
226       <td class="kt">volatile const</td>\r
227       <td class="kt">Read access only</td>\r
228     </tr>\r
229     <tr>\r
230       <td class="kt" nowrap="nowrap">__O</td>\r
231       <td class="kt">volatile</td>\r
232       <td class="kt">Write access only</td>\r
233     </tr>\r
234     <tr>\r
235       <td class="kt" nowrap="nowrap">__IO</td>\r
236       <td class="kt">volatile</td>\r
237       <td class="kt">Read and write access</td>\r
238     </tr>\r
239   </tbody>\r
240 </table>\r
241 \r
242 <h3>CMSIS Version Number</h3>\r
243 <p>\r
244   File <strong>core_cm3.h</strong> contains the version number of the CMSIS with the following define:\r
245 </p>\r
246 \r
247 <pre>\r
248 #define __CM3_CMSIS_VERSION_MAIN  (0x00)      /* [31:16] main version       */\r
249 #define __CM3_CMSIS_VERSION_SUB   (0x03)      /* [15:0]  sub version        */\r
250 #define __CM3_CMSIS_VERSION       ((__CM3_CMSIS_VERSION_MAIN &lt;&lt; 16) | __CM3_CMSIS_VERSION_SUB)</pre>\r
251 \r
252 <p>\r
253   File <strong>core_cm0.h</strong> contains the version number of the CMSIS with the following define:\r
254 </p>\r
255 \r
256 <pre>\r
257 #define __CM0_CMSIS_VERSION_MAIN  (0x00)      /* [31:16] main version       */\r
258 #define __CM0_CMSIS_VERSION_SUB   (0x00)      /* [15:0]  sub version        */\r
259 #define __CM0_CMSIS_VERSION       ((__CM0_CMSIS_VERSION_MAIN &lt;&lt; 16) | __CM0_CMSIS_VERSION_SUB)</pre>\r
260 \r
261 \r
262 <h3>CMSIS Cortex Core</h3>\r
263 <p>\r
264   File <strong>core_cm3.h</strong> contains the type of the CMSIS Cortex-Mx with the following define:\r
265 </p>\r
266 \r
267 <pre>\r
268 #define __CORTEX_M                (0x03)</pre>\r
269 \r
270 <p>\r
271   File <strong>core_cm0.h</strong> contains the type of the CMSIS Cortex-Mx with the following define:\r
272 </p>\r
273 \r
274 <pre>\r
275 #define __CORTEX_M                (0x00)</pre>\r
276 \r
277 \r
278 <h2><a name="3"></a>CMSIS Files</h2>\r
279 <p>\r
280   This section describes the Files provided in context with the CMSIS to access the Cortex-Mx\r
281   hardware and peripherals.\r
282 </p>\r
283 \r
284 <table class="kt" border="0" cellpadding="0" cellspacing="0">\r
285   <tbody>\r
286     <tr>\r
287       <th class="kt" nowrap="nowrap">File</th>\r
288       <th class="kt">Provider</th>\r
289       <th class="kt">Description</th>\r
290     </tr>\r
291     <tr>\r
292       <td class="kt" nowrap="nowrap"><i>device.h</i></td>\r
293       <td class="kt">Device specific (provided by silicon partner)</td>\r
294       <td class="kt">Defines the peripherals for the actual device. The file may use \r
295         several other include files to define the peripherals of the actual device.</td>\r
296     </tr>\r
297     <tr>\r
298       <td class="kt" nowrap="nowrap">core_cm0.h</td>\r
299       <td class="kt">ARM (for RealView ARMCC, IAR, and GNU GCC)</td>\r
300       <td class="kt">Defines the core peripherals for the Cortex-M0 CPU and core peripherals.</td>\r
301     </tr>\r
302     <tr>\r
303       <td class="kt" nowrap="nowrap">core_cm3.h</td>\r
304       <td class="kt">ARM (for RealView ARMCC, IAR, and GNU GCC)</td>\r
305       <td class="kt">Defines the core peripherals for the Cortex-M3 CPU and core peripherals.</td>\r
306     </tr>\r
307     <tr>\r
308       <td class="kt" nowrap="nowrap">core_cm0.c</td>\r
309       <td class="kt">ARM (for RealView ARMCC, IAR, and GNU GCC)</td>\r
310       <td class="kt">Provides helper functions that access core registers.</td>\r
311     </tr>\r
312     <tr>\r
313       <td class="kt" nowrap="nowrap">core_cm0.c</td>\r
314       <td class="kt">ARM (for RealView ARMCC, IAR, and GNU GCC)</td>\r
315       <td class="kt">Provides helper functions that access core registers.</td>\r
316     </tr>\r
317     <tr>\r
318       <td class="kt" nowrap="nowrap">startup<i>_device</i></td>\r
319       <td class="kt">ARM (adapted by compiler partner / silicon partner)</td>\r
320       <td class="kt">Provides the Cortex-Mx startup code and the complete (device specific) Interrupt Vector Table</td>\r
321     </tr>\r
322     <tr>\r
323       <td class="kt" nowrap="nowrap">system<i>_device</i></td>\r
324       <td class="kt">ARM (adapted by silicon partner)</td>\r
325       <td class="kt">Provides a device specific configuration file for the device. It configures the device initializes \r
326         typically the oscillator (PLL) that is part of the microcontroller device</td>\r
327     </tr>\r
328   </tbody>\r
329 </table>\r
330 \r
331 <h3><em>device.h</em></h3>\r
332 \r
333 <p>\r
334   The file <em><strong>device.h</strong></em> is provided by the silicon vendor and is the \r
335   <u><strong>central include file</strong></u> that the application programmer is using in \r
336   the C source code. This file contains:\r
337 </p>\r
338 <ul>\r
339   <li>\r
340         <p><strong>Interrupt Number Definition</strong>: provides interrupt numbers \r
341         (IRQn) for all core and device specific exceptions and interrupts.</p>\r
342         </li>\r
343         <li>\r
344         <p><strong>Configuration for core_cm0.h / core_cm3.h</strong>: reflects the \r
345         actual configuration of the Cortex-Mx processor that is part of the actual \r
346         device. As such the file <strong>core_cm0.h / core_cm3.h</strong> is included that \r
347         implements access to processor registers and core peripherals. </p>\r
348         </li>\r
349         <li>\r
350         <p><strong>Device Peripheral Access Layer</strong>: provides definitions\r
351     for all device peripherals. It contains all data structures and the address \r
352         mapping for the device specific peripherals. </p>\r
353         </li>\r
354   <li><strong>Access Functions for Peripherals (optional)</strong>: provides\r
355     additional helper functions for peripherals that are useful for programming \r
356         of these peripherals. Access Functions may be provided as inline functions \r
357         or can be extern references to a device specific library provided by the \r
358         silicon vendor.</li>\r
359 </ul>\r
360 \r
361 \r
362 <h4><strong>Interrupt Number Definition</strong></h4>\r
363 \r
364 <p>To access the device specific interrupts the device.h file defines IRQn \r
365 numbers for the complete device using a enum typedef as shown below:</p>\r
366 <pre>\r
367 typedef enum IRQn\r
368 {\r
369 /******  Cortex-M3 Processor Exceptions/Interrupt Numbers ************************************************/\r
370   NonMaskableInt_IRQn             = -14,      /*!&lt; 2 Non Maskable Interrupt                              */\r
371   HardFault_IRQn                  = -13,      /*!&lt; 3 Cortex-M3 Hard Fault Interrupt                      */\r
372   MemoryManagement_IRQn           = -12,      /*!&lt; 4 Cortex-M3 Memory Management Interrupt               */\r
373   BusFault_IRQn                   = -11,      /*!&lt; 5 Cortex-M3 Bus Fault Interrupt                       */\r
374   UsageFault_IRQn                 = -10,      /*!&lt; 6 Cortex-M3 Usage Fault Interrupt                     */\r
375   SVCall_IRQn                     = -5,       /*!&lt; 11 Cortex-M3 SV Call Interrupt                        */\r
376   DebugMonitor_IRQn               = -4,       /*!&lt; 12 Cortex-M3 Debug Monitor Interrupt                  */\r
377   PendSV_IRQn                     = -2,       /*!&lt; 14 Cortex-M3 Pend SV Interrupt                        */\r
378   SysTick_IRQn                    = -1,       /*!&lt; 15 Cortex-M3 System Tick Interrupt                    */\r
379 /******  STM32 specific Interrupt Numbers ****************************************************************/\r
380   WWDG_STM_IRQn                   = 0,        /*!&lt; Window WatchDog Interrupt                             */\r
381   PVD_STM_IRQn                    = 1,        /*!&lt; PVD through EXTI Line detection Interrupt             */\r
382   :\r
383   :\r
384   } IRQn_Type;</pre>\r
385 \r
386 \r
387 <h4>Configuration for core_cm0.h / core_cm3.h</h4>\r
388 <p>\r
389   The Cortex-Mx core configuration options which are defined for each device implementation. Some \r
390   configuration options are reflected in the CMSIS layer using the #define settings described below.\r
391 </p>\r
392 <p>\r
393   To access core peripherals file <em><strong>device.h</strong></em> includes file <b>core_cm0.h / core_cm3.h</b>.\r
394   Several features in <strong>core_cm0.h / core_cm3.h</strong> are configured by the following defines that must be \r
395   defined before <strong>#include &lt;core_cm0.h&gt;</strong> / <strong>#include &lt;core_cm3.h&gt;</strong>\r
396   preprocessor command.\r
397 </p>\r
398 \r
399 <table class="kt" border="0" cellpadding="0" cellspacing="0">\r
400   <tbody>\r
401     <tr>\r
402       <th class="kt" nowrap="nowrap">#define</th>\r
403       <th class="kt" nowrap="nowrap">File</th>\r
404       <th class="kt" nowrap="nowrap">Value</th>\r
405       <th class="kt">Description</th>\r
406     </tr>\r
407     <tr>\r
408       <td class="kt" nowrap="nowrap">__NVIC_PRIO_BITS</td>\r
409       <td class="kt">core_cm0.h</td>\r
410       <td class="kt" nowrap="nowrap">(2)</td>\r
411       <td class="kt">Number of priority bits implemented in the NVIC (device specific)</td>\r
412     </tr>\r
413     <tr>\r
414       <td class="kt" nowrap="nowrap">__NVIC_PRIO_BITS</td>\r
415       <td class="kt">core_cm3.h</td>\r
416       <td class="kt" nowrap="nowrap">(2 ... 8)</td>\r
417       <td class="kt">Number of priority bits implemented in the NVIC (device specific)</td>\r
418     </tr>\r
419     <tr>\r
420       <td class="kt" nowrap="nowrap">__MPU_PRESENT</td>\r
421       <td class="kt">core_cm0.h, core_cm3.h</td>\r
422       <td class="kt" nowrap="nowrap">(0, 1)</td>\r
423       <td class="kt">Defines if an MPU is present or not</td>\r
424     </tr>\r
425     <tr>\r
426       <td class="kt" nowrap="nowrap">__Vendor_SysTickConfig</td>\r
427       <td class="kt">core_cm0.h, core_cm3.h</td>\r
428       <td class="kt" nowrap="nowrap">(1)</td>\r
429       <td class="kt">When this define is setup to 1, the <strong>SysTickConfig</strong> function \r
430                 in <strong>core_cm3.h</strong> is excluded. In this case the <em><strong>device.h</strong></em> \r
431                 file must contain a vendor specific implementation of this function.</td>\r
432     </tr>\r
433   </tbody>\r
434 </table>\r
435 \r
436 \r
437 <h4>Device Peripheral Access Layer</h4>\r
438 <p>\r
439   Each peripheral uses a <strong>PERIPHERAL_</strong> prefix to identify peripheral registers \r
440   and functions that access this specific peripheral. If more than one peripheral of the same \r
441   type exists, identifiers have a postfix (digit or letter). For example:\r
442 </p>\r
443 <ul>\r
444         <li>UART_Type: defines the generic register layout for all UART channels in a device.</li>\r
445         <li>UART1: is a pointer to a register structure that refers to a specific UART. \r
446       For example UART1-&gt;DR is the data register of UART1.</li>\r
447         <li>UART_SendChar(UART1, c): is a generic function that works with all UART's in the device. \r
448       To communicate the UART that it accesses the first parameter is a pointer to the actual \r
449       UART register structure.</li>\r
450         <li>UART1_SendChar(c): is an UART1 specific implementation (in this case the send function).</li>\r
451 </ul>\r
452 \r
453 <h5>Minimal Requiements</h5>\r
454 <p>\r
455   To access the peripheral registers and related function in a device the files <strong><em>device.h</em></strong> \r
456   and <strong>core_cm0.h</strong> / <strong>core_cm3.h</strong> defines as a minimum:\r
457 </p>\r
458 <ul>\r
459   <li>The <strong>Register Layout Typedef</strong> for each peripheral that defines all register names.\r
460       Names that start with RESERVE are used to introduce space into the structure to adjust the addresses of\r
461       the peripheral registers. For example:\r
462       <pre>\r
463 typedef struct {\r
464   __IO uint32_t CTRL;      /* SysTick Control and Status Register */\r
465   __IO uint32_t LOAD;      /* SysTick Reload Value Register       */\r
466   __IO uint32_t VAL;       /* SysTick Current Value Register      */\r
467   __I  uint32_t CALIB;     /* SysTick Calibration Register        */\r
468   } SysTick_Type;</pre>\r
469   </li>\r
470 \r
471   <li><strong>Base Address</strong> for each peripheral (in case of multiple peripherals \r
472        that use the same <strong>register layout typedef</strong> multiple base addresses are defined). For example:\r
473     <pre>\r
474 #define SysTick_BASE (SCS_BASE + 0x0010)            /* SysTick Base Address */</pre>\r
475   </li>\r
476 \r
477   <li><strong>Access Definition</strong> for each peripheral (in case of multiple peripherals that use \r
478       the same <strong>register layout typedef</strong> multiple access definitions exist, i.e. UART0, \r
479       UART1). For Example:\r
480     <pre>\r
481 #define SysTick ((SysTick_Type *) SysTick_BASE)     /* SysTick access definition */</pre>\r
482   </li>\r
483 </ul>\r
484 \r
485 <p>\r
486   These definitions allow to access the peripheral registers from user code with simple assignments like:\r
487 </p>\r
488 <pre>SysTick-&gt;CTRL = 0;</pre>\r
489 \r
490 <h5>Optional Features</h5>\r
491 <p>In addition the <em> <strong>device.h </strong></em>file may define:</p>\r
492 <ul>\r
493         <li>#define constants that simplify access to the peripheral registers. \r
494         These constant define bit-positions or other specific patterns are that \r
495         required for the programming of the peripheral registers. The identifiers \r
496         used start with the name of the <strong>PERIPERHAL_</strong>. It is \r
497         recommended to use CAPITAL letters for such #define constants.</li>\r
498         <li>Functions that perform more complex functions with the peripheral (i.e. \r
499         status query before a sending register is accessed). Again these function \r
500         start with the name of the <strong>PERIPHERAL_</strong>. </li>\r
501 </ul>\r
502 \r
503 <h3>core_cm0.h and core_cm0.c</h3>\r
504 <p>\r
505   File <b>core_cm0.h</b> describes the data structures for the Cortex-M0 core peripherals and does \r
506   the address mapping of this structures. It also provides basic access to the Cortex-M0 core registers \r
507   and core peripherals with efficient functions (defined as <strong>static inline</strong>).\r
508 </p>\r
509 <p>\r
510   File <b>core_cm0.c</b> defines several helper functions that access processor registers.\r
511 </p>\r
512 <p>Together these files implement the <a href="#4">Core Peripheral Access Layer</a> for a Cortex-M0.</p>\r
513 \r
514 <h3>core_cm3.h and core_cm3.c</h3>\r
515 <p>\r
516   File <b>core_cm3.h</b> describes the data structures for the Cortex-M3 core peripherals and does \r
517   the address mapping of this structures. It also provides basic access to the Cortex-M3 core registers \r
518   and core peripherals with efficient functions (defined as <strong>static inline</strong>).\r
519 </p>\r
520 <p>\r
521   File <b>core_cm3.c</b> defines several helper functions that access processor registers.\r
522 </p>\r
523 <p>Together these files implement the <a href="#4">Core Peripheral Access Layer</a> for a Cortex-M3.</p>\r
524 \r
525 <h3>startup_<em>device</em></h3>\r
526 <p>\r
527   A template file for <strong>startup_<em>device</em></strong> is provided by ARM for each supported\r
528   compiler. It is adapted by the silicon vendor to include interrupt vectors for all device specific \r
529   interrupt handlers. Each interrupt handler is defined as <strong><em>weak</em></strong> function \r
530   to an dummy handler. Therefore the interrupt handler can be directly used in application software \r
531   without any requirements to adapt the <strong>startup_<em>device</em></strong> file.\r
532 </p>\r
533 <p>\r
534   The following exception names are fixed and define the start of the vector table for a Cortex-M0:\r
535 </p>\r
536 <pre>\r
537 __Vectors       DCD     __initial_sp              ; Top of Stack\r
538                 DCD     Reset_Handler             ; Reset Handler\r
539                 DCD     NMI_Handler               ; NMI Handler\r
540                 DCD     HardFault_Handler         ; Hard Fault Handler\r
541                 DCD     0                         ; Reserved\r
542                 DCD     0                         ; Reserved\r
543                 DCD     0                         ; Reserved\r
544                 DCD     0                         ; Reserved\r
545                 DCD     0                         ; Reserved\r
546                 DCD     0                         ; Reserved\r
547                 DCD     0                         ; Reserved\r
548                 DCD     SVC_Handler               ; SVCall Handler\r
549                 DCD     0                         ; Reserved\r
550                 DCD     0                         ; Reserved\r
551                 DCD     PendSV_Handler            ; PendSV Handler\r
552                 DCD     SysTick_Handler           ; SysTick Handler</pre>\r
553 \r
554 <p>\r
555   The following exception names are fixed and define the start of the vector table for a Cortex-M3:\r
556 </p>\r
557 <pre>\r
558 __Vectors       DCD     __initial_sp              ; Top of Stack\r
559                 DCD     Reset_Handler             ; Reset Handler\r
560                 DCD     NMI_Handler               ; NMI Handler\r
561                 DCD     HardFault_Handler         ; Hard Fault Handler\r
562                 DCD     MemManage_Handler         ; MPU Fault Handler\r
563                 DCD     BusFault_Handler          ; Bus Fault Handler\r
564                 DCD     UsageFault_Handler        ; Usage Fault Handler\r
565                 DCD     0                         ; Reserved\r
566                 DCD     0                         ; Reserved\r
567                 DCD     0                         ; Reserved\r
568                 DCD     0                         ; Reserved\r
569                 DCD     SVC_Handler               ; SVCall Handler\r
570                 DCD     DebugMon_Handler          ; Debug Monitor Handler\r
571                 DCD     0                         ; Reserved\r
572                 DCD     PendSV_Handler            ; PendSV Handler\r
573                 DCD     SysTick_Handler           ; SysTick Handler</pre>\r
574 \r
575 <p>\r
576   In the following examples for device specific interrupts are shown:\r
577 </p>\r
578 <pre>\r
579 ; External Interrupts\r
580                 DCD     WWDG_IRQHandler           ; Window Watchdog\r
581                 DCD     PVD_IRQHandler            ; PVD through EXTI Line detect\r
582                 DCD     TAMPER_IRQHandler         ; Tamper</pre>\r
583 \r
584 <p>\r
585   Device specific interrupts must have a dummy function that can be overwritten in user code. \r
586   Below is an example for this dummy function.\r
587 </p>\r
588 <pre>\r
589 Default_Handler PROC\r
590                 EXPORT WWDG_IRQHandler   [WEAK]\r
591                 EXPORT PVD_IRQHandler    [WEAK]\r
592                 EXPORT TAMPER_IRQHandler [WEAK]\r
593                 :\r
594                 :\r
595                 WWDG_IRQHandler\r
596                 PVD_IRQHandler\r
597                 TAMPER_IRQHandler\r
598                 :\r
599                 :\r
600                 B .\r
601                 ENDP</pre>\r
602                 \r
603 <p>\r
604   The user application may simply define an interrupt handler function by using the handler name\r
605   as shown below.\r
606 </p>\r
607 <pre>\r
608 void WWDG_IRQHandler(void)\r
609 {\r
610   :\r
611   :\r
612 }</pre>\r
613 \r
614 \r
615 <h3><a name="4"></a>system_<em>device</em>.c</h3>\r
616 <p>\r
617   A template file for <strong>system_<em>device</em>.c</strong> is provided by ARM but adapted by \r
618   the silicon vendor to match their actual device. As a <strong>minimum requirement</strong> \r
619   this file must provide a device specific system configuration function and a global variable \r
620   that contains the system frequency. It configures the device and initializes typically the \r
621   oscillator (PLL) that is part of the microcontroller device.\r
622 </p>\r
623 <p>\r
624   The file <strong>system_</strong><em><strong>device</strong></em><strong>.c</strong> must provide\r
625   as a minimum requirement the SystemInit function as shown below.\r
626 </p>\r
627 \r
628 <table class="kt" border="0" cellpadding="0" cellspacing="0">\r
629   <tbody>\r
630     <tr>\r
631       <th class="kt">Function Definition</th>\r
632       <th class="kt">Description</th>\r
633     </tr>\r
634     <tr>\r
635       <td class="kt" nowrap="nowrap">void SystemInit (void)</td>\r
636       <td class="kt">Setup the microcontroller system. Typically this function configures the \r
637                      oscillator (PLL) that is part of the microcontroller device. For systems \r
638                      with variable clock speed it also updates the variable SystemFrequency.</td>\r
639     </tr>\r
640   </tbody>\r
641 </table>\r
642 \r
643 <p>\r
644   Also part of the file <strong>system_</strong><em><strong>device</strong></em><strong>.c</strong> \r
645   is the variable <strong>SystemFrequency</strong> which contains the current CPU clock speed shown below.\r
646 </p>\r
647 \r
648 <table class="kt" border="0" cellpadding="0" cellspacing="0">\r
649   <tbody>\r
650     <tr>\r
651       <th class="kt">Variable Definition</th>\r
652       <th class="kt">Description</th>\r
653     </tr>\r
654     <tr>\r
655       <td class="kt" nowrap="nowrap">uint32_t SystemFrequency</td>\r
656       <td class="kt">Contains the system frequency (which is the system clock   frequency supplied \r
657                      to the SysTick timer and the processor core clock). This variable can be \r
658                      used by the user application after the call to the function SystemInit() \r
659                      to setup the SysTick timer or configure other parameters. It may also be \r
660                      used by debugger to query the frequency of the debug timer or configure \r
661                      the trace clock speed.<br><br>\r
662                                  This variable may also be defined in the <strong>const</strong> space. \r
663                                  The compiler must be configured to avoid the removal of this variable in \r
664                                  case that the application program is not using it. It is important for \r
665                                  debug systems that the variable is physically present in memory so that \r
666                                  it can be examined to configure the debugger.</td>\r
667     </tr>\r
668   </tbody>\r
669 </table>\r
670 \r
671 <p class="Note">Note</p>\r
672 <ul>\r
673   <li><p>The above definitions are the minimum requirements for the file <strong>\r
674         system_</strong><em><strong>device</strong></em><strong>.c</strong>. This \r
675         file may export more functions or variables that provide a more flexible \r
676         configuration of the microcontroller system.</p>\r
677   </li>\r
678 </ul>\r
679 \r
680 \r
681 <h2>Core Peripheral Access Layer</h2>\r
682 \r
683 <h3>Cortex-Mx Core Register Access</h3>\r
684 <p>\r
685   The following functions are defined in <strong>core_cm0.h</strong> / <strong>core_cm3.h</strong>\r
686   and provide access to Cortex-Mx core registers.\r
687 </p>\r
688 \r
689 <table class="kt" border="0" cellpadding="0" cellspacing="0">\r
690   <tbody>\r
691     <tr>\r
692       <th class="kt">Function Definition</th>\r
693       <th class="kt">Core</th>\r
694       <th class="kt">Core Register</th>\r
695       <th class="kt">Description</th>\r
696     </tr>\r
697     <tr>\r
698       <td class="kt" nowrap="nowrap">void __enable_irq (void)</td>\r
699       <td class="kt">M0, M3</td>\r
700       <td class="kt">PRIMASK = 0</td>\r
701       <td class="kt">Global Interrupt enable (using the instruction <strong>CPSIE \r
702                 i</strong>)</td>\r
703     </tr>\r
704     <tr>\r
705       <td class="kt" nowrap="nowrap">void __disable_irq (void)</td>\r
706       <td class="kt">M0, M3</td>\r
707       <td class="kt">PRIMASK = 1</td>\r
708       <td class="kt">Global Interrupt disable (using the instruction <strong>\r
709                 CPSID i</strong>)</td>\r
710     </tr>\r
711     <tr>\r
712       <td class="kt" nowrap="nowrap">void __set_PRIMASK (uint32_t value)</td>\r
713       <td class="kt">M0, M3</td>\r
714       <td class="kt">PRIMASK = value</td>\r
715       <td class="kt">Assign value to Priority Mask Register (using the instruction \r
716                 <strong>MSR</strong>)</td>\r
717     </tr>\r
718     <tr>\r
719       <td class="kt" nowrap="nowrap">uint32_t __get_PRIMASK (void)</td>\r
720       <td class="kt">M0, M3</td>\r
721       <td class="kt">return PRIMASK</td>\r
722       <td class="kt">Return Priority Mask Register (using the instruction \r
723                 <strong>MRS</strong>)</td>\r
724     </tr>\r
725     <tr>\r
726       <td class="kt" nowrap="nowrap">void __enable_fault_irq (void)</td>\r
727       <td class="kt">M3</td>\r
728       <td class="kt">FAULTMASK = 0</td>\r
729       <td class="kt">Global Fault exception and Interrupt enable (using the \r
730                 instruction <strong>CPSIE \r
731                 f</strong>)</td>\r
732     </tr>\r
733     <tr>\r
734       <td class="kt" nowrap="nowrap">void __disable_fault_irq (void)</td>\r
735       <td class="kt">M3</td>\r
736       <td class="kt">FAULTMASK = 1</td>\r
737       <td class="kt">Global Fault exception and Interrupt disable (using the \r
738                 instruction <strong>CPSID f</strong>)</td>\r
739     </tr>\r
740     <tr>\r
741       <td class="kt" nowrap="nowrap">void __set_FAULTMASK (uint32_t value)</td>\r
742       <td class="kt">M3</td>\r
743       <td class="kt">FAULTMASK = value</td>\r
744       <td class="kt">Assign value to Fault Mask Register (using the instruction \r
745                 <strong>MSR</strong>)</td>\r
746     </tr>\r
747     <tr>\r
748       <td class="kt" nowrap="nowrap">uint32_t __get_FAULTMASK (void)</td>\r
749       <td class="kt">M3</td>\r
750       <td class="kt">return FAULTMASK</td>\r
751       <td class="kt">Return Fault Mask Register (using the instruction <strong>MRS</strong>)</td>\r
752     </tr>\r
753     <tr>\r
754       <td class="kt" nowrap="nowrap">void __set_BASEPRI (uint32_t value)</td>\r
755       <td class="kt">M3</td>\r
756       <td class="kt">BASEPRI = value</td>\r
757       <td class="kt">Set Base Priority (using the instruction <strong>MSR</strong>)</td>\r
758     </tr>\r
759     <tr>\r
760       <td class="kt" nowrap="nowrap">uiuint32_t __get_BASEPRI (void)</td>\r
761       <td class="kt">M3</td>\r
762       <td class="kt">return BASEPRI</td>\r
763       <td class="kt">Return Base Priority (using the instruction <strong>MRS</strong>)</td>\r
764     </tr>\r
765     <tr>\r
766       <td class="kt" nowrap="nowrap">void __set_CONTROL (uint32_t value)</td>\r
767       <td class="kt">M0, M3</td>\r
768       <td class="kt">CONTROL = value</td>\r
769       <td class="kt">Set CONTROL register value (using the instruction <strong>MSR</strong>)</td>\r
770     </tr>\r
771     <tr>\r
772       <td class="kt" nowrap="nowrap">uint32_t __get_CONTROL (void)</td>\r
773       <td class="kt">M0, M3</td>\r
774       <td class="kt">return CONTROL</td>\r
775       <td class="kt">Return Control Register Value (using the instruction\r
776                 <strong>MRS</strong>)</td>\r
777     </tr>\r
778     <tr>\r
779       <td class="kt" nowrap="nowrap">void __set_PSP (uint32_t TopOfProcStack)</td>\r
780       <td class="kt">M0, M3</td>\r
781       <td class="kt">PSP = TopOfProcStack</td>\r
782       <td class="kt">Set Process Stack Pointer value (using the instruction\r
783                 <strong>MSR</strong>)</td>\r
784     </tr>\r
785     <tr>\r
786       <td class="kt" nowrap="nowrap">uint32_t __get_PSP (void)</td>\r
787       <td class="kt">M0, M3</td>\r
788       <td class="kt">return PSP</td>\r
789       <td class="kt">Return Process Stack Pointer (using the instruction <strong>MRS</strong>)</td>\r
790     </tr>\r
791     <tr>\r
792       <td class="kt" nowrap="nowrap">void __set_MSP (uint32_t TopOfMainStack)</td>\r
793       <td class="kt">M0, M3</td>\r
794       <td class="kt">MSP = TopOfMainStack</td>\r
795       <td class="kt">Set Main Stack Pointer (using the instruction <strong>MSR</strong>)</td>\r
796     </tr>\r
797     <tr>\r
798       <td class="kt" nowrap="nowrap">uint32_t __get_MSP (void)</td>\r
799       <td class="kt">M0, M3</td>\r
800       <td class="kt">return MSP</td>\r
801       <td class="kt">Return Main Stack Pointer (using the instruction <strong>MRS</strong>)</td>\r
802     </tr>\r
803   </tbody>\r
804 </table>\r
805 \r
806 <h3>Cortex-Mx Instruction Access</h3>\r
807 <p>\r
808   The following functions are defined in <strong>core_cm0.h</strong> / <strong>core_cm3.h</strong>and\r
809   generate specific Cortex-Mx instructions. The functions are implemented in the file \r
810   <strong>core_cm0.c</strong> / <strong>core_cm3.c</strong>.\r
811 </p>\r
812 \r
813 <table class="kt" border="0" cellpadding="0" cellspacing="0">\r
814   <tbody>\r
815     <tr>\r
816       <th class="kt">Name</th>\r
817       <th class="kt">Core</th>\r
818       <th class="kt">Generated CPU Instruction</th>\r
819       <th class="kt">Description</th>\r
820     </tr>\r
821     <tr>\r
822       <td class="kt" nowrap="nowrap">void __WFI (void)</td>\r
823       <td class="kt">M0, M3</td>\r
824       <td class="kt">WFI</td>\r
825       <td class="kt">Wait for Interrupt</td>\r
826     </tr>\r
827     <tr>\r
828       <td class="kt" nowrap="nowrap">void __WFE (void)</td>\r
829       <td class="kt">M0, M3</td>\r
830       <td class="kt">WFE</td>\r
831       <td class="kt">Wait for Event</td>\r
832     </tr>\r
833     <tr>\r
834       <td class="kt" nowrap="nowrap">void __SEV (void)</td>\r
835       <td class="kt">M0, M3</td>\r
836       <td class="kt">SEV</td>\r
837       <td class="kt">Set Event</td>\r
838     </tr>\r
839     <tr>\r
840       <td class="kt" nowrap="nowrap">void __ISB (void)</td>\r
841       <td class="kt">M0, M3</td>\r
842       <td class="kt">ISB</td>\r
843       <td class="kt">Instruction Synchronization Barrier</td>\r
844     </tr>\r
845     <tr>\r
846       <td class="kt" nowrap="nowrap">void __DSB (void)</td>\r
847       <td class="kt">M0, M3</td>\r
848       <td class="kt">DSB</td>\r
849       <td class="kt">Data Synchronization Barrier</td>\r
850     </tr>\r
851     <tr>\r
852       <td class="kt" nowrap="nowrap">void __DMB (void)</td>\r
853       <td class="kt">M0, M3</td>\r
854       <td class="kt">DMB</td>\r
855       <td class="kt">Data Memory Barrier</td>\r
856     </tr>\r
857     <tr>\r
858       <td class="kt" nowrap="nowrap">uint32_t __REV (uint32_t value)</td>\r
859       <td class="kt">M0, M3</td>\r
860       <td class="kt">REV</td>\r
861       <td class="kt">Reverse byte order in integer value.</td>\r
862     </tr>\r
863     <tr>\r
864       <td class="kt" nowrap="nowrap">uint32_t __REV16 (uint16_t value)</td>\r
865       <td class="kt">M0, M3</td>\r
866       <td class="kt">REV16</td>\r
867       <td class="kt">Reverse byte order in unsigned short value. </td>\r
868     </tr>\r
869     <tr>\r
870       <td class="kt" nowrap="nowrap">sint32_t __REVSH (sint16_t value)</td>\r
871       <td class="kt">M0, M3</td>\r
872       <td class="kt">REVSH</td>\r
873       <td class="kt">Reverse byte order in signed short value with sign extension to integer.</td>\r
874     </tr>\r
875     <tr>\r
876       <td class="kt" nowrap="nowrap">uint32_t __RBIT (uint32_t value)</td>\r
877       <td class="kt">M3</td>\r
878       <td class="kt">RBIT</td>\r
879       <td class="kt">Reverse bit order of value</td>\r
880     </tr>\r
881     <tr>\r
882       <td class="kt" nowrap="nowrap">uint8_t __LDREXB (uint8_t *addr)</td>\r
883       <td class="kt">M3</td>\r
884       <td class="kt">LDREXB</td>\r
885       <td class="kt">Load exclusive byte</td>\r
886     </tr>\r
887     <tr>\r
888       <td class="kt" nowrap="nowrap">uint16_t __LDREXH (uint16_t *addr)</td>\r
889       <td class="kt">M3</td>\r
890       <td class="kt">LDREXH</td>\r
891       <td class="kt">Load exclusive half-word</td>\r
892     </tr>\r
893     <tr>\r
894       <td class="kt" nowrap="nowrap">uint32_t __LDREXW (uint32_t *addr)</td>\r
895       <td class="kt">M3</td>\r
896       <td class="kt">LDREXW</td>\r
897       <td class="kt">Load exclusive word</td>\r
898     </tr>\r
899     <tr>\r
900       <td class="kt" nowrap="nowrap">uint32_t __STREXB (uint8_t value, uint8_t *addr)</td>\r
901       <td class="kt">M3</td>\r
902       <td class="kt">STREXB</td>\r
903       <td class="kt">Store exclusive byte</td>\r
904     </tr>\r
905     <tr>\r
906       <td class="kt" nowrap="nowrap">uint32_t __STREXB (uint16_t value, uint16_t *addr)</td>\r
907       <td class="kt">M3</td>\r
908       <td class="kt">STREXH</td>\r
909       <td class="kt">Store exclusive half-word</td>\r
910     </tr>\r
911     <tr>\r
912       <td class="kt" nowrap="nowrap">uint32_t __STREXB (uint32_t value, uint32_t *addr)</td>\r
913       <td class="kt">M3</td>\r
914       <td class="kt">STREXW</td>\r
915       <td class="kt">Store exclusive word</td>\r
916     </tr>\r
917     <tr>\r
918       <td class="kt" nowrap="nowrap">void  __CLREX (void)</td>\r
919       <td class="kt">M3</td>\r
920       <td class="kt">CLREX</td>\r
921       <td class="kt">Remove the exclusive lock created by __LDREXB, __LDREXH, or __LDREXW</td>\r
922     </tr>\r
923   </tbody>\r
924 </table>\r
925 \r
926 \r
927 <h3>NVIC Access Functions</h3>\r
928 <p>\r
929   The CMSIS provides access to the NVIC via the register interface structure and several helper\r
930   functions that simplify the setup of the NVIC. The CMSIS HAL uses IRQ numbers (IRQn) to \r
931   identify the interrupts. The first device interrupt has the IRQn value 0. Therefore negative \r
932   IRQn values are used for processor core exceptions.\r
933 </p>\r
934 <p>\r
935   For the IRQn values of core exceptions the file <strong><em>device.h</em></strong> provides \r
936   the following enum names.\r
937 </p>\r
938 \r
939 <table class="kt" border="0" cellpadding="0" cellspacing="0">\r
940   <tbody>\r
941     <tr>\r
942       <th class="kt" nowrap="nowrap">Core Exception enum Value</th>\r
943       <th class="kt">Core</th>\r
944       <th class="kt">IRQn</th>\r
945       <th class="kt">Description</th>\r
946     </tr>\r
947     <tr>\r
948       <td class="kt" nowrap="nowrap">NonMaskableInt_IRQn</td>\r
949       <td class="kt">M0, M3</td>\r
950       <td class="kt">-14</td>\r
951       <td class="kt">Cortex-Mx Non Maskable Interrupt</td>\r
952     </tr>\r
953     <tr>\r
954       <td class="kt" nowrap="nowrap">HardFault_IRQn</td>\r
955       <td class="kt">M0, M3</td>\r
956       <td class="kt">-13</td>\r
957       <td class="kt">Cortex-Mx Hard Fault Interrupt</td>\r
958     </tr>\r
959     <tr>\r
960       <td class="kt" nowrap="nowrap">MemoryManagement_IRQn</td>\r
961       <td class="kt">M3</td>\r
962       <td class="kt">-12</td>\r
963       <td class="kt">Cortex-Mx Memory Management Interrupt</td>\r
964     </tr>\r
965     <tr>\r
966       <td class="kt" nowrap="nowrap">BusFault_IRQn</td>\r
967       <td class="kt">M3</td>\r
968       <td class="kt">-11</td>\r
969       <td class="kt">Cortex-Mx Bus Fault Interrupt</td>\r
970     </tr>\r
971     <tr>\r
972       <td class="kt" nowrap="nowrap">UsageFault_IRQn</td>\r
973       <td class="kt">M3</td>\r
974       <td class="kt">-10</td>\r
975       <td class="kt">Cortex-Mx Usage Fault Interrupt</td>\r
976     </tr>\r
977     <tr>\r
978       <td class="kt" nowrap="nowrap">SVCall_IRQn</td>\r
979       <td class="kt">M0, M3</td>\r
980       <td class="kt">-5</td>\r
981       <td class="kt">Cortex-Mx SV Call Interrupt </td>\r
982     </tr>\r
983     <tr>\r
984       <td class="kt" nowrap="nowrap">DebugMonitor_IRQn</td>\r
985       <td class="kt">M3</td>\r
986       <td class="kt">-4</td>\r
987       <td class="kt">Cortex-Mx Debug Monitor Interrupt</td>\r
988     </tr>\r
989     <tr>\r
990       <td class="kt" nowrap="nowrap">PendSV_IRQn</td>\r
991       <td class="kt">M0, M3</td>\r
992       <td class="kt">-2</td>\r
993       <td class="kt">Cortex-Mx Pend SV Interrupt</td>\r
994     </tr>\r
995     <tr>\r
996       <td class="kt" nowrap="nowrap">SysTick_IRQn</td>\r
997       <td class="kt">M0, M3</td>\r
998       <td class="kt">-1</td>\r
999       <td class="kt">Cortex-Mx System Tick Interrupt</td>\r
1000     </tr>\r
1001   </tbody>\r
1002 </table>\r
1003 \r
1004 <p>The following functions simplify the setup of the NVIC.\r
1005 The functions are defined as <strong>static inline</strong>.</p>\r
1006 \r
1007 <table class="kt" border="0" cellpadding="0" cellspacing="0">\r
1008   <tbody>\r
1009     <tr>\r
1010       <th class="kt" nowrap="nowrap">Name</th>\r
1011       <th class="kt">Core</th>\r
1012       <th class="kt">Parameter</th>\r
1013       <th class="kt">Description</th>\r
1014     </tr>\r
1015     <tr>\r
1016       <td class="kt" nowrap="nowrap">void NVIC_SetPriorityGrouping (uint32_t PriorityGroup)</td>\r
1017       <td class="kt">M3</td>\r
1018       <td class="kt">Priority Grouping Value</td>\r
1019       <td class="kt">Set the Priority Grouping (Groups . Subgroups)</td>\r
1020     </tr>\r
1021     <tr>\r
1022       <td class="kt" nowrap="nowrap">void NVIC_EnableIRQ (IRQn_Type IRQn)</td>\r
1023       <td class="kt">M0, M3</td>\r
1024       <td class="kt">IRQ Number</td>\r
1025       <td class="kt">Enable IRQn</td>\r
1026     </tr>\r
1027     <tr>\r
1028       <td class="kt" nowrap="nowrap">void NVIC_DisableIRQ (IRQn_Type IRQn)</td>\r
1029       <td class="kt">M0, M3</td>\r
1030       <td class="kt">IRQ Number</td>\r
1031       <td class="kt">Disable IRQn</td>\r
1032     </tr>\r
1033     <tr>\r
1034       <td class="kt" nowrap="nowrap">uint32_t NVIC_GetPendingIRQ (IRQn_Type IRQn)</td>\r
1035       <td class="kt">M0, M3</td>\r
1036       <td class="kt">IRQ Number</td>\r
1037       <td class="kt">Return 1 if IRQn is pending else 0</td>\r
1038     </tr>\r
1039     <tr>\r
1040       <td class="kt" nowrap="nowrap">void NVIC_SetPendingIRQ (IRQn_Type IRQn)</td>\r
1041       <td class="kt">M0, M3</td>\r
1042       <td class="kt">IRQ Number</td>\r
1043       <td class="kt">Set IRQn Pending</td>\r
1044     </tr>\r
1045     <tr>\r
1046       <td class="kt" nowrap="nowrap">void NVIC_ClearPendingIRQ (IRQn_Type IRQn)</td>\r
1047       <td class="kt">M0, M3</td>\r
1048       <td class="kt">IRQ Number</td>\r
1049       <td class="kt">Clear IRQn Pending Status</td>\r
1050     </tr>\r
1051     <tr>\r
1052       <td class="kt" nowrap="nowrap">uint32_t NVIC_GetActive (IRQn_Type IRQn)</td>\r
1053       <td class="kt">M3</td>\r
1054       <td class="kt">IRQ Number</td>\r
1055       <td class="kt">Return 1 if IRQn is active else 0</td>\r
1056     </tr>\r
1057     <tr>\r
1058       <td class="kt" nowrap="nowrap">void NVIC_SetPriority (IRQn_Type IRQn, uint32_t priority)</td>\r
1059       <td class="kt">M0, M3</td>\r
1060       <td class="kt">IRQ Number, Priority</td>\r
1061       <td class="kt">Set Priority for IRQn<br>\r
1062                      (not threadsafe for Cortex-M0)</td>\r
1063     </tr>\r
1064     <tr>\r
1065       <td class="kt" nowrap="nowrap">uint32_t NVIC_GetPriority (IRQn_Type IRQn)</td>\r
1066       <td class="kt">M0, M3</td>\r
1067       <td class="kt">IRQ Number</td>\r
1068       <td class="kt">Get Priority for IRQn</td>\r
1069     </tr>\r
1070     <tr>\r
1071 <!--      <td class="kt" nowrap="nowrap">uint32_t NVIC_EncodePriority (uint32_t PriorityGroup, uint32_t PreemptPriority, uint32_t SubPriority)</td> -->\r
1072       <td class="kt">uint32_t NVIC_EncodePriority (uint32_t PriorityGroup, uint32_t PreemptPriority, uint32_t SubPriority)</td>\r
1073       <td class="kt">M3</td>\r
1074       <td class="kt">IRQ Number, Priority Group, Preemtive Priority, Sub Priority</td>\r
1075       <td class="kt">Encode priority for given group, preemtive and sub priority</td>\r
1076     </tr>\r
1077 <!--      <td class="kt" nowrap="nowrap">NVIC_DecodePriority (uint32_t Priority, uint32_t PriorityGroup, uint32_t* pPreemptPriority, uint32_t* pSubPriority)</td> -->\r
1078       <td class="kt">NVIC_DecodePriority (uint32_t Priority, uint32_t PriorityGroup, uint32_t* pPreemptPriority, uint32_t* pSubPriority)</td>\r
1079       <td class="kt">M3</td>\r
1080       <td class="kt">IRQ Number, Priority, pointer to Priority Group, pointer to Preemtive Priority, pointer to Sub Priority</td>\r
1081       <td class="kt">Deccode given priority to group, preemtive and sub priority</td>\r
1082     </tr>\r
1083     <tr>\r
1084       <td class="kt" nowrap="nowrap">void NVIC_SystemReset (void)</td>\r
1085       <td class="kt">M0, M3</td>\r
1086       <td class="kt">(void)</td>\r
1087       <td class="kt">Resets the System</td>\r
1088     </tr>\r
1089   </tbody>\r
1090 </table>\r
1091 <p class="Note">Note</p>\r
1092 <ul>\r
1093   <li><p>The processor exceptions have negative enum values. Device specific interrupts \r
1094                have positive enum values and start with 0. The values are defined in\r
1095          <b><em>device.h</em></b> file.\r
1096       </p>\r
1097   </li>\r
1098   <li><p>The values for <b>PreemptPriority</b> and <b>SubPriority</b>\r
1099          used in functions <b>NVIC_EncodePriority</b> and <b>NVIC_DecodePriority</b>\r
1100          depend on the available __NVIC_PRIO_BITS implemented in the NVIC.\r
1101       </p>\r
1102   </li>\r
1103 </ul>\r
1104 \r
1105 \r
1106 <h3>SysTick Configuration Function</h3>\r
1107 \r
1108 <p>The following function is used to configure the SysTick timer and start the \r
1109 SysTick interrupt.</p>\r
1110 \r
1111 <table class="kt" border="0" cellpadding="0" cellspacing="0">\r
1112   <tbody>\r
1113     <tr>\r
1114       <th class="kt" nowrap="nowrap">Name</th>\r
1115       <th class="kt">Parameter</th>\r
1116       <th class="kt">Description</th>\r
1117     </tr>\r
1118     <tr>\r
1119       <td class="kt" nowrap="nowrap">uint32_t Sys<span class="style1">TickConfig \r
1120                 (uint32_t ticks)</span></td>\r
1121       <td class="kt">ticks is SysTick counter reload value</td>\r
1122       <td class="kt">Setup the SysTick timer and enable the SysTick interrupt. After this \r
1123                 call the SysTick timer creates interrupts with the specified time \r
1124                 interval. <br>\r
1125                 <br>\r
1126                 Return: 0 when successful, 1 on failure.<br>\r
1127                 </td>\r
1128     </tr>\r
1129   </tbody>\r
1130 </table>\r
1131 \r
1132 \r
1133 <h3>Cortex-M3 ITM Debug Access</h3>\r
1134 \r
1135 <p>The Cortex-M3 incorporates the Instrumented Trace Macrocell (ITM) that \r
1136 provides together with the Serial Viewer Output trace capabilities for the \r
1137 microcontroller system. The ITM has 32 communication channels; two ITM \r
1138 communication channels are used by CMSIS to output the following information:</p>\r
1139 <ul>\r
1140         <li>ITM Channel 0: implements the <strong>ITM_putchar</strong> function \r
1141         which can be used for printf-style output via the debug interface.</li>\r
1142         <li>ITM Channel 31: is reserved for the RTOS kernel and can be used for \r
1143         kernel awareness debugging.</li>\r
1144 </ul>\r
1145 <p class="Note">Note</p>\r
1146 <ul>\r
1147   <li><p>The ITM channel 31 is selected for the RTOS kernel since some kernels \r
1148         may use the Privileged level for program execution. ITM \r
1149         channels have 4 groups with 8 channels each, whereby each group can be \r
1150         configured for access rights in the Unprivileged level. The ITM channel 0 \r
1151         may be therefore enabled for the user task whereas ITM channel 31 may be \r
1152         accessible only in Privileged level from the RTOS kernel itself.</p>\r
1153   </li>\r
1154 </ul>\r
1155 \r
1156 <p>The prototype of the <strong>ITM_putchar</strong> routine is shown in the \r
1157 table below.</p>\r
1158 \r
1159 <table class="kt" border="0" cellpadding="0" cellspacing="0">\r
1160   <tbody>\r
1161     <tr>\r
1162       <th class="kt" nowrap="nowrap">Name</th>\r
1163       <th class="kt">Parameter</th>\r
1164       <th class="kt">Description</th>\r
1165     </tr>\r
1166     <tr>\r
1167       <td class="kt" nowrap="nowrap">void uint32_t ITM_putchar(uint32_t chr)</td>\r
1168       <td class="kt">character to output</td>\r
1169       <td class="kt">The function outputs a character via the ITM channel 0. The \r
1170                                  function returns when no debugger is connected that has booked the \r
1171                                  output. It is blocking when a debugger is connected, but the \r
1172                                  previous character send is not transmitted. <br><br>\r
1173                                  Return: the input character 'chr'.</td>\r
1174     </tr>\r
1175   </tbody>\r
1176 </table>\r
1177 \r
1178 \r
1179 <p>\r
1180   Example for the usage of the ITM Channel 31 for RTOS Kernels:\r
1181 </p>\r
1182 <pre>\r
1183   // check if debugger connected and ITM channel enabled for tracing\r
1184   if ((CoreDebug-&gt;DEMCR &amp; CoreDebug_DEMCR_TRCENA) &amp;&amp;\r
1185   (ITM-&gt;TCR &amp; ITM_TCR_ITMENA) &amp;&amp;\r
1186   (ITM-&gt;TER &amp; (1UL &lt;&lt; 31))) {\r
1187     // transmit trace data\r
1188     while (ITM-&gt;PORT31_U32 == 0);\r
1189     ITM-&gt;PORT[31].u8 = task_id;      // id of next task\r
1190     while (ITM-&gt;PORT[31].u32 == 0);\r
1191     ITM-&gt;PORT[31].u32 = task_status; // status information\r
1192   }</pre>\r
1193 \r
1194 \r
1195 <h2><a name="5"></a>CMSIS Example</h2>\r
1196 <p>\r
1197   The following section shows a typical example for using the CMSIS layer in user applications.\r
1198 </p>\r
1199 <pre>\r
1200 #include &lt;device.h&gt;                              // file name depends on the device used.\r
1201 \r
1202 void SysTick_Handler (void)  {                   // SysTick Interrupt Handler\r
1203   ;\r
1204 }\r
1205 \r
1206 void TIM1_UP_IRQHandler (void)  {                // Timer Interrupt Handler\r
1207   ;\r
1208 }\r
1209 \r
1210 void timer1_init(int frequency) {\r
1211                                                  // set up Timer (device specific)\r
1212   NVIC_SetPriority (TIM1_UP_IRQn, 1);            // Set Timer priority\r
1213   NVIC_EnableIRQ (TIM1_UP_IRQn);                 // Enable Timer Interrupt\r
1214 }\r
1215 \r
1216 void main (void) {\r
1217   SystemInit ();\r
1218 \r
1219   if (SysTick_Config (SystemFrequency / 1000)) { // Setup SysTick Timer for 1 msec interrupts\r
1220     :                                            // Handle Error\r
1221     :\r
1222     while (1);\r
1223   }\r
1224 \r
1225   timer1_init ();                                // device specific timer\r
1226 \r
1227   while (1);\r
1228 }</pre>\r
1229 \r
1230 \r
1231 </body></html>