2019-06-06 12:25 AM
No matter what I try, something as simple as printf("%f\n", 0.0) or printf("%f\n, 3.14159265359 for some reason produces a text string representing a negative, extremely long and seemingly random number.
Opening project-settings on C/C++ Build -> Settings -> Tools Settings there is a checkbox with the text "Use float with printf from newlib-nano (-u _printf_float)", but enabling that doesn't change anything. Also, Eclipse still keeps complaining that there is no float-support (-u _printf_float), even though the flag is clearly visible on the command-line when compiling a project -- seemingly the only way of getting Eclipse to stop complaining is to manually add the flag to linker-settings. Doesn't fix printf, though.
This is on the STM32CubeIde 1.0.0 and a STM32F103CBT6 -- no, there is no H/W-float. I'm left wondering if this is a bug or if I'm missing something. I mean, the checkbox is pretty clear and one would assume that it does what it says, but....
(Disclaimer: this isn't an issue for me, per se, as I have a workaround for printing floats. I'm merely curious and if this were an actual bug and not just me doing things wrong again, it probably should be fixed.)
Solved! Go to Solution.
2019-06-06 12:34 AM
Yes, this is a known issue. _estack in linker script is not set properly. You may have _estack in 0x2004ffff (odd alignment anyway) and please change it to 0x20050000 (by word alignment). There were couple of discussions on this topic in previous threads.
Would you mind sharing your workdaround with me?
2019-06-06 12:34 AM
Yes, this is a known issue. _estack in linker script is not set properly. You may have _estack in 0x2004ffff (odd alignment anyway) and please change it to 0x20050000 (by word alignment). There were couple of discussions on this topic in previous threads.
Would you mind sharing your workdaround with me?
2019-06-06 12:44 AM
I don't think my workaround is what you were thinking; I don't fix printf, I just take a few extra steps to get the desired output. It's basically the following:
double dIntPart, dFractPart;
dFractPart = modf(insertYourFloatHere, &dIntPart);
printf("Printing float with two decimals: %d.%d\n", (int)dIntPart, (int)(dFractPart * 105.0f));