cancel
Showing results for 
Search instead for 
Did you mean: 

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

FStra.9
Associate III
 
6 REPLIES 6
FStra.9
Associate III

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

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.

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
Associate III

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.

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
Up vote any posts that you find helpful, it shows what's working..