Skip to main content
IVent.1
Senior
March 20, 2023
Question

Why printf doesn't work?

  • March 20, 2023
  • 7 replies
  • 2504 views

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.

This topic has been closed for replies.

7 replies

ONadr.1
Senior III
March 20, 2023

Do you enabled float output in CubeIDE?

Tesla DeLorean
Guru
March 20, 2023

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 VenmoUp vote any posts that you find helpful, it shows what's working..
IVent.1
IVent.1Author
Senior
March 20, 2023

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
March 20, 2023

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

ONadr.1
Senior III
March 20, 2023

0693W00000aJKsFQAW.png

IVent.1
IVent.1Author
Senior
March 20, 2023

Attached my compiler configuration.

IVent.1
IVent.1Author
Senior
March 20, 2023

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?

Piranha
Principal III
March 22, 2023

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