Skip to main content
LCE
Principal II
July 24, 2026
Solved

FPU: CubeIDE setting overrides register SCB->CPACR

  • July 24, 2026
  • 6 replies
  • 101 views

Heyho,

just played with / checked the FPU on a G431.

I found that the CubeIDE setting overrides the enable via register SCB->CPACR.

So, if source code sets FPU on, but IDE says FPU off, the FPU is off.

That a bug or a feature?

Best answer by waclawek.jan

> if source code sets FPU on

How?

> but IDE says FPU off, the FPU is off

How do you know FPU is off?

 

I don’t use CubeIDE, but my guess would be, that any “FPU on/off” tickbox results in preprocessor symbols being defined/not defined, probably through command-line -Dxxx switch, which are then used in SystemInit()

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

so if your code changes that before SystemInit is called, it will be overriden.

Or not. I don’t Cube.

JW

6 replies

mƎALLEm
ST Technical Moderator
July 24, 2026

So if it’s a question on CubeIDE, that must be asked in STM32CubeIDE.

I’m moving the post then.

To give better visibility on the answered topics, please click "Best answer" on the reply which solved your issue or answered your question.
TDK
July 24, 2026

That’s not how it works. The IDE can set some things up but once the source code is running it controls things. Recheck your assumptions.

"If you feel a post has answered your question, please click ""Accept as Solution""."
LCE
LCEAuthor
Principal II
July 27, 2026

Okay, let’s rephrase it:

something changes it, probably the compiler ?

waclawek.jan
waclawek.janBest answer
Super User
July 24, 2026

> if source code sets FPU on

How?

> but IDE says FPU off, the FPU is off

How do you know FPU is off?

 

I don’t use CubeIDE, but my guess would be, that any “FPU on/off” tickbox results in preprocessor symbols being defined/not defined, probably through command-line -Dxxx switch, which are then used in SystemInit()

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

so if your code changes that before SystemInit is called, it will be overriden.

Or not. I don’t Cube.

JW

LCE
LCEAuthor
Principal II
July 27, 2026

Ouch, feeling stooopid once more…

I copied exactly the above lines including the preprocessor #if, without having checked where the __FPU defines come from. I assumed wrongly that these were set in some *.h file.

Ouch, ouch, ouch, ...

LCE
LCEAuthor
Principal II
July 27, 2026

BTW, I checked by setting up a timer running with CPU clock and checked the timer ticks.

That showed pretty clearly if FPU was on or not, a division taking about 10 times more cycles without the FPU.

case '/':
case ':':
{
__disable_irq();
TIM6->CNT = 0;
if( flValY != 0.0f ) flResult = flValX / flValY;
else u32Error = 1;
__ISB();
u32TimStop = TimTestGetCnt();
__enable_irq();
break;
}