cancel
Showing results for 
Search instead for 
Did you mean: 

Possible bug formatting floating point numbers in STM32CubeIDE

rrnicolay
Associate II

I'm facing a problem trying to format floating point numbers in STM32CubeIDE. The uC is STM32F103. I've checked the "use newlib-nano to print floating numbers" in the project settings.

To narrow things down, I used the following code snippet to reproduce the error:

char strP[100];
uint16_t cx = 0;
cx = snprintf(strP, 100, "%6.2f, %6.2f, %6.2f, %6.2f", 0.0115697104, -0.0796313286, -0.0220388453, -0.111881733);

The error doesn't appear on every iteration of the example code. It works most of the time, actually. When it fails, it prints:

26815634999686289245754584189029181710324847797922429453525901675501503951146118153956426275383940846635237101275691881352391832390627762028461487571337216.00,  0.00, -0.00,  0.00"

Or:

0.00 2.00 0.00 2.00

Things I tried to fix the problem:

  • Increased the stack from 0x400 to 0x500 through STM32CubeIDE interface.
  • Changed the linker scripts like told in this link.

I'm sending some floating point numbers to the uart to plot inclinometer data on a PC. This issue is annoying me for some days. Any help would be appreciated. Thanks!

20 REPLIES 20
rrnicolay
Associate II

@Sebastian​ I moved a long way to solve this one.

Firstly, I switched from baremetal to FreeRTOS.

After that, the app was crashing while printing floating point numbers. To solve that one, check this topic.