Skip to main content

Command Palette

Search for a command to run...

How to import CMSIS-DSP library into STM32Cube?

Published
3 min read
How to import CMSIS-DSP library into STM32Cube?

Here are the 2 common ways to “import” CMSIS-DSP into an STM32CubeMX / STM32CubeIDE project. (CubeMX usually already ships the CMSIS-DSP files inside the STM32Cube firmware package—you mainly need to add include paths and either compile sources or link the prebuilt lib.)


1) Locate CMSIS-DSP in your Cube project

After CubeMX generates code, you typically have:

  • Drivers/CMSIS/Include

  • Drivers/CMSIS/DSP/Include

  • Drivers/CMSIS/DSP/Source/...

2) Add include paths (CubeIDE)

Project → Properties → C/C++ Build → Settings → MCU GCC Compiler → Includes
Add:

  • ${workspace_loc:/${ProjName}/Drivers/CMSIS/Include}

  • ${workspace_loc:/${ProjName}/Drivers/CMSIS/DSP/Include}

3) Add DSP source files to build

You can either:

  • Copy the needed folders from Drivers/CMSIS/DSP/Source/ into your project (e.g., TransformFunctions, FilteringFunctions, …), or

  • Link them in place (keep them inside Drivers and ensure they’re compiled)

Practical tip: don’t compile everything unless you need it—FFT only needs the TransformFunctions (+ some BasicMath / CommonTables depending on function).

4) Define the correct core macro

MCU GCC Compiler → Preprocessor → Defined symbols, add one that matches your CPU:

  • ARM_MATH_CM0 / ARM_MATH_CM0PLUS

  • ARM_MATH_CM3

  • ARM_MATH_CM4

  • ARM_MATH_CM7

  • ARM_MATH_CM33

5) Make sure your FPU settings match (if your MCU has FPU)

CubeIDE usually sets this correctly from CubeMX. Check:
MCU GCC Compiler → MCU Settings

  • Cortex-M4F: -mfpu=fpv4-sp-d16 -mfloat-abi=hard

  • Cortex-M7: -mfpu=fpv5-d16 -mfloat-abi=hard (varies by part)

Then include in code:

#include "arm_math.h"

Some Cube packages include prebuilt libs like:
Drivers/CMSIS/DSP/Lib/GCC/libarm_cortexM4lf_math.a (example)

1) Add include paths (same as Option A)

  • Drivers/CMSIS/Include

  • Drivers/CMSIS/DSP/Include

2) Add library search path + library name

Project → Properties → C/C++ Build → Settings → MCU GCC Linker

  • Library search path (-L): add the folder containing the .a

  • Libraries (-l): add the library name without lib and .a

    • e.g. for libarm_cortexM4lf_math.a, use: arm_cortexM4lf_math

3) Confirm CPU/FPU flags match the library

If you link an M4F hard-float library but your project is set to soft-float, you’ll get linker errors or wrong behavior.


Quick sanity test (FFT example)

If you’re on an FPU part (M4F/M7), try the fast real FFT:

#include "arm_math.h"

arm_rfft_fast_instance_f32 S;
float32_t in[256];
float32_t out[256]; // RFFT output packed (complex bins)

void dsp_init(void){
  arm_rfft_fast_init_f32(&S, 256);
}

void do_fft(void){
  arm_rfft_fast_f32(&S, in, out, 0);
}

Common problems (and what they mean)

  • “arm_math.h not found” → include paths not set.

  • Undefined references to arm_ functions* → you didn’t compile DSP sources (Option A) or didn’t link the .a correctly (Option B).

  • HardFault during DSP call → wrong FPU settings / wrong library flavor / stack too small.

  • Huge build times → you compiled all DSP modules; compile only needed folders.

More from this blog

A

Ampheo Electronic Blog-Chip and component knowledge sharing

181 posts

Original and Genuine Electronic Components Distributor