2 \page templates_pg CMSIS-Core Device Templates
6 ARM supplies CMSIS-Core device template files for the all supported Cortex-A processors and various compiler vendors.
7 Refer to the list of \ref tested_tools_sec for compliance.
9 These CMSIS-Core device template files include the following:
10 - Register names of the Core Peripherals and names of the Core Exception Vectors.
11 - Functions to access core peripherals, cache, MMU and special CPU instructions
12 - Generic startup code and system configuration code.
14 The detailed file structure of the CMSIS-Core device templates is shown in the following picture.
16 <!-- \image html "CMSIS_CORE_Files.png" "CMSIS-Core File Structure" -->
18 \section CMSIS_Processor_files CMSIS-Core Processor Files
20 The CMSIS-Core processor files provided by ARM are in the directory .\\CMSIS\\Core_A\\Include. These header files define all processor specific attributes do not need any modifications.
21 The <b>core_<cpu>.h</b> defines the core peripherals and provides helper functions that access the core registers. One file is available for each supported Cortex-A processor:
23 Header File | Processor
24 :----------------|:------------------------------
25 core_ca.h | generics for all supportet Cortex-A processors
27 \section device_examples Device Examples
29 The CMSIS Software Pack defines several devices that are based on the various processors. The device related CMSIS-Core files are in the directory .\\Device\\ARM
30 and include CMSIS-Core processor file explained before. The following sample devices are defined in the CMSIS-Pack description file <b>ARM.CMSIS.pdsc</b>:
32 Family | Device | Description
33 :------------------|:------------------|:---------------------------------
34 ARM Cortex-A7 | ARMCA7 | Cortex-A7 based device
35 ARM Cortex-A9 | ARMCA9 | Cortex-A9 based device
39 \section template_files_sec Template Files
41 To simplify the creation of CMSIS-Core device files, the following template files are provided that should be extended by the silicon vendor to reflect the actual device and device peripherals.
42 Silicon vendors add to these template files the following information:
43 - <b>Device Peripheral Access Layer</b> that provides definitions for device-specific peripherals.
44 - <b>Access Functions for Peripherals</b> (optional) that provides additional helper functions to access device-specific peripherals.
45 - <b>Interrupt vectors</b> in the startup file that are device specific.
47 <table class="cmtable">
49 <th>Template File</th>
53 <td>.\\Device\\\_Template_Vendor\\Vendor\\Device\\Source\\ARM\\startup_Device.c</td>
54 <td>Startup file template for ARM C/C++ Compiler.</td>
57 <td>.\\Device\\\_Template_Vendor\\Vendor\\Device\\Source\\GCC\\startup_Device.c</td>
58 <td>Startup file template for GNU GCC ARM Embedded Compiler.</td>
61 <td>.\\Device\\\_Template_Vendor\\Vendor\\Device\\Source\\IAR\\startup_Device.c</td>
62 <td>Startup file template for IAR C/C++ Compiler.</td>
65 <td>.\\Device\\\_Template_Vendor\\Vendor\\Device\\Source\\system_Device.c</td>
66 <td>Generic system_Device.c file for system configuration (i.e. processor clock and memory bus system).</td>
69 <td>.\\Device\\\_Template_Vendor\\Vendor\\Device\\Include\\Device.h</td>
70 <td>Generic device header file. Needs to be extended with the device-specific peripheral registers. Optionally functions that access the peripherals
71 can be part of that file.</td>
74 <td>.\\Device\\\_Template_Vendor\\Vendor\\Device\\Include\\system_Device.h</td>
75 <td>Generic system device configuration include file.</td>
80 <b>Adapt Template Files to a Device</b>
82 The following steps describe how to adopt the template files to a specific device or device family.
83 Copy the complete all files in the template directory and replace:
84 - directory name 'Vendor' with the abbreviation for the device vendor e.g.: NXP.
85 - directory name 'Device' with the specific device name e.g.: LPC17xx.
86 - in the file names 'Device' with the specific device name e.g.: LPC17xx.
88 Each template file contains comments that start with \b ToDo: that describe a required modification.
89 The template files contain place holders:
91 <table class="cmtable">
94 <th>Replaced with</th>
97 <td><Device></td>
98 <td>the specific device name or device family name; i.e. LPC17xx.</td>
101 <td><DeviceInterrupt></td>
102 <td>a specific interrupt name of the device; i.e. TIM1 for Timer 1.</td>
104 <td><DeviceAbbreviation></td>
105 <td>short name or abbreviation of the device family; i.e. LPC.</td>
109 <td>the specific Cortex-M processor name; i.e. Cortex-M3.</td>
114 The device configuration of the template files is described in detail on the following pages:
115 - \subpage startup_c_pg
116 - \subpage system_c_pg
117 - \subpage device_h_pg
121 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
123 \page startup_c_pg Startup File startup_<device>.c
125 The \ref startup_c_pg contains:
126 - The reset handler which is executed after CPU reset and typically calls the \ref SystemInit function.
127 - The setup values for the Main Stack Pointer (MSP).
128 - Exception vectors of the Cortex-M Processor with weak functions that implement default routines.
129 - Interrupt vectors that are device specific with weak functions that implement default routines.
131 The file exists for each supported toolchain and is the only tool-chain specific CMSIS file.
133 To adapt the file to a new device only the interrupt vector table needs to be extended with
134 the device-specific interrupt handlers. The naming convention for the interrupt handler names are
135 <interrupt_name>_IRQHandler. This table needs to be consistent with \ref IRQn_Type that defines all the
136 IRQ numbers for each interrupt.
140 The following example shows the extension of the interrupt vector table for the LPC1100 device family.
143 ; External Interrupts
144 DCD WAKEUP0_IRQHandler ; 16+ 0: Wakeup PIO0.0
145 DCD WAKEUP1_IRQHandler ; 16+ 1: Wakeup PIO0.1
146 DCD WAKEUP2_IRQHandler ; 16+ 2: Wakeup PIO0.2
149 DCD EINT1_IRQHandler ; 16+30: PIO INT1
150 DCD EINT0_IRQHandler ; 16+31: PIO INT0
153 EXPORT WAKEUP0_IRQHandler [WEAK]
154 EXPORT WAKEUP1_IRQHandler [WEAK]
155 EXPORT WAKEUP2_IRQHandler [WEAK]
158 EXPORT EINT1_IRQHandler [WEAK]
159 EXPORT EINT0_IRQHandler [WEAK]
172 \section startup_s_sec startup_Device.s Template File
174 An ARM Compiler \ref startup_s_sec for an ARMv7-M processor like Cortex-M3 is shown below.
175 The files for other compiler vendors differ slightly in the syntax, but not in the overall structure.
177 \verbinclude "Source\ARM\startup_Device.s"
180 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
182 \page system_c_pg System Configuration Files system_<device>.c and system_<device>.h
184 The \ref system_c_pg provides as a minimum the functions described under \ref system_init_gr.
185 These functions are device specific and need adaptations. In addition, the file might have
186 configuration settings for the device such as XTAL frequency or PLL prescaler settings.
188 For devices with external memory BUS the system_<device>.c also configures the BUS system.
190 The silicon vendor might expose other functions (i.e. for power configuration) in the system_<device>.c file.
191 In case of additional features the function prototypes need to be added to the system_<device>.h header file.
193 \section system_Device_sec system_Device.c Template File
195 The \ref system_Device_sec for the Cortex-M3 is shown below.
197 \verbinclude "Source\system_Device.c"
199 \section system_Device_h_sec system_Device.h Template File
201 The system_<device>.h header file contains prototypes to access the public functions in the system_<device>.c file.
202 The \ref system_Device_h_sec is shown below.
204 \verbinclude "Include\system_Device.h"
208 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
210 \page device_h_pg Device Header File \<device.h>
212 The \ref device_h_pg contains the following sections that are device specific:
213 - \ref irqn_defs provides interrupt numbers (IRQn) for all exceptions and interrupts of the device.
214 - \ref config_perifs reflect the features of the device.
215 - \ref access_perifs definitions for the \ref peripheral_gr to all device peripherals. It contains all data structures and the address mapping for device-specific peripherals.
216 - <b>Access Functions for Peripherals (optioal)</b> provide additional helper functions for peripherals that are useful for programming of these peripherals. Access Functions may be provided as inline functions or can be extern references to a device-specific library provided by the silicon vendor.
218 <a href="Modules.html">\b Reference </a> describes the standard features and functions of the \ref device_h_pg in detail.
220 \section interrupt_number_sec Interrupt Number Definition
222 \ref device_h_pg contains the enumeration \ref IRQn_Type that defines all exceptions and interrupts of the device.
223 - Negative IRQn values represent processor core exceptions (internal interrupts).
224 - Positive IRQn values represent device-specific exceptions (external interrupts). The first device-specific interrupt has the IRQn value 0.
225 The IRQn values needs extension to reflect the device-specific interrupt vector table in the \ref startup_s_pg.
229 The following example shows the extension of the interrupt vector table for the LPC1100 device family.
234 /****** Cortex-M0 Processor Exceptions Numbers ***************************************************/
235 NonMaskableInt_IRQn = -14, /*!< 2 Non Maskable Interrupt */
236 HardFault_IRQn = -13, /*!< 3 Cortex-M0 Hard Fault Interrupt */
237 SVCall_IRQn = -5, /*!< 11 Cortex-M0 SV Call Interrupt */
238 PendSV_IRQn = -2, /*!< 14 Cortex-M0 Pend SV Interrupt */
239 SysTick_IRQn = -1, /*!< 15 Cortex-M0 System Tick Interrupt */
241 /****** LPC11xx/LPC11Cxx Specific Interrupt Numbers **********************************************/
242 WAKEUP0_IRQn = 0, /*!< All I/O pins can be used as wakeup source. */
243 WAKEUP1_IRQn = 1, /*!< There are 13 pins in total for LPC11xx */
247 EINT1_IRQn = 30, /*!< External Interrupt 1 Interrupt */
248 EINT0_IRQn = 31, /*!< External Interrupt 0 Interrupt */
252 \section core_config_sect Configuration of the Processor and Core Peripherals
254 The \ref device_h_pg configures the Cortex-M or SecurCore processor and the core peripherals with <i>\#defines</i>
255 that are set prior to including the file <b>core_<cpu>.h</b>.
257 The following tables list the <i>\#defines</i> along with the possible values for each processor core.
258 If these <i>\#defines</i> are missing default values are used.
261 <table class="cmtable">
272 <td>Core revision number ([15:8] revision number, [7:0] patch number)</td>
275 <td>__NVIC_PRIO_BITS</td>
278 <td>Number of priority bits implemented in the NVIC (device specific)</td>
281 <td>__Vendor_SysTickConfig</td>
284 <td>If this define is set to 1, then the default <b>SysTick_Config</b> function
285 is excluded. In this case, the file <i><b>device.h</b></i>
286 must contain a vendor specific implementation of this function.</td>
291 <table class="cmtable">
299 <td>__CM0PLUS_REV</td>
302 <td>Core revision number ([15:8] revision number, [7:0] patch number)</td>
305 <td>__NVIC_PRIO_BITS</td>
308 <td>Number of priority bits implemented in the NVIC (device specific)</td>
311 <td>__Vendor_SysTickConfig</td>
314 <td>If this define is set to 1, then the default <b>SysTick_Config</b> function
315 is excluded. In this case, the file <i><b>device.h</b></i>
316 must contain a vendor specific implementation of this function.</td>
321 <table class="cmtable">
330 <td>0x0101 | 0x0200</td>
332 <td>Core revision number ([15:8] revision number, [7:0] patch number)</td>
335 <td>__NVIC_PRIO_BITS</td>
338 <td>Number of priority bits implemented in the NVIC (device specific)</td>
341 <td>__MPU_PRESENT</td>
344 <td>Defines if a MPU is present or not</td>
347 <td>__Vendor_SysTickConfig</td>
350 <td>If this define is set to 1, then the default <b>SysTick_Config</b> function
351 is excluded. In this case, the file <i><b>device.h</b></i>
352 must contain a vendor specific implementation of this function.</td>
357 <table class="cmtable">
368 <td>Core revision number ([15:8] revision number, [7:0] patch number)</td>
371 <td>__NVIC_PRIO_BITS</td>
374 <td>Number of priority bits implemented in the NVIC (device specific)</td>
377 <td>__MPU_PRESENT</td>
380 <td>Defines if a MPU is present or not</td>
383 <td>__FPU_PRESENT</td>
386 <td>Defines if a FPU is present or not</td>
389 <td>__Vendor_SysTickConfig</td>
392 <td>If this define is set to 1, then the default <b>SysTick_Config</b> function
393 is excluded. In this case, the file <i><b>device.h</b></i>
394 must contain a vendor specific implementation of this function.</td>
399 <table class="cmtable" summary="">
410 <td>Core revision number ([15:8] revision number, [7:0] patch number)</td>
413 <td>__MPU_PRESENT</td>
416 <td>Defines if a MPU is present or not</td>
419 <td>__NVIC_PRIO_BITS</td>
422 <td>Number of priority bits implemented in the NVIC (device specific)</td>
425 <td>__Vendor_SysTickConfig</td>
428 <td>If this define is set to 1, then the default <b>SysTick_Config</b> function
429 is excluded. In this case, the file <i><b>device.h</b></i>
430 must contain a vendor specific implementation of this function.</td>
433 <td>__FPU_PRESENT</td>
436 <td>Defines if a FPU is present or not. See <b>__FPU_DP</b> description below.</td>
442 <td>The combination of the defines <b>__FPU_PRESENT</b> and <b>__FPU_DP</b>
443 determine the whether the FPU is with single or double precision as shown in the table below.
445 <table class="cmtable" summary="">
447 <td><b>__FPU_PRESENT</b></td>
448 <td><b>__FPU_DP</b></td>
449 <td><b>Description</b></td>
452 <td align="center">0</td>
453 <td align="center"><i>ignored</i></td>
454 <td>Processor has no FPU. The value set for <b>__FPU_DP</b> has no influence. </td>
457 <td align="center">1</td>
458 <td align="center">0</td>
459 <td>Processor with FPU with single precision. The file <b>ARMCM7_SP.h</b> has preconfigured settings for this combination.</td>
462 <td align="center">1</td>
463 <td align="center">1</td>
464 <td>Processor with FPU with double precision. The file <b>ARMCM7_DP.h</b> has preconfigured settings for this combination.</td>
470 <td>__ICACHE_PRESENT</td>
473 <td>Instruction Chache present or not</td>
476 <td>__DCACHE_PRESENT</td>
479 <td>Data Chache present or not</td>
482 <td>__DTCM_PRESENT</td>
485 <td>Data Tightly Coupled Memory is present or not</td>
490 <table class="cmtable">
501 <td>Core revision number ([15:8] revision number, [7:0] patch number)</td>
504 <td>__NVIC_PRIO_BITS</td>
507 <td>Number of priority bits implemented in the NVIC (device specific)</td>
510 <td>__MPU_PRESENT</td>
513 <td>Defines if a MPU is present or not</td>
516 <td>__Vendor_SysTickConfig</td>
519 <td>If this define is set to 1, then the default <b>SysTick_Config</b> function
520 is excluded. In this case, the file <i><b>device.h</b></i>
521 must contain a vendor specific implementation of this function.</td>
526 <table class="cmtable">
537 <td>Core revision number ([15:8] revision number, [7:0] patch number)</td>
540 <td>__NVIC_PRIO_BITS</td>
543 <td>Number of priority bits implemented in the NVIC (device specific)</td>
546 <td>__MPU_PRESENT</td>
549 <td>Defines if a MPU is present or not</td>
552 <td>__Vendor_SysTickConfig</td>
555 <td>If this define is set to 1, then the default <b>SysTick_Config</b> function
556 is excluded. In this case, the file <i><b>device.h</b></i>
557 must contain a vendor specific implementation of this function.</td>
561 \b core_CM23.h or \b core_ARMv8MBL.h
562 <table class="cmtable">
570 <td>__ARMv8MBL_REV</td>
573 <td>Core revision number ([15:8] revision number, [7:0] patch number)</td>
576 <td>__MPU_PRESENT</td>
579 <td>Defines if a MPU is present or not</td>
582 <td>__SAUREGION_PRESENT</td>
585 <td>Defines if SAU regions are present or not</td>
588 <td>__VTOR_PRESENT</td>
591 <td>Defines if a VTOR register is present or not</td>
594 <td>__NVIC_PRIO_BITS</td>
597 <td>Number of priority bits implemented in the NVIC (device specific)</td>
600 <td>__Vendor_SysTickConfig</td>
603 <td>If this define is set to 1, then the default <b>SysTick_Config</b> function
604 is excluded. In this case, the file <i><b>device.h</b></i>
605 must contain a vendor specific implementation of this function.</td>
609 \b core_CM33.h or \b core_ARMv8MML.h
610 <table class="cmtable">
618 <td>__ARMv8MML_REV</td>
621 <td>Core revision number ([15:8] revision number, [7:0] patch number)</td>
624 <td>__MPU_PRESENT</td>
627 <td>Defines if a MPU is present or not</td>
630 <td>__SAUREGION_PRESENT</td>
633 <td>Defines if SAU regions are present or not</td>
636 <td>__FPU_PRESENT</td>
639 <td>Defines if a FPU is present or not</td>
642 <td>__NVIC_PRIO_BITS</td>
645 <td>Number of priority bits implemented in the NVIC (device specific)</td>
648 <td>__Vendor_SysTickConfig</td>
651 <td>If this define is set to 1, then the default <b>SysTick_Config</b> function
652 is excluded. In this case, the file <i><b>device.h</b></i>
653 must contain a vendor specific implementation of this function.</td>
659 The following code exemplifies the configuration of the Cortex-M4 Processor and Core Peripherals.
662 #define __CM4_REV 0x0001 /* Core revision r0p1 */
663 #define __MPU_PRESENT 1 /* MPU present or not */
664 #define __NVIC_PRIO_BITS 3 /* Number of Bits used for Priority Levels */
665 #define __Vendor_SysTickConfig 0 /* Set to 1 if different SysTick Config is used */
666 #define __FPU_PRESENT 1 /* FPU present or not */
669 #include <core_cm4.h> /* Cortex-M4 processor and core peripherals */
673 \section core_version_sect CMSIS Version and Processor Information
675 Defines in the core_<i>cpu</i>.h file identify the version of the CMSIS-Core-M and the processor used.
676 The following shows the defines in the various core_<i>cpu</i>.h files that may be used in the \ref device_h_pg
677 to verify a minimum version or ensure that the right processor core is used.
681 #define __CM0_CMSIS_VERSION_MAIN (5U) /* [31:16] CMSIS HAL main version */
682 #define __CM0_CMSIS_VERSION_SUB (0U) /* [15:0] CMSIS HAL sub version */
683 #define __CM0_CMSIS_VERSION ((__CM0_CMSIS_VERSION_MAIN << 16U) | \
684 __CM0_CMSIS_VERSION_SUB ) /* CMSIS HAL version number */
686 #define __CORTEX_M (0U) /* Cortex-M Core */
692 #define __CM0PLUS_CMSIS_VERSION_MAIN (5U) /* [31:16] CMSIS HAL main version */
693 #define __CM0PLUS_CMSIS_VERSION_SUB (0U) /* [15:0] CMSIS HAL sub version */
694 #define __CM0PLUS_CMSIS_VERSION ((__CM0P_CMSIS_VERSION_MAIN << 16U) | \
695 __CM0P_CMSIS_VERSION_SUB ) /* CMSIS HAL version number */
697 #define __CORTEX_M (0U) /* Cortex-M Core */
703 #define __CM3_CMSIS_VERSION_MAIN (5U) /* [31:16] CMSIS HAL main version */
704 #define __CM3_CMSIS_VERSION_SUB (0U) /* [15:0] CMSIS HAL sub version */
705 #define __CM3_CMSIS_VERSION ((__CM3_CMSIS_VERSION_MAIN << 16U) | \
706 __CM3_CMSIS_VERSION_SUB ) /* CMSIS HAL version number */
708 #define __CORTEX_M (3U) /* Cortex-M Core */
713 #define __CM4_CMSIS_VERSION_MAIN (5U) /* [31:16] CMSIS HAL main version */
714 #define __CM4_CMSIS_VERSION_SUB (0U) /* [15:0] CMSIS HAL sub version */
715 #define __CM4_CMSIS_VERSION ((__CM4_CMSIS_VERSION_MAIN << 16U) | \
716 __CM4_CMSIS_VERSION_SUB ) /* CMSIS HAL version number */
718 #define __CORTEX_M (4U) /* Cortex-M Core */
723 #define __CM7_CMSIS_VERSION_MAIN (5U) /* [31:16] CMSIS HAL main version */
724 #define __CM7_CMSIS_VERSION_SUB (0U) /* [15:0] CMSIS HAL sub version */
725 #define __CM7_CMSIS_VERSION ((__CM7_CMSIS_VERSION_MAIN << 16U) | \
726 __CM7_CMSIS_VERSION_SUB ) /* CMSIS HAL version number */
728 #define __CORTEX_M (7U) /* Cortex-M Core */
733 #define __SC000_CMSIS_VERSION_MAIN (5U) /* [31:16] CMSIS HAL main version */
734 #define __SC000_CMSIS_VERSION_SUB (0U) /* [15:0] CMSIS HAL sub version */
735 #define __SC000_CMSIS_VERSION ((__SC000_CMSIS_VERSION_MAIN << 16U) | \
736 __SC000_CMSIS_VERSION_SUB ) /* CMSIS HAL version number */
738 #define __CORTEX_SC (0U) /* Cortex secure core */
743 #define __SC300_CMSIS_VERSION_MAIN (5U) /* [31:16] CMSIS HAL main version */
744 #define __SC300_CMSIS_VERSION_SUB (0U) /* [15:0] CMSIS HAL sub version */
745 #define __SC300_CMSIS_VERSION ((__SC300_CMSIS_VERSION_MAIN << 16U) | \
746 __SC300_CMSIS_VERSION_SUB ) /* CMSIS HAL version number */
748 #define __CORTEX_SC (300U) /* Cortex secure core */
753 #define __ARMv8MBL_CMSIS_VERSION_MAIN (5U) /* [31:16] CMSIS HAL main version */
754 #define __ARMv8MBL_CMSIS_VERSION_SUB (0U) /* [15:0] CMSIS HAL sub version */
755 #define __ARMv8MBL_CMSIS_VERSION ((__ARMv8MBL_CMSIS_VERSION_MAIN << 16U) | \
756 __ARMv8MBL_CMSIS_VERSION_SUB ) /* CMSIS HAL version number */
758 #define __CORTEX_M (tbd) /* Cortex secure core */
763 #define __ARMv8MML_CMSIS_VERSION_MAIN (5U) /* [31:16] CMSIS HAL main version */
764 #define __ARMv8MML_CMSIS_VERSION_SUB (0U) /* [15:0] CMSIS HAL sub version */
765 #define __ARMv8MML_CMSIS_VERSION ((__ARMv8MML_CMSIS_VERSION_MAIN << 16U) | \
766 __ARMv8MML_CMSIS_VERSION_SUB ) /* CMSIS HAL version number */
768 #define __CORTEX_M (tbd) /* Cortex secure core */
772 \section device_access Device Peripheral Access Layer
774 The \ref device_h_pg contains for each peripheral:
775 - Register Layout Typedef
779 The section \ref peripheral_gr shows examples for peripheral definitions.
781 \section device_h_sec Device.h Template File
783 The silicon vendor needs to extend the Device.h template file with the CMSIS features described above.
784 In addition the \ref device_h_pg may contain functions to access device-specific peripherals.
785 The \ref system_Device_h_sec which is provided as part of the CMSIS specification is shown below.
787 \verbinclude "Include\Device.h"