Skip to main content
FStra.9
Associate III
July 7, 2019
Question

What do you need to do to get printf to format floating point numbers?

  • July 7, 2019
  • 6 replies
  • 1939 views

..

This topic has been closed for replies.

6 replies

FStra.9
FStra.9Author
Associate III
July 7, 2019

Using STM32CubeIDEwith an STM32L433RBTx micro. I've gone through all the settings and nothing helps.

It formats a string into garbage.

sprintf( strBuff, "%4.2f", (double)12.34 );

strBuff[0] = 0

strBuff[1] = 0

strBuff[2] = 0x2e (Which is correct)

strBuff[3] = 1

strBuff[4] = 0x20

FStra.9
FStra.9Author
Associate III
July 7, 2019
Thanks for the quick response.
Unfortunately, I tried changing the linker script as outlined in the link you sent and everything else I can think of, and still get the same garbage.
I'm trying to figure out how to change the library that it links with in STM32CubeIDE and haven't figured that out yet.
Ozone
Principal
July 8, 2019

You need to consult the STM32CubeIDE tutorials/documentation. Usually, this is found in the project properties.

This IDE seems relatively new, and bug prone. Consider setting up the project again, with the proper library.

FStra.9
FStra.9Author
Associate III
July 8, 2019

It turns out that the fix was to rewrite the _sbrk routine to what was outlined in the first reply. I hadn't looked at it carefully enough initially.

The original _sbrk routine assumes that you have a linear address space and the heap is below the stack always. That is not the case when you use freeRTOS and have multiple stacks that are statically created. I had to add a label to the heap end in the linker script file and follow what was done in the first reply example.

Tesla DeLorean
Guru
July 8, 2019

The sorry state of the _sbrk has been lamented before... ST still also has code generating unaligned stacks via linker scripts..

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..