Page 1 of 1

STM32M4 FPU isn't initialized while start in crt0.c

Posted: Tue Nov 05, 2013 12:30 pm
by Torbik
Hello,

I tried to use FPU on STM32F4 (OS v 2.6.1) and I've got exception while context switching (while try to vpush {s16-s31}).
I've found CORTEX_USE_FPU is set to TRUE in os/ports/GCC/ARMCMx/chcore_v7m.h:

Code: Select all

#define CORTEX_USE_FPU                  CORTEX_HAS_FPU

CORTEX_HAS_FPU is TRUE in os/ports/GCC/ARMCMx/STM32F4xx/cmparams.h:

Code: Select all

#define CORTEX_HAS_FPU          TRUE

But os/ports/GCC/ARMCMx/crt0.c doesn't include any headers (except for stdint.h), so CORTEX_HAS_FPU is undefined and FPU initialization is skipped:

Code: Select all

#if CORTEX_USE_FPU
  /* Initializing the FPU context save in lazy mode.*/
  SCB_FPCCR = FPCCR_ASPEN | FPCCR_LSPEN;

  /* CP10 and CP11 set to full access.*/
  SCB_CPACR |= 0x00F00000;

  /* FPSCR and FPDSCR initially zero.*/
  reg = 0;
  asm volatile ("vmsr    FPSCR, %0" : : "r" (reg) : "memory");
  SCB_FPDSCR = reg;

  /* CPU mode initialization, enforced FPCA bit.*/
  reg = CRT0_CONTROL_INIT | 4;
#else
  /* CPU mode initialization.*/
  reg = CRT0_CONTROL_INIT;
#endif


When I defined CORTEX_HAS_FPU globally in Eclipse then it works fine.

Is it mistake?

Re: STM32M4 FPU isn't initialized while start in crt0.c

Posted: Tue Nov 05, 2013 12:33 pm
by Giovanni
Hi,

It is not a mistake, it is defined in the Makefile usually, if you use another build system then you have to define the macro there.

Giovanni

Re: STM32M4 FPU isn't initialized while start in crt0.c

Posted: Tue Nov 05, 2013 12:36 pm
by Torbik
Thanks for the quick answer!
But if it must be defined in makefile why is it defined also in chcore_v7m.h/cmparams.h?

Re: STM32M4 FPU isn't initialized while start in crt0.c

Posted: Tue Nov 05, 2013 2:13 pm
by Giovanni
It is just a default in case that it is not externally defined, crt0.c does not share the same default because it cannot include a port file for architectural reasons.

Giovanni