Section 6.43

CMSIS

Full name: Common Microcontroller Software Interface Standard.

Definition

CMSIS (Common Microcontroller Software Interface Standard) is a family of software interfaces, libraries, tools and file formats that Arm publishes for microcontrollers §6.1 built on its Cortex processors. It is not one library: each part has its own name and job. CMSIS-Core gives C code standard access to the processor core; CMSIS-Driver defines peripheral driver interfaces; CMSIS-RTOS2 is the second version of the CMSIS interface to an RTOS (real-time operating system); and CMSIS-DSP provides DSP (digital signal processing) functions. Using one part does not imply using another.

The idea

Before CMSIS, each chip vendor wrote its own names and functions for parts that are identical on every chip with the same Arm processor core, such as the interrupt §6.11 controller and the system timer. Code that enabled an interrupt on one vendor’s Cortex-M4 §6.3 chip had to be rewritten for another vendor’s Cortex-M4 chip. CMSIS fixed one set of names for those common parts, and Arm later added further standard pieces around it: driver interfaces, an operating-system interface, math libraries, a packaging format and debugging aids. Arm first published it under the name Cortex Microcontroller Software Interface Standard; Arm now expands the C as Common.

The umbrella name is the trap. Saying that firmware “uses CMSIS” is like saying that a house uses standard parts: true, and useless until one says which parts. The parts carry different kinds of dependency. CMSIS-Core is mostly header files: names, constants and short inline functions that cost nothing until they are called. CMSIS-DSP is compiled code that runs and whose results obey a numerical contract. CMSIS-RTOS2 is an interface whose behavior comes entirely from the kernel behind it. A claim about one part says nothing about the others.

How it works

Arm’s documentation groups the parts as follows.

CMSIS-Core is the part that most firmware touches. For each chip the vendor supplies a device header. It defines the chip’s interrupt numbers, as a C enumeration of names such as UART0_IRQn, and constants such as __NVIC_PRIO_BITS, the number of priority bits that the chip implements. The device header includes Arm’s core header for the processor, such as core_cm4.h for the Cortex-M4, which supplies:

The vendor also supplies start-up code and a system file whose function SystemInit() sets up the clocks and whose variable SystemCoreClock holds the processor’s clock frequency.

To tell which part a piece of code uses, look at the names it uses. Functions beginning with NVIC_ or SysTick_, and intrinsics such as __DSB(), belong to CMSIS-Core. Functions beginning with arm_ and ending in a number-format suffix such as _f32 or _q15, for example arm_mean_q15(), belong to CMSIS-DSP; CMSIS-NN also uses the arm_ prefix. Functions beginning with os, such as osThreadNew(), belong to CMSIS-RTOS2. Driver structures such as ARM_DRIVER_USART belong to CMSIS-Driver.

Worked example

CMSIS-Core: an interrupt priority. A chip implements 3 priority bits, so its device header sets __NVIC_PRIO_BITS to 3, and the chip has 23=82^3 = 8 priority levels, from 0, the most urgent, to 7. Each interrupt has an 8-bit priority field of which only the top 3 bits exist. NVIC_SetPriority(irq, 5) shifts the value left by 8−3=58 - 3 = 5 bits and keeps the low 8 bits of the result: 5×25=1605 \times 2^5 = 160, which is 0xA0, or 101 followed by five zeros in binary. The top 3 bits hold 5, as intended. The function does not check its argument. A call with priority 9 computes 9×25=2889 \times 2^5 = 288; keeping the low 8 bits gives 288−256=32288 - 256 = 32, whose top 3 bits hold 1. A programmer who asked for a level less urgent than 7 got the second most urgent one. CMSIS-Core standardizes how the register is written; staying within the chip’s range is the caller’s job.

CMSIS-DSP: a number format. The library’s Q15 functions take 16-bit integers that stand for fractions: the integer xx means x/32768x / 32768, so the range runs from −1-1 to just below 1. The samples 0.25, 0.5, −0.25-0.25 and 0.75 are stored as 0.25×32768=81920.25 \times 32768 = 8192, 16384, −8192-8192 and 24576. Their sum is 8192+16384−8192+24576=409608192 + 16384 - 8192 + 24576 = 40960, larger than 32767, the largest 16-bit value, so a correct mean function adds them in a wider register. The mean is 40960/4=1024040960 / 4 = 10240, which stands for 10240/32768=0.312510240 / 32768 = 0.3125; indeed (0.25+0.5−0.25+0.75)/4=1.25/4=0.3125(0.25 + 0.5 - 0.25 + 0.75) / 4 = 1.25 / 4 = 0.3125. The output 10240 is correct only for a caller who reads it as 0.3125; a caller who treats the numbers as plain integers has broken the format contract.

CMSIS-RTOS2: a delay. osDelay(10) asks the kernel behind the interface to suspend the calling thread for 10 kernel ticks, the kernel’s unit of time. With a kernel configured for 1000 ticks per second, that is 10 ms; with one configured for 100 ticks per second, it is 100 ms. The call is the same; the time comes from the kernel and its configuration, which osKernelGetTickFreq() reports.

Stated precisely

Identify a CMSIS dependency by four things: the component, its version, the implementation that provides it, and the target processor. Each component then has its own kind of contract.

Limits and common mistakes

“Uses CMSIS” is not a claim about security, speed or correctness. Each such claim needs the component that supports it, and that component’s contract.

CMSIS-Core standardizes names; the vendor’s device header supplies the values. A wrong interrupt number or priority-bit count in that header makes standard code do the wrong thing.

Versions differ. CMSIS 6 moved CMSIS-DSP and CMSIS-NN out of the main package into packs of their own, and Arm states that the CMSIS-Core headers for Cortex-M devices changed in version 6.0.0 in ways incompatible with earlier versions.

CMSIS covers processors of Arm’s Cortex families. Code written against CMSIS-Core does not carry over to processors of other architectures.

An operating-system interface does not make timing portable. The same CMSIS-RTOS2 call takes whatever time the kernel behind it takes.

Zephyr §6.33 includes CMSIS-Core for its Arm Cortex-M targets and offers an optional CMSIS-RTOS2 layer over its own kernel. A Zephyr application that calls Zephyr’s own kernel functions does not use CMSIS-RTOS2 at all.

Questions answered

Which CMSIS component is actually relevant: core headers, DSP, RTOS interface, or another layer?

The relevant CMSIS component is the one whose names the code actually uses, and it must be found from the code, not from the umbrella name. CMSIS (Common Microcontroller Software Interface Standard) is Arm’s family of separate standard parts for microcontrollers built on Cortex processors. Look at the included files and the calls:

Then judge the code by that component’s own contract and version. Using CMSIS-Core says nothing about threads or signal processing. Much firmware, including most Zephyr applications on Cortex-M chips, uses CMSIS-Core and none of the other parts.

Related entries: NVIC (§6.13), Hardware abstraction layer (HAL) (§6.42), Firmware build profile (§6.44), Arm Cortex-M4 (§6.3). Further reading: [94, 175].