cancel
Showing results for 
Search instead for 
Did you mean: 

Why printf doesn't work?

IVent.1
Senior

I have some problems with printf function.

For example,

float valf=0;

printf("%.0f",valf)

The result is

f

I don't understand...I thought that the native printf worked...

The option

Use float with printf is flagged.

Thank you.

8 REPLIES 8
ONadr.1
Senior III

Do you enabled float output in CubeIDE?

Make sure you've provided suitable plumbing code to a UART you have configured and enabled.

I​n STs GNU/GCC implementation via __io_putchar and called from write()

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
IVent.1
Senior

If I write, for example,

printf("TEST %.0f",valf)

the result is

TEST f

if I put the breakpoint in my uart function, the string pointed is "TEST f"

I have no problems with integer...

this for example works correctly

TRACE(("ENDLOG%.2d%.2d%.2d%.2d%.2d%.2d.%d",g_DATEDAY,g_DATEMONTH,g_DATEYEAR,g_TIMEHOURS,g_TIMEMINUTES,g_TIMESECONDS,g_TIMEmSECONDS));

the result is:

ENDLOG010323142500.1

ONadr.1
Senior III

In your IDE, compiler configuration, check icon "nano printf" for float variables.

ONadr.1
Senior III

0693W00000aJKsFQAW.png

IVent.1
Senior

Attached my compiler configuration.

IVent.1
Senior

The problem was a writing in flash (I'm using a nucleo-board). How to know the part of the flash you can write to?

Learn how the flash memories work and read the reference manual.