Skip to main content
Associate
November 25, 2024
Solved

The float formatting support is not enabled

  • November 25, 2024
  • 2 replies
  • 2587 views

Hello All,

I am getting this error while compiling the project " The float formatting support is not enabled ".

I have checked use float with "printf from new lib-nano" in MCU/MPU settings save and recompile the problem didn't go!!

I have added manually "-u_printf_float" in MCU/MPU GCC linker with no success.

I am using the latest version of stm32cubeide 1.16.1 the MCU is stm32g031f6p6.

my code in while loop:

 

HAL_ADC_Start(&hadc1);

HAL_ADC_PollForConversion(&hadc1, 20);

voltage = (HAL_ADC_GetValue(&hadc1)/4096) * 3.3f;

printf("Voltage = %0.2f\n", voltage);

HAL_Delay(1000);

 

Best answer by MM..1

Your error isnt about float. You compile bigger code as flash... try change optimize level or better not use float.

2 replies

MM..1
MM..1Best answer
Chief III
November 25, 2024

Your error isnt about float. You compile bigger code as flash... try change optimize level or better not use float.

FahdAuthor
Associate
November 26, 2024

Thanks after changing optimizition level it works. Ididn't know float take so much space.

Ozone
Principal
November 26, 2024

The STM32Gxx MCUs are Cortex M0/M0+.
They have no FPU, and thus no floating point instructions.
Everything needs to be emulated. 
If not absolutely necessary, avoid float - even float constants.

  voltage = (HAL_ADC_GetValue(&hadc1)/4096) * 3.3f;
  printf("Voltage = %0.2f\n", voltage);

Things like this can easily be done with scaled integer maths.
The resulting code is an order of magnitude smaller.

NEdom.1
Associate III
November 26, 2024

Use printf in C/C++ very carefully in embedded software. The printf family functions could be very dirty in memory access and bloated in code size.