cancel
Showing results for 
Search instead for 
Did you mean: 

How to integrate CMSIS-DSP libraries on a STM32 project

KDJEM.1
ST Employee

Introduction

Since CMSIS V 5.8.0, the CMSIS-DSP libraries are supplied as an individual package. The advantage is to decouple the release cycles of DSP from the CMSIS-Core stuff. As a side-effect, the DSP libraries structure was changed and the steps described in the article: Configuring DSP libraries on STM32CubeIDE cannot be applied.
For that the aim of this article is to describe step by step: How to integrate this new CMSIS-DSP on an STM32 project.

Before you get started, open the ARM.CMSIS.pdsc file in \STM32Cube_FW_xx_Vx.x.x\Drivers\CMSIS folder with notepad to know which CMSIS version is included in the package. 

KDJEM1_3-1716913675458.png

Software prerequisite

The versions used in this tutorial are:

Step-by-step instructions

The following steps show how to integrate DSP libraries in your project when using STM32CubeIDE toolchain. For this demonstration, an example based on the STM32CubeF4 package version 1.28.0 is used.

1. Create a new project using STM32CubeMX and STM32F429-DISC1 board.

KDJEM1_0-1716913201570.png
2. After finishing the settings, generate the code with the STM32CubeIDE tool chain and STM32CubeF4 1.28.0
KDJEM1_1-1716913286505.png
3. In the generated project, create a folder under ..\Drivers named "CMSIS_DSP"

4. Copy these folders in the created folder:

<STM32Cube_Repository>\STM32Cube_FW_F4_V1.28.0\Drivers\CMSIS\DSP\Include

<STM32Cube_Repository>\STM32Cube_FW_F4_V1.28.0\Drivers\CMSIS\DSP\PrivateInclude

<STM32Cube_Repository>\STM32Cube_FW_F4_V1.28.0\Drivers\CMSIS\DSP\Source

5. For this example, only the SupportFunctions are used. For that, open the "Source" folder under "..\Drivers\CMSIS_DSP" and keep only the SupportFunctions (other folders can be removed).

KDJEM1_5-1716913808851.png
6. Make sure that you have these folders in your project with this structure
KDJEM1_6-1716913860403.png
7. Update include paths: 
Include paths: Select project properties from the [Project Explorer] section
From the [Project menu or [File menu], go to [Project properties] > [C/C++ Build] > [Settings] > [Tool Settings] > [MCU GCC Compiler] > [Include paths]
  • Click on [Add] to include the new paths.

  • Add the ../Drivers/CMSIS_DSP/Include path and the ../Drivers/CMSIS_DSP/PrivateInclude path

KDJEM1_3-1714995417164.png
8. Open SupportFunctions.c and SupportFunctionsF16.c files and comment these lines of code:

File name

Source Comment code lines

SupportFunctions.c

Drivers\CMSIS_DSP\Source\

SupportFunctions

#include "arm_barycenter_f32.c"
#include "arm_bitonic_sort_f32.c"
#include "arm_bubble_sort_f32.c"
#include "arm_copy_f32.c"
#include "arm_copy_f64.c"
#include "arm_copy_q15.c"
#include "arm_copy_q31.c"
#include "arm_copy_q7.c"
#include "arm_fill_f32.c"
#include "arm_fill_f64.c"
#include "arm_fill_q15.c"
#include "arm_fill_q31.c"
#include "arm_fill_q7.c"
#include "arm_heap_sort_f32.c"
#include "arm_insertion_sort_f32.c"
#include "arm_merge_sort_f32.c"
#include "arm_merge_sort_init_f32.c"
#include "arm_quick_sort_f32.c"
#include "arm_selection_sort_f32.c"
#include "arm_sort_f32.c"
#include "arm_sort_init_f32.c"
#include "arm_weighted_sum_f32.c"

#include "arm_float_to_q15.c"
#include "arm_float_to_q31.c"
#include "arm_float_to_q7.c"
#include "arm_q15_to_float.c"
#include "arm_q15_to_q31.c"
#include "arm_q15_to_q7.c"
#include "arm_q31_to_float.c"
#include "arm_q31_to_q15.c"
#include "arm_q31_to_q7.c"
#include "arm_q7_to_float.c"
#include "arm_q7_to_q15.c"
#include "arm_q7_to_q31.c"
SupportFunctionsF16.c

Drivers\CMSIS_DSP\Source\

SupportFunctions

#include "arm_copy_f16.c"

#include "arm_fill_f16.c"

#include "arm_f16_to_q15.c"

#include "arm_f16_to_float.c"

#include "arm_q15_to_f16.c"

#include "arm_float_to_f16.c"

#include "arm_weighted_sum_f16.c"

#include "arm_barycenter_f16.c"

 

9. Now, you can use the DSP libraries in your project. For that open main.c and add the required header file "arm_math.h" and declare the used variables:

#include "arm_math.h"

 

/* USER CODE BEGIN PD */
#define FFT_Length  1024
/* USER CODE END PD */

 

/* USER CODE BEGIN PV */
float32_t FFT_Input_Q15_f[50];
float32_t aFFT_Input_Q15[50];
/* USER CODE END PV */

10. Let us take the example of using the “arm_float_to_q15” function:

/* USER CODE BEGIN 1 */
	arm_float_to_q15((float32_t *)&FFT_Input_Q15_f[0], (q15_t *)&aFFT_Input_Q15[0], FFT_Length*2);
/* USER CODE END 1 */

 

Note:

Conclusion

In conclusion, after following the steps outlined in this article, you should be able to add DSP libraries to a STM32 project. If you encounter any issues, we suggest that you create a post in the ST community for further assistance.

Comments
Bruce_nForeTek
Associate

Hello KDJEM.1,

This works on my STM32U5 chip!

Thanks for the tutorial!

Thanks a lot!

 

BTW,

There are some mistakes in 7.

The path is wrong(but they're correct in the figure)

 

7. Update include paths: 
Include paths: Select project properties from the [Project Explorer] section
From the [Project menu or [File menu], go to [Project properties] > [C/C++ Build] > [Settings] > [Tool Settings] > [MCU GCC Compiler] > [Include paths]
  • Click on [Add] to include the new paths.

  • Add the ../Drivers/CMSIS/CMSIS_DSP/Include path and the ../Drivers/CMSIS/CMSIS_DSP/PrivateInclude path  <- Path here is wrong

KDJEM.1
ST Employee

Hello @Bruce_nForeTek and welcome to STCommunity :),

 

Glad to know that this FAQ can help to integrate the DSP library with STM32U5.

Thank you for bringing the step 7 typo to our attention. 

The typo is fixed.

Thank you again for the continued feedback; it is much appreciated!

 

Kaouthar

 

thejc
Associate II

Hello @KDJEM.1 

if I want to add the whole DSP library do I need to go through every folder and comment out every #include "file.c" in every .c file. This solution doesn't really seem that elegant, isn't there a possibility to add it through the CubeIDE just like its possible for FreeRTOS?

 

Julian

JvdV
Associate II

I had a project working with the CMSIS 5.8.0 but wanted to update it to use CMSIS 5.9.0. I followed your steps, but things are not working as expected. I get an undefined reference to `arm_fir_init_f32' error when I try to compile, which is the first function I try to use from CMSIS-DSP. To be clear, I removed the arm_cortexm4lf_math library that I used to need. I did not comment anything out of any .c files, so all functions should be available. Do you have any idea what the problem might be? Thank you so much for your advice!

Edit: Since I did not put my DSP folder inside Drivers folder, I had to add DSP folder as Source Location. Then the DSP functions were located, but tons of complaints about multiple definitions. Originally I thought you were commenting out stuff in SupportFunctions.c and SupportFunctionsF16.c because you weren't using those bits, but wow those <foldername>.c and <foldername>F16.c files have to be commented out or deleted in every folder a person keeps in their project! So I did all that and my code compiles, but I am still not all the way there. My filter code that worked with the previous CMSIS-DSP setup (with the arm_cortexm4lf_math library and all) now does not work and causes all kinds of strange behaviours. Still wrestling. Will report back if/when I figure it out.

Further edit: Code was fine, but my filter with 101 coefficients that worked fine before now takes too long for my 1024 half DMA buffer. If I reduce to a filter with 81 coefficients, everything is OK. Surprised that the previous setup for CMSIS-DSP would be faster then the new setup. Other interesting note: the output of my code completely dies (even talk-through, no filter) when I set -Ofast flag.

JvdV_1-1724555204418.png

JvdV_2-1724555233302.png

JvdV_0-1724555177051.png

 

 

 

KDJEM.1
ST Employee

Hello @JvdV,

 

Which error did you get about "arm_fir_init_f32.c"?

If you encounter any issues, we suggest that you create a post in the ST Community for further assistance.

To check the issue could you please share your project when you create a new thread in the community?

Thank you.

Kaouthar

tasabao
Associate III

Hello @KDJEM.1,
I encountered the same issue. The current error code is: undefined reference to arm_rfft_fast_f32. I followed the steps exactly as instructed. May I ask why this is happening? Thank you.

 

 

tasabao_1-1725529190656.png

 

tasabao_3-1725529262913.png

 

 

tasabao_0-1725529108599.png

 

KDJEM.1
ST Employee

Hi @tasabao , 

 

According " arm_rfft_fast_f32" error, you use a FilteringFunctions.

For that, in step 5 keep also a FilteringFunctions Folder.

Note that only the SupportFunctions are used in this FAQ.

KDJEM1_1-1725530040213.png

Please don't forgot to open FilteringFunctions.c and FilteringFunctionsF16.c and comment and comment all include as descripted in step 8.

 Also, I e suggest that you create a post in the ST Community for further assistance.

 

Thank you.

Kaouthar

 

Version history
Last update:
‎2024-06-24 01:36 AM
Updated by: