5 Replies Latest reply on Mar 14, 2014 12:57 AM by nikvh

    How to use HW FPU on STM32F4xx?

      What do I need to do to get the tool chain to build for the HW FPU on the STM32F4xx?



        • 1. Re: How to use HW FPU on STM32F4xx?

          Broadcom Team,


          Does the WICED toolchain have M4 FPU support?? Are the lib's compiled for it?


          I am building with the following flags:

          CPU_CFLAGS := -mthumb -mcpu=cortex-m4 -mfloat-abi=softfp -mfpu=vfpv4


          Building with these options does create "vmla", "vcvt" and other floating-point instructions. However, I incur a hard fault immediately. Building with "-mfloat-abi=hard" yields incompatible libc.a build errors.


          Are we wasting our time here, or is FPU support really included?

          • 2. Re: How to use HW FPU on STM32F4xx?

            Information from this site http://stackoverflow.com/questions/18772848/fpu-in-stm32f4-processors indicates that you must enable the FPU on the STM32F4 prior to using floating point instructions.

            Currently the STM32F4xx platform files do not initialize the FPU automatically however you should ideally add the instruction that enables the FPU in the STM32f4xx init_architecture() function.

            We appreciate the time you've spent investigating this and we hope we can work together to get this working.

            • 3. Re: How to use HW FPU on STM32F4xx?

              Hi Nikvh,


              We are enabling the FPU explicitly in init_architecture(), just before the watchdog is initiated. The exact line is:


                   /* set CP10 and CP11 Full Access */

                  SCB->CPACR |= ((3UL << 10*2)|(3UL << 11*2));

              • 4. Re: How to use HW FPU on STM32F4xx?

                The entire build flags I am using are:

                CPU_CFLAGS     := -mthumb -mcpu=cortex-m4 -mfloat-abi=softfp -mfpu=vfpv4

                CPU_CXXFLAGS   := -mthumb -mcpu=cortex-m4

                CPU_ASMFLAGS   := -mcpu=cortex-m4

                CPU_LDFLAGS    := -mthumb -mcpu=cortex-m4

                If I try building =hard, the lib errors follow:

                wiced-sdk/tools/arm_gnu/bin/win32/arm-none-eabi-ld.exe: error: build/waf_bootloader-NoOS-NoNS-IHM-SDIO/Binary/waf_bootloader-NoOS-NoNS-IHM-SDIO.elf uses VFP register arguments, c:/users/risleym/desktop/ihm/ptolemy/wiced-sdk/tools/arm_gnu/bin/win32/../../lib/thumb/v7m\libc.a(lib_a-errno.o) does not

                I wanted to find the specific instruction that was causing this hard fault, so I followed the steps in this guide:


                Executing this left me with a program counter of 0x800FECA, which lies within _tx_thread_system_return() here:

                0x0800fec0: mrs r0, PRIMASK

                0x0800fec4: push {r0}

                0x0800fec6: cpsie i

                0x0800fec8: svc 0

                0x0800feca:   nop

                0x0800fecc: pop {r0}

                0x0800fece: msr PRIMASK, r0

                Program Status Register: 0x41000248

                Link Register: 0x800E899

                I also find that this occurs prior to any floating point operations. I hope this information is valuable, please let me know your thoughts & any direction I can take this in.

                • 5. Re: How to use HW FPU on STM32F4xx?

                  Thank you for your detailed analysis and the wealth of information.

                  We are working on building a new libc library with the additional CFLAGS.