CMSIS2000
0.0.7
|
CMSIS is Cortex Microcontroller Software Interface Standard
ARM provides as part of the CMSIS the following software layers that are available for various compiler implementations:
These software layers are expanded by Silicon partners with:
CMSIS defines for a Cortex-M Microcontroller System:
By using CMSIS compliant software components, the user can easier re-use template code. CMSIS is intended to enable the combination of software components from multiple middleware vendors.
The CMSIS recommends the following conventions for identifiers.
Comments
Function Comments provide for each function the following information:
Doxygen Example:
/** * @brief Enable Interrupt in NVIC Interrupt Controller * @param IRQn interrupt number that specifies the interrupt * @return none. * Enable the specified interrupt in the NVIC Interrupt Controller. * Other settings of the interrupt such as priority are not affected. */
/**
The Cortex-M HAL uses the standard types from the standard ANSI C header file <stdint.h>. IO Type Qualifiers are used to specify the access to peripheral variables. IO Type Qualifiers are indented to be used for automatic generation of debug information of peripheral registers.
IO Type Qualifier | #define | description |
__I | volatile const | Read access only |
__O | volatile | Write access only |
__IO | volatile | Read and write access |
Files core_cm0.h, core_cm3.h, core_cm4.h contains the version number of the CMSIS with the following define:
Files core_cm0.h, core_cm3.h, core_cm4.h contains the type of the CMSIS Cortex-M with the following defines:
This section describes the Files provided in context with the CMSIS to access the Cortex-M hardware and peripherals.
File | Provider | Description |
device.h | Device specific (provided by silicon partner) | Defines the peripherals for the actual device. The file may use several other include files to define the peripherals of the actual device. |
core_cm0.h | ARM (for RealView ARMCC, IAR, and GNU GCC) | Defines the core peripherals for the Cortex-M0 CPU and core peripherals. |
core_cm3.h | ARM (for RealView ARMCC, IAR, and GNU GCC) | Defines the core peripherals for the Cortex-M3 CPU and core peripherals. |
core_cm4.h | ARM (for RealView ARMCC, IAR, and GNU GCC) | Defines the core peripherals for the Cortex-M4 CPU and core peripherals. |
core_cm4_simd.h | ARM (for RealView ARMCC, IAR, and GNU GCC) | Defines the Cortex-M4 Core SIMD functions. |
core_cmFunc.h | ARM (for RealView ARMCC, IAR, and GNU GCC) | Defines the Cortex-M Core Register access functions. |
core_cmInstr.h | ARM (for RealView ARMCC, IAR, and GNU GCC) | Defines the Cortex-M Core instructions. |
core_cm0.c | ARM (for RealView ARMCC, IAR, and GNU GCC) | Provides helper functions that access core registers. |
core_cm3.c | ARM (for RealView ARMCC, IAR, and GNU GCC) | Provides helper functions that access core registers. |
core_cm4.c | ARM (for RealView ARMCC, IAR, and GNU GCC) | Provides helper functions that access core registers. |
startup_device | ARM (adapted by compiler partner / silicon partner) | Provides the Cortex-M startup code and the complete (device specific) Interrupt Vector Table |
system_device | ARM (adapted by silicon partner) | Provides a device specific configuration file for the device. It configures the device initializes typically the oscillator (PLL) that is part of the microcontroller device |
The file device.h is provided by the silicon vendor and is the central include file that the application programmer is using in the C source code. This file contains:
To access the device specific interrupts the device.h file defines IRQn numbers for the complete device using a enum typedef as shown below:
The following device implementation specific defines are set in the device header file and are used for the Cortex-M core configuration options. Some configuration options are reflected in the CMSIS layer using the #define settings described below.
Several features in core_cm#.h are configured by the following defines that must be defined before include <core_cm#.h> preprocessor command. If the defines are missing the default values will be used.
#define | Core | Value | Default | Description |
__CM0_REV | M0 | 0x0000 | 0x0000 | Core revision number ([15:8] revision number, [7:0] patch number) |
__CM3_REV | M3 | 0x0101 | 0x0200 | 0x0200 | Core revision number ([15:8] revision number, [7:0] patch number) |
__CM4_REV | M4 | 0x0000 | 0x0000 | Core revision number ([15:8] revision number, [7:0] patch number) |
__NVIC_PRIO_BITS | M0, M3, M4 | 2 .. 8 | 2 (M0) 4 (CM3, CM4) | Number of priority bits implemented in the NVIC (device specific) |
__MPU_PRESENT | M0, M3, M4 | 0 | 1 | 0 | Defines if a MPU is present or not |
__FPU_PRESENT | M4 | 0 | 1 | 0 | Defines if a FPU is present or not |
__Vendor_SysTickConfig | M0, M3, M4 | 0 | 1 | 0 | When this define is setup to 1, the SysTickConfig function in core_cm3.h is excluded. In this case the device.h file must contain a vendor specific implementation of this function. |
Each peripheral uses a prefix which consists of <device abbreviation>_ and <peripheral name>_ to identify peripheral registers that access this specific peripheral. The intention of this is to avoid name collisions caused due to short names. If more than one peripheral of the same type exists, identifiers have a postfix (digit or letter). For example:
To access the peripheral registers and related function in a device the files device.h and core_cm0.h / core_cm3.h defines as a minimum:
These definitions allow to access the peripheral registers from user code with simple assignments like:
In addition the device.h file may define:
File core_cm0.h describes the data structures for the Cortex-M0 core peripherals and does the address mapping of this structures. It also provides basic access to the Cortex-M0 core registers and core peripherals with efficient functions (defined as static inline).
File core_cm0.c defines several helper functions that access processor registers.
Together these files implement the Core Peripheral Access Layer for a Cortex-M0.
The define __CMSIS_GENERIC allows to use core_cm0.h in generic library projects that are device independent. Only core relevant types and defines are used.
File core_cm3.h describes the data structures for the Cortex-M3 core peripherals and does the address mapping of this structures. It also provides basic access to the Cortex-M3 core registers and core peripherals with efficient functions (defined as static inline).
File core_cm3.c defines several helper functions that access processor registers.
Together these files implement the Core Peripheral Access Layer for a Cortex-M3.
The define __CMSIS_GENERIC allows to use core_cm3.h in generic library projects that are device independent. Only core relevant types and defines are used.
File core_cm4.h describes the data structures for the Cortex-M4 core peripherals and does the address mapping of this structures. It also provides basic access to the Cortex-M4 core registers and core peripherals with efficient functions (defined as static inline).
File core_cm4.c defines helper functions that access processor registers.
File core_cm4_simd.h defines Cortex-M4 SIMD instructions.
Together these files implement the Core Peripheral Access Layer for a Cortex-M4.
The define __CMSIS_GENERIC allows to use core_cm4.h in generic library projects that are device independent. Only core relevant types and defines are used.
File core_cmFunc.h defines the Cortex-M Core Register access functions (defined as static inline)..
File core_cmInstr.h defines the Cortex-M Core instructions (defined as static inline)..
These files are part of the Core Peripheral Access Layer for a Cortex-M.
A template file for startup_device is provided by ARM for each supported compiler. It is adapted by the silicon vendor to include interrupt vectors for all device specific interrupt handlers. Each interrupt handler is defined as weak function to an dummy handler. Therefore the interrupt handler can be directly used in application software without any requirements to adapt the startup_device file.
The following exception names are fixed and define the start of the vector table for a Cortex-M0:
The following exception names are fixed and define the start of the vector table for a Cortex-M3:
In the following examples for device specific interrupts are shown:
Device specific interrupts must have a dummy function that can be overwritten in user code. Below is an example for this dummy function.
The user application may simply define an interrupt handler function by using the handler name as shown below.
/**
A template file for system_device.c is provided by ARM but adapted by the silicon vendor to match their actual device. As a minimum requirement this file must provide a device specific system configuration function and a global variable that contains the system frequency. It configures the device and initializes typically the oscillator (PLL) that is part of the microcontroller device.
The file system_device.c must provide as a minimum requirement the SystemInit function as shown below.
Function Definition | Description |
void SystemInit (void) | Setup the microcontroller system. Typically this function configures the oscillator (PLL) that is part of the microcontroller device. For systems with variable clock speed it also updates the variable SystemCoreClock. SystemInit is called from startup_device file. |
void SystemCoreClockUpdate (void) | Updates the variable SystemCoreClock and must be called whenever the core clock is changed during program execution. SystemCoreClockUpdate() evaluates the clock register settings and calculates the current core clock. |
Also part of the file system_device.c is the variable SystemCoreClock which contains the current CPU clock speed shown below.
Variable Definition | Description |
uint32_t SystemCoreClock (void) |
Contains the system core clock (which is the system clock frequency supplied to the SysTick timer and the processor core clock). This variable can be used by the user application to setup the SysTick timer or configure other parameters. It may also be used by debugger to query the frequency of the debug timer or configure the trace clock speed. SystemCoreClock is initialized with a correct predefined value. The compiler must be configured to avoid the removal of this variable in case that the application program is not using it. It is important for debug systems that the variable is physically present in memory so that it can be examined to configure the debugger. |
Note: