3

For STM32F407 Discovery board how do I enable its FPU from CubeMX?

The following instruction is used in handwritten code. How can I get it generated from CubeMX?

// Enable FPU SCB->CPACR |= 0xf00000;

ajeebx
  • 165
  • 1
  • 8
  • Not an expert, IMO the compiler/linker has to make a code that will use embedded instructions of the FPU. – Marko Buršič Apr 12 '19 at 09:27
  • 2
    @MarkoBuršič that is true, however that the generated code runs, the FPU has to get enabled somewhere. Usually the compiler won't do that on its own. So usually one of the very first instructions in the startup code is to enable the FPU because it might get used by the constructors or initialization of floating point variables which crashes without enabling the FPU. (But I have no experience with CubeMX, so I can't answer the question) – Arsenal Apr 12 '19 at 11:59

1 Answers1

2

Perhaps the CubeMX is missing this feature and it should add some code in SystemInit.

This is from Keil forum:

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

Somewhere in the compiler/linker you should enable the flags FPU_PRESENT and FPU_USED.

Marko Buršič
  • 23,562
  • 2
  • 20
  • 33