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

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

Post Reply
Torbik
Posts: 2
Joined: Tue Nov 05, 2013 12:15 pm

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

Post 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?
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

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

Post 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
Torbik
Posts: 2
Joined: Tue Nov 05, 2013 12:15 pm

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

Post 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?
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

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

Post 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
Post Reply