Electronic – Atmel printf formatting doesn’t work, no formatting does work

atmelavravr-gcccembedded

We are running an Atmel AVR32 chip on our board, and recently discovered that printf with format/conversion specifiers doesn't work. A regular printf does work.

For instance,

printf("hello\n"); // works just fine
printf("number: %d\n", 12); // returns -1, nothing prints.

No format specifiers seem to have any effect, printf just returns -1.

We have tried linking in different versions of the vfprintf family of functions, e.g. adding -Wl,-u,vfprintf -lprintf_flt -lm to add floating point format capabilities (documented here), but to no effect.

Note that we are NOT looking for floating point capabilities, we are just trying to get ANY formatting for a regular decimal (int, uint_8, etc.).

Any help greatly appreciated.

Best Answer

Have you tried creating a character buffer, formatting it, and then printing it?

   char buffer [50];
   int A = 12;
   i = sprintf (buffer, "A: %d \n", A);

   printf(buffer);

Also, try initializing the variable first, then include it inside the printf.

   int A = 12; 
   printf("number: %d \n", A);