cancel
Showing results for 
Search instead for 
Did you mean: 

CMSIS functions not working (what is the right compilation flag to give?)

KMaen
Associate III

I am currently using Linux and compiling my project using my own Makefile, with libraries generated via STM32CubeMX from my Windows machine. I am trying to use CMSIS's arm_mat_mult_f32() function but it is not working. I suspect I am passing the wrong compilation flag, but am not sure what I am doing wrong.

I am using STM32F7508-DISCO board. Below are my (what I think are relevant) compilation flags..

-mthumb -mfpu=fpv5-sp-d16 -mfloat-abi=softfp -mcpu=cortex-m7 -DSTM32F750xx -DUSE_HAL_DRIVER -DARM_MATH_CM7 -D__FPU_PRESENT=1 (-DARM_MATH_DSP)

I had to add -DARM_MATH_CM7 and -D__FPU_PRESENT=1 to make it compile, but maybe I am adding something I shouldn't be adding. I tried both with and without -DARM_MATH_DSP but it does not work.

Especally, I go into hardfault handler while running arm_mat_mult_f32(), especially when (I think) running this inst: vldr s14, [r4, #-12]

I am not sure if I am passing the wrong flags, and if so, what is the right flag for my board. (1) what is the right flag for my board? (2) where can I get this information (maybe from STM32CubeMX) ?

Any help will be highly appreciated.

Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
Ozone
Lead

The FPU needs to be enabled explicitly, usually in the startup code.

Here an example from F4 code:

void SystemInit(void)
{
 /* FPU settings ------------------------------------------------------------*/
 #if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
  SCB->CPACR |= ((3UL << 10*2)|(3UL << 11*2)); /* set CP10 and CP11 Full Access */
 #endif
 

SystemInit() is a CMSIS function as well.

View solution in original post

5 REPLIES 5
Ozone
Lead

The FPU needs to be enabled explicitly, usually in the startup code.

Here an example from F4 code:

void SystemInit(void)
{
 /* FPU settings ------------------------------------------------------------*/
 #if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
  SCB->CPACR |= ((3UL << 10*2)|(3UL << 11*2)); /* set CP10 and CP11 Full Access */
 #endif
 

SystemInit() is a CMSIS function as well.

KMaen
Associate III

I am already calling the SystemInit() function in the startup. Actually, I have used FPU assembly's before in my own code. Just the CMSIS DSP functions won't work. That is why I think some new compilation flags that I added to compile the DSP lib might be the problem ( -DARM_MATH_CM7 -D__FPU_PRESENT=1 -DARM_MATH_DSP)

However, while inspecting the SystemInit() function you pointed, I found something weird. __FPU_PRESENT was set even before I added -D__FPU_PRESENT=1 in my CFLAGS and that line was being compiled...(I checked by putting random line between that if-endif).

I am not sure which part of my build chain is setting the __FPU_PRESENT to 1.

Do you know which part of the CMSIS header set __FPU_PRESENT? That might be the starting point for me to understand where everything starts to break.

Thank you for the comment!

KMaen
Associate III

I figured that CMSIS/Device/ST/STM32F7xx/Include/stm32f750xx.h sets the __FPU_PRESENT to 1. However, when compiling CMSIS DSP library, CMSIS/Core/Include/core_cm7.h does not include that file or its mother file stm32f7xx.h, and checks for __FPU_PRESENT, so it thinks it is set to 0.

My build configuration must have been broken, but I don't know how I should be fixing this. How should the __FPU_PRESENT be passed to core_cm7.h when it is not including stm32f750xx.h??

This CubeMX generated libraries (and porting it to Makefile) is so confusing for me. Any help would be appreciated!

Thank you.

Amel NASRI
ST Employee

Hi @KMaen​ ,

If you would like to use STM32CubeIDE, you can refer to the article Configuring DSP libraries on STM32CubeIDE.

You need to pay attention at the end in order to put relevant values related to Cortex-M7.

-Amel

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

KMaen
Associate III

After several days of debugging, I figure that actually my FPU was working correctly -- I was passing a bad pointer so it was just a good old segfault giving me problem. Thank you for the help, all!