Skip to main content
t_j_l
Associate II
March 4, 2026
Question

How to enable FPU support?

  • March 4, 2026
  • 2 replies
  • 217 views

After generating the CMake project using STM32CubeMX (with the MCU being stm32f412ret6), how can FPU support be enabled in VSCode(STM32CubeIDE for Visual Studio Code)?

2 replies

March 4, 2026

To enable FPU support, first make sure your processor supports FPU, then enable it in BIOS/UEFI if required, and configure your compiler with the correct FPU flags (like -mfpu for GCC). Also ensure your OS or firmware has FPU support enabled. Just like following 呪術廻戦raw, small configuration details can make a big difference. :rocket:

 
 
 
Nawres GHARBI
Technical Moderator
March 5, 2026

Hi @t_j_l 

1. Check that your MCU has an FPU

The STM32F412RE has an ARM Cortex‑M4 with single‑precision FPU.
So you should use:

  • -mfpu=fpv4-sp-d16

  • -mfloat-abi=hard


2. Locate your CMake toolchain / compiler flags

Depending on how STM32CubeMX generated your CMake project, you will typically have one of these:

  • CMakeLists.txt at project root (for generic CMake)

  • And optionally a toolchain file, e.g. cmake/gcc-arm-none-eabi.toolchain.cmake or similar.

Open CMakeLists.txt and look for compiler flags such as:

set(CMAKE_C_FLAGS "...existing flags...")
set(CMAKE_CXX_FLAGS "...existing flags...")
set(CMAKE_ASM_FLAGS "...existing flags...")

or

add_compile_options(...)

3. Add FPU flags to C / C++ / ASM

Add the three options for architecture, FPU and ABI to all languages:

# Example: add to global compile options
add_compile_options(
 -mcpu=cortex-m4
 -mthumb
 -mfpu=fpv4-sp-d16
 -mfloat-abi=hard
)

If you prefer to modify the existing variables instead:

set(COMMON_FLAGS "-mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard")

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COMMON_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMMON_FLAGS}")
set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} ${COMMON_FLAGS}")

Also ensure your linker flags include the same CPU/FPU options:

set(CMAKE_EXE_LINKER_FLAGS
 "${CMAKE_EXE_LINKER_FLAGS} -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard"
)

4. Update .vscode/settings.json (if needed)

If the STM32 VSCode extension generated IntelliSense configuration, it might have a compilerPath or compilerArgs section. Check .vscode/c_cpp_properties.json or .vscode/settings.json for something like:

"compilerArgs": [
 "-mcpu=cortex-m4",
 "-mthumb"
]

Add the FPU arguments there too:

"compilerArgs": [
 "-mcpu=cortex-m4",
 "-mthumb",
 "-mfpu=fpv4-sp-d16",
 "-mfloat-abi=hard"
]

This does not affect the build, but keeps IntelliSense consistent with the actual compilation flags.


5. Regenerate / configure CMake in VSCode

In VSCode (STM32CubeIDE for VSCode):

  1. Open the CMake Tools extension (or the STM32 CMake integration).

  2. Run Configure (or Clean Configure) so the new flags are picked up.

  3. Then run Build.

If you use CMake presets (CMakePresets.json), you can also add the flags there:

{
 "configurePresets": [
 {
 "name": "stm32-debug",
 "cacheVariables": {
 "CMAKE_C_FLAGS": "-mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard",
 "CMAKE_EXE_LINKER_FLAGS": "-mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard"
 }
 }
 ]
}