Skip to main content
KMaen
Associate III
March 26, 2021
Solved

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

  • March 26, 2021
  • 5 replies
  • 2371 views

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!

This topic has been closed for replies.
Best answer by Ozone

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.

5 replies

Ozone
OzoneBest answer
Principal
March 26, 2021

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
KMaenAuthor
Associate III
March 26, 2021

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!

Amel NASRI
ST Technical Moderator
April 2, 2021

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 "Best Answer" on the reply which solved your issue or answered your question.
KMaen
KMaenAuthor
Associate III
April 9, 2021

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!