This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

__FPU_USED not set despite FPU compiler & linker flags

My setup: Eclipse, nrf52832 on a custom target board, s132, SDK13

I am trying to implement the workaround for the problem described here:

https://devzone.nordicsemi.com/f/nordic-q-a/15243/high-power-consumption-when-using-fpu#post-id-87847

However, when I compile the project, __FPU_USED is defined as 0, so that section of code is not compiled.  If I look up where __FPU_USED is defined, I find this in core_cm4.h:

#elif defined ( __GNUC__ )
  #if defined (__VFP_FP__) && !defined(__SOFTFP__)
    #if (__FPU_PRESENT == 1U)
      #define __FPU_USED       1U
    #else
      #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
      #define __FPU_USED       0U
    #endif
  #else
    #define __FPU_USED         0U
  #endif

In that block of code, __GNUC__ is defined, but __VFP_FP__ is not.  My understanding is that __VFP_FP__ should be defined by the compiler, based on some flags that are set in my make file:

CFLAGS += -DARM_MATH_CM4
CFLAGS += -mcpu=cortex-m4
CFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16

...

ASMFLAGS += -DARM_MATH_CM4

...

LDFLAGS += -mcpu=cortex-m4
LDFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16

However, __VFP_FP__ is not defined, and so __FPU_USED is not defined as 1.  Is there another step I am missing here?

  • Do you get any warnings or errors in the build log or is it just Eclipse that shows is as undefined (ie greyed out in the text editor)?  Please add the check below at the beginning of main() and see if you get the "FPU is not used" warning when you re-build the project. I suspect the problem is with the Eclipse code analyzer, possibly using the wrong compiler flags.  

    #if __FPU_USED == 0)
          #warning "FPU is not used"
    #endif

  • There were no warnings associated with that code in the build log, it's only Eclipse showing __VFP_FP as undefined (greyed out).

    When I added your code snippet to my main(), I did not get the compiler warning, which would indicate that you are correct, and that Eclipse is not recognizing the compiler flags.  Just to make sure, I also changed it to:
    #if (__FPU_USED == 1)
    And it *did* show the warning, which means that the compiler is using it correctly.

    Thank you for your help!

Related