Skip to main content
AAnth.1
Senior
November 28, 2021
Question

STM32F303: Where are __SOFT_FP, __ARM_FP, __GNUC__, __VFP_FP__, __SOFTFP__ defined?

  • November 28, 2021
  • 5 replies
  • 5316 views

Hi

Having generated a blank STM32F303 project in STM32CubeIDE, my main file has the following code

#if !defined(__SOFT_FP__) && defined(__ARM_FP)
 #warning "FPU is not initialized, but the project is compiling for an FPU. Please initialize the FPU before use."
#endif

My compiler flags are among others -mfpu=fpv4-sp-d16 -mfloat-abi=hard

I get the following warning as a compilation output:

../Src/main.c:10:4: warning: #warning "FPU is not initialized, but the project is compiling for an FPU. Please initialize the FPU before use." [-Wcpp]

Full compiler invocation:

arm-none-eabi-gcc -mcpu=cortex-m4 -g3 -c -x assembler-with-cpp -MMD -MP -MF"Startup/startup_stm32f303cctx.d" -MT"Startup/startup_stm32f303cctx.o" --specs=nano.specs -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb -o "Startup/startup_stm32f303cctx.o" "../Startup/startup_stm32f303cctx.s"
arm-none-eabi-gcc "../Src/main.c" -mcpu=cortex-m4 -std=gnu11 -g3 -DSTM32 -DSTM32F303xC -DSTM32F3 -DSTM32F303CCTx -DDEBUG -c -I../Inc -I../Drivers/CMSIS/Device/ST/STM32F3xx/Include -I../Drivers/CMSIS/Include -O0 -ffunction-sections -fdata-sections -Wall -fstack-usage -MMD -MP -MF"Src/main.d" -MT"Src/main.o" --specs=nano.specs -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb -o "Src/main.o"
arm-none-eabi-gcc "../Src/syscalls.c" -mcpu=cortex-m4 -std=gnu11 -g3 -DSTM32 -DSTM32F303xC -DSTM32F3 -DSTM32F303CCTx -DDEBUG -c -I../Inc -I../Drivers/CMSIS/Device/ST/STM32F3xx/Include -I../Drivers/CMSIS/Include -O0 -ffunction-sections -fdata-sections -Wall -fstack-usage -MMD -MP -MF"Src/syscalls.d" -MT"Src/syscalls.o" --specs=nano.specs -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb -o "Src/syscalls.o"
arm-none-eabi-gcc "../Src/sysmem.c" -mcpu=cortex-m4 -std=gnu11 -g3 -DSTM32 -DSTM32F303xC -DSTM32F3 -DSTM32F303CCTx -DDEBUG -c -I../Inc -I../Drivers/CMSIS/Device/ST/STM32F3xx/Include -I../Drivers/CMSIS/Include -O0 -ffunction-sections -fdata-sections -Wall -fstack-usage -MMD -MP -MF"Src/sysmem.d" -MT"Src/sysmem.o" --specs=nano.specs -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb -o "Src/sysmem.o"
arm-none-eabi-gcc "../Drivers/CMSIS/Device/ST/STM32F3xx/system_stm32f3xx.c" -mcpu=cortex-m4 -std=gnu11 -g3 -DSTM32 -DSTM32F303xC -DSTM32F3 -DSTM32F303CCTx -DDEBUG -c -I../Inc -I../Drivers/CMSIS/Device/ST/STM32F3xx/Include -I../Drivers/CMSIS/Include -O0 -ffunction-sections -fdata-sections -Wall -fstack-usage -MMD -MP -MF"Drivers/CMSIS/Device/ST/STM32F3xx/system_stm32f3xx.d" -MT"Drivers/CMSIS/Device/ST/STM32F3xx/system_stm32f3xx.o" --specs=nano.specs -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb -o "Drivers/CMSIS/Device/ST/STM32F3xx/system_stm32f3xx.o"
../Src/main.c:10:4: warning: #warning "FPU is not initialized, but the project is compiling for an FPU. Please initialize the FPU before use." [-Wcpp]
 10 | #warning "FPU is not initialized, but the project is compiling for an FPU. Please initialize the FPU before use."
 | ^~~~~~~

So I am wondering where these defines are hidden, but it seems very difficult to locate them. Digging deeper, I found the CMSIS specific "core_cm4.h" file, which has the following code:

#elif defined ( __GNUC__ )
 #if defined (__VFP_FP__) && !defined(__SOFTFP__)
 #if defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)
 #define __FPU_USED 1U

__FPU_PRESENT is defined in a file called "stm32f303xc.h":

#define __CM4_REV 0x0001U /*!< Core revision r0p1 */
#define __MPU_PRESENT 1U /*!< STM32F303xC devices provide an MPU */
#define __NVIC_PRIO_BITS 4U /*!< STM32F303xC devices use 4 Bits for the Priority Levels */
#define __Vendor_SysTickConfig 0U /*!< Set to 1 if different SysTick Config is used */
#define __FPU_PRESENT 1U /*!< STM32F303xC devices provide an FPU */

But it leaves me with the unknown __VFP_FP__ and __SOFTFP__ defines, which I cannot seem to find :\

I believe I went through all possible header and CMSIS files, but cannot seem to find the relevant defines. Is there anything magic happening behind the scenes that I am not aware of?

PS: I am using GNU GCC as a compiler/toolchain.

Thank you,

This topic has been closed for replies.

5 replies

KnarfB
Super User
November 28, 2021

Those are gcc built-in defines which depend on the machine/arch/... options you are using. You can show them by preprocessing an empty file and dumping the output to stdout like:

arm-none-eabi-gcc.exe -mcpu=cortex-m4 -dM -E - < /dev/null

Replace /dev/null by NUL for Windows.

hth

KnarfB

AAnth.1
AAnth.1Author
Senior
November 29, 2021

Thank you, that is some very interesting information. I didn't know that before.

That basically leaves me with the two missing defines from the main code:

#if !defined(__SOFT_FP__) && defined(__ARM_FP)
 #warning "FPU is not initialized, but the project is compiling for an FPU. Please initialize the FPU before use."
#endif

__SOFT_FP_ and __ARM_FP

Any idea what's the background story or relevance of that? To me, it appears that __SOFT_FP__ and __ARM_FP are nowhere defined and have little to none relevance in the code. Either just ignoring the warning during compilation, or just deleting the above code from my project.

Would you agree?

Thank you,

KnarfB
Super User
November 29, 2021

Hmm. Just generated STM32CubeMX code for STM32F302RB Nucleo board (the closest match I own). There is not such #if ... block generated in my main.c or anywhere else in the project.

The rationale is, that the FPU needs initialization before the first FPU instruction is executed. This is handled in SystemInit(); in system_stm32f3xx.c:

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
...

Don't know how that is mapped to the macros. If the FPU init code is present, you could probably ignore that warning.