2026-03-03 10:23 PM
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)?
2026-03-05 12:42 AM
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:
A 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):
Open the CMake Tools extension (or the STM32 CMake integration).
Run Configure (or Clean Configure) so the new flags are picked up.
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"
}
}
]
}