cancel
Showing results for 
Search instead for 
Did you mean: 

Question about STM32 FPUs and FREERTOS

CStew.2
Associate II

Do the STM32 MCUs that have a floating point unit use it automatically or does it only use it once you have enabled it in the FREERTOS configuration?

Say on a STM32H743 which has a double precision FPU, if I have a floating point calculation in my code will it automatically use the FPU to do the calculation.

The reason I'm asking this is because I am currently looking at freertos and it has an option called ENABLE_FPU, does this mean that I have to enable this to use the FPU at all even if I dont use freertos or does it just let freertos use the FPU and if so, if I am using freertos should I enable it.

Many thanks,

Conor Stewart

6 REPLIES 6
TDK
Guru

It needs to be enabled at compile-time in order for the compiler to generate FPU instructions, rather than emulating them in software. This is done in the IDE:

0693W00000BbbYwQAJ.png 

It also needs to be enabled in hardware when your program is starting up. In HAL, this is done with the __FPU_PRESENT and __FPU_USED flags.

Enabling the FPU is the default as far as I can tell.

If you feel a post has answered your question, please click "Accept as Solution".

The FPU is a coprocessor, it must be explicitly enabled in code, typically in Reset_Handler or SystemInit(), otherwise the execution of FPU instructions, including push/pop at function prologue/epilogue code (ie float code in main() ), will cause a Hard Fault

You probably don't need to tell FreeRTOS you're using it if you have everything in a single thread of execution, and the context doesn't need preserving, but if you don't think you can maintain containment of the code, or you pull in other libraries or code with different expectations, probably safer to have the RTOS be aware.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Thank you that was extremely helpful, I've had a project I've been working on that involves a lot of floating point math so I just saw this config setting that said enable fpu so I thought maybe my project was just doing it in software instead of using the fpu, thus running slower but it seem in cubeide that it is enabled by default. This has cleared up a lot for me.

Thank you, just trying to learn RTOS at the moment and saw this config setting and thought that one of my other projects that didnt use RTOS maybe wasnt using the FPU but it is enabled by default in the project properties.

Did you figure out what those define mean ? As for I am aware , The RTOS compilation fails whenever I shift the compiler flag to not use FPU. So I assumed stm adoption of FreeRTOS has some part of code dependent on FPU.

There's even source code for the moderately curious..​

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..