Skip to main content
Hansel
Senior
January 29, 2024
Solved

STMCubeIDE: compiler doesn't create code for FPU on STM32G431

I am using STM32CubeIDE version 1.14.1 on a WIN10 machine.

The following C code

 

asm("VMUL.F32 s0, s0, s0");
volatile float xyz = 3.1415;
 xyz = xyz * 2.3;

 

disassembles to the following:

 

 79 asm("VMUL.F32 s0, s0, s0");
08000df0: vmul.f32 s0, s0, s0
 80 volatile float xyz = 3.1415;
08000df4: ldr r3, [pc, #344] ; (0x8000f50 <main+360>)
08000df6: str r3, [sp, #0]
 81 xyz = xyz * 2.3;
08000df8: ldr r0, [sp, #0]
08000dfa: bl 0x8000598 <__extendsfdf2>
08000dfe: add r3, pc, #328 ; (adr r3, 0x8000f48 <main+352>)
08000e00: ldrd r2, r3, [r3]
08000e04: bl 0x8000648 <__muldf3>
08000e08: bl 0x8000bf8 <__truncdfsf2>

 

The compiler flags are set:

Capture.JPG

and I see them also used when compiling.

The compiler used is GNU11 (ISO C11 + gnu extensions)(-std=gnu11)

When walking through the code, the debugger stops at the breakpoint for SCB->CPACK:

 

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

 

Clearly something's wrong but I am out of ideas where to search. Can someone give me a hint what's going on?

This topic has been closed for replies.
KnarfB
KnarfBBest answer
Super User
January 30, 2024

constant 2.3 is of type double. So the multiplication is for double type operands and the assignment truncates to float.Try 2.3f.

hth

KnarfB

3 replies

KnarfB
KnarfBBest answer
Super User
January 30, 2024

constant 2.3 is of type double. So the multiplication is for double type operands and the assignment truncates to float.Try 2.3f.

hth

KnarfB

Hansel
HanselAuthor
Senior
January 30, 2024

D'oh! What impact a single character can have. This did the trick. Thank you very much, Frank!

KnarfB
Super User
January 30, 2024

Yeah, that's a nuisance, especially when porting existing code. There are some compiler flags for it too, see https://stackoverflow.com/questions/32266864/make-c-floating-point-literals-float-rather-than-double, but they are compiler dependent and don't cure the root cause.

KnarfB