STM32 FPU (Floating-Point Unit) Enable/Disable

In this short article, we’ll explore How To Enable The STM32 FPU (Floating-Point Unit) and how much it affects the speed of executing floating-point arithmetic operations. We’ll also conduct a simple experiment to test the execution time reduction that we can get by using the STM32 FPU for floating-point operations.

Table of Contents

  1. STM32 FPU
  2. STM32 FPU Enable Floating-Point Unit (Steps)
  3. STM32 FPU Performance Test (Enable / Disable)
  4. Wrap Up


Some STM32 microcontrollers have an internal FPU (Floating-Point Unit) that can accelerate floating-point arithmetic operations by executing them in hardware instead of software emulation for these operations which takes a bit longer time compared to the hardware FPU performance.

Below is a table that summarizes which ARM Cortex-M cores support a hardware FPU with only single-precision (SP), double-precision (DP), or no FPU at all. By checking your STM32 microcontroller’s datasheet you can easily figure out which ARM Cortex-M core it has.

M0, M0+, M1, M3, M23*
M4, M33, M35P, M55*

STM32 FPU Enable Floating-Point Unit (Steps)

There are only two steps required to enable the STM32 FPU given that your target STM32 microcontroller does actually have an internal hardware FPU unit. Those steps are as follows:

Step #1

Set The Compiler Flags To Use The Hardware FPU

We need to set the compiler flags so it uses the hardware FPU unit for floating-point arithmetic operations instead of software-emulating them. This is done by default if you’re using the STM32CubeMX for generating your project, it’ll automatically detect if your selected STM32 microcontroller has an internal FPU unit and it’ll set it for you.

To double-check this, we can right-click the project name in the project navigator > select Properties > C/C++ Build > Settings > MCU Settings

And there you’ll find the following options enabled by default.

STM32 FPU (Floating Point Unit) Enable Compiler Flags

Step #2

Set The FPU Enable Bit in The CPACR Register

Next up, we need to enable the FPU by writing to the CPACR register (Coprocessor Access Control Register) which has a control bit to enable/disable the hardware FPU unit. This is also done by default if you’re using the STM32CubeMX to generate your project initialization code, you’ll find that it calls the HAL_Init() function at the beginning of the main() function.

By tracking the initialization sequence, you’ll find out that it also calls the SystemInit() function that looks like the one shown below.

And that’s all about it, now the FPU is enabled and any floating-point operations in your source code will be executed with the help of the FPU to accelerate the CPU’s performance in such calculations.

❕ Note

If you’re using the STM32CubeMX to generate your project initialization code files, you’ll probably be good to go and the FPU will be used by default in your floating-point operations without worrying about manually enabling the FPU.

STM32 FPU Performance Test (Enable / Disable)

To test the FPU performance and compare between having it enabled or disabled, I’ve created the following simple test setup. We’ll just create a new project for our STM32 hardware board (I’ve used Nucleo-L432KC) and enable a GPIO output pin.

The Application Code For This Test Example

As stated earlier, the CubeMX HAL initializes the necessary hardware and enables the FPU by default. And the default compiler flags are also pointing to the hardware FPU instead of software emulation, so we’re good to go. Here is the measured execution time for the function above that does 10x floating-point multiplications.

STM32 FPU Enable Performance Test

Let’s now disable the FPU using the compiler flags as shown below.


Here is what the execution time measured looks like.

STM32 FPU Enable Example Test

FPU EnabledFPU Disabled
Execution Time Measured3µs7.16µs

There is definitely a noticeable acceleration in the floating-point computations when having the STM32 FPU enabled.

Required Parts For STM32 Examples

All the example Code/LABs/Projects in this STM32 Series of Tutorials are done using the Dev boards & Electronic Parts Below:

QTY.Component NameAmazon.comAliExpresseBay
1STM32-F103 BluePill Board (ARM Cortex-M3 @ 72MHz)AmazonAliExpresseBay
1Nucleo-L432KC (ARM Cortex-M4 @ 80MHz)AmazonAliExpresseBay
1ST-Link V2 DebuggerAmazonAliExpresseBay
1LEDs KitAmazonAmazonAliExpresseBay
1Resistors KitAmazonAmazonAliExpresseBay
1Capacitors KitAmazonAmazonAliExpress & AliExpresseBay & eBay
1Jumper Wires PackAmazonAmazonAliExpress & AliExpresseBay & eBay
1Push ButtonsAmazonAmazonAliExpresseBay
1Micro USB CableAmazonAliExpresseBay

★ Check The Links Below For The Full Course Kit List & LAB Test Equipment Required For Debugging ★

Download Attachments

You can download all attachment files for this Article/Tutorial (project files, schematics, code, etc..) using the link below. Please consider supporting our work through the various support options listed in the link down below. Every small donation helps to keep this website up and running and ultimately supports the whole community.

Wrap Up

In conclusion, we’ve discussed how the STM32 FPU can be enabled & disabled and how it can accelerate the performance of the CPU by doing the floating-point arithmetic operations in hardware instead of being software-emulated. You should choose an STM32 microcontroller that has an internal hardware FPU if you’re planning to create a project that’s computationally intensive and requires a lot of floating-point operations.

If you’re just getting started with STM32, you need to check out the STM32 Getting Started Tutorial here.

Follow this STM32 Series of Tutorials to learn more about STM32 Microcontrollers Programming.

Share This Page With Your Network!
Join Our +25,000 Newsletter Subscribers!

Stay Updated With All New Content Releases. You Also Get Occasional FREE Coupon Codes For Courses & Other Stuff!

Photo of author
Khaled Magdy
Embedded systems engineer with several years of experience in embedded software and hardware design. I work as an embedded SW engineer in the Automotive & e-Mobility industry. However, I still do Hardware design and SW development for DSP, Control Systems, Robotics, AI/ML, and other fields I'm passionate about.
I love reading, writing, creating projects, and teaching. A reader by day and a writer by night, it's my lifestyle. I believe that the combination of brilliant minds, bold ideas, and a complete disregard for what is possible, can and will change the world! I will be there when it happens, will you?

Leave a Comment