The Cortex Microcontroller Software Interface Standard (CMSIS) DSP library provides a wide range of digital signal processing functions that are optimized for ARM Cortex-M processor-based microcontrollers. Using the CMSIS DSP library in Keil projects can help improve performance and reduce development time compared to coding the DSP algorithms from scratch.
What is the CMSIS DSP Library?
The CMSIS DSP library is a collection of common digital signal processing functions that are optimized for Cortex-M processors. It provides implementations of many common DSP algorithms like filtering, matrix operations, transforms, and statistics functions. The library is part of ARM’s CMSIS packs which aim to simplify software reuse across Cortex-M devices.
The CMSIS DSP library has several key features:
- Implemented in C with ARM assembly optimizations for performance
- Algorithms optimized for Cortex-M4/M7 processors with DSP extensions
- Flexible 32-bit and 64-bit implementations for most functions
- Supports both fixed-point and floating-point data types
- BSD 3-clause license allows free use in commercial applications
Using the CMSIS DSP library can help improve performance over C implementations by 2x to 10x depending on the algorithm. It also saves development time compared to coding DSP functions from scratch.
Adding the CMSIS DSP Library to a Keil Project
To use the CMSIS DSP library in a Keil project, you need to add it to your project and include the appropriate header files. Here are the main steps:
- Download the latest CMSIS DSP library files from GitHub or as part of a Keil pack.
- Add the CMSIS/DSP folder to your project in Keil.
- Include arm_math.h header file which gives access to the core DSP functions.
- Include arm_const_structs.h if using the FIR or IIR filter functions.
- Include arm_common_tables.h for common tables like bit reversal.
- Add the appropriate source files from CMSIS/DSP/Source to your project.
That’s all that is needed to start using the CMSIS DSP functions in your code! Keil’s pack installer makes it easy to quickly add the library files. You can also reference the functions directly from the original GitHub repository.
Using the CMSIS DSP Library Functions
The CMSIS DSP library provides a wide range of digital signal processing functions that are accessible through a consistent API naming scheme. Here are some examples of how to use key CMSIS DSP functions in your code:
Vectors and Matrices
Functions for vector and matrix math like add, multiply, scale, dot product, etc: #include “arm_math.h” float32_t srcA[16], srcB[16], dst[16]; … arm_add_f32(srcA, srcB, dst, 16); // add vectors arm_dot_prod_f32(srcA, srcB, 16); // dot product
Filtering
FIR and IIR filter functions are provided: #include “arm_math.h” #include “arm_const_structs.h” arm_fir_instance_f32 S; arm_fir_init_f32(&S, NUM_TAPS, (float32_t *)&firCoeffs[0], &stateF32[0], BUFFER_SIZE); … arm_fir_f32(&S, inputF32, outputF32, BLOCK_SIZE);
Transforms
Common transforms like FFT, DCT, etc are included: #include “arm_math.h” arm_rfft_instance_f32 S; arm_rfft_init_f32(&S, FFT_SIZE, 0, 1); … arm_rfft_f32(&S, inputF32, outputF32);
Convolution
Convolution functions for efficient sliding window operations: #include “arm_math.h” const float32_t coeffs[5] = {…}; float32_t state[4]; float32_t input[SIGNAL_LENGTH]; float32_t output[SIGNAL_LENGTH]; arm_conv_partial_f32(input, SIGNAL_LENGTH, coeffs, 5, output, &state[0]);
Statistics
Common statistical operations like mean, std deviation, max value are provided: #include “arm_math.h” float32_t input[16]; float32_t mean, stddev; arm_mean_f32(input, 16, &mean); arm_std_f32(input, 16, &stddev);
Tips for Using the CMSIS DSP Library
Here are some tips for working with the CMSIS DSP library in your projects:
- Use Cortex-M4 or M7 devices to take advantage of DSP extensions like SIMD instructions.
- Enable optimizations in your compiler settings for best performance.
- Allocate data buffers in RAM not flash for faster access.
- Use the Compiler 6 toolchain and packs for easy access to CMSIS files.
- Start with float implementations. Switch to fixed-point for memory constrained applications.
- Review algorithm documentation on strategies to optimize or tradeoff precision vs performance.
Example Projects
ARM and Keil provide some example projects showing how to use different CMSIS DSP algorithms:
- FIR Filter – Cascaded FIR filter using the CMSIS DSP library
- Convolution – Convolution example using the CMSIS DSP kernel
- Matrix Math – Matrix addition and multiplication
- FFT – Fast Fourier Transform using CMSIS DSP functions
It’s a good idea to review these for guidance on integrating key algorithms into your application.
Performance and Memory Footprint
A primary benefit of the CMSIS DSP library is providing performance optimized DSP functions that leverage Cortex-M processor capabilities like SIMD. However, there are still tradeoffs to consider between performance, precision, and memory footprint.
Some tips for managing performance and memory:
- Floating point uses more memory but offers better precision and dynamic range.
- Higher order filters provide better frequency response but use more memory and MIPS.
- Enable loop unrolling in the compiler for better performance at the cost of code size.
- Use Cortex-M cores with DSP extensions like M4 and M7 for better CMSIS DSP performance.
- Profile on your target hardware. Memory and performance can vary across Cortex-M devices.
In memory constrained applications, you may need to use fixed-point, lower filter orders, reduce matrix sizes, or disable someloop optimizations. Profiling end application metrics like latency or frequency response on your board can help guide these tradeoff decisions.
Conclusion
The CMSIS DSP library provides an extensive set of common DSP functions optimized for Cortex-M processors. Using the library in Keil projects can accelerate development by leveraging optimized algorithms rather than coding them from scratch.
Add the library using Keil packs, include the arm_math.h header, and call the DSP functions from your code for efficient, high performance signal processing on Cortex-M. Review the algorithm documentation and example projects to best leverage the library capabilities. Evaluate the tradeoffs around precision, memory, and performance for your application requirements.
With its ARM optimizations, the CMSIS DSP library enables developers to achieve great performance in digital signal processing applications using Cortex-M devices. Using the library can help accelerate development of high quality embedded signal processing designs.