first post, perplexed by printf()

Freddie Chopin freddie_chopin@op.pl
Fri Oct 3 07:13:00 GMT 2014


On 10/03/2014 05:42 AM, Dave McGuire wrote:
> If I do printf("%d\n", 1); everything works fine.  If I do
> printf("%d\n", 10);, my processor hangs.  (again with no debugging
> support just yet, I don't know where)  In other words, as soon as I try
> to format an integer with more than one digit, it hangs.  I can add
> characters to the format string, and it works.  I've given it ever more
> stack, no change. (I'm aware of printf()'s appetite for memory)

Before digging any further set stack to 4kB (or 2kB at least). Second 
thing - make sure your stack is 8-byte aligned (this shouldn't be a 
problem for printf()ing ints, but its better to be safe).

You could also try one of my example ARM projects, take the one for 
Cortex-M3 (like the one for STM32F4) and just do these two things:
- disable any hardware-specific calls in main() - setting the PLL, 
GPIOs, ...,
- adjust the sizes and addresses of memories in the linker script to 
match your chip (you can also increase the stack size).

Then download the "syscalls" package, drop the source file into the main 
folder of the example and at this point printf() MUST work. To make it 
actually print anything, you'd also need to add your "retargetting" code...

Did you build the toolchain yourself or are you using some precompiled 
one? Have you tried your code with the "official" one - 
https://launchpad.net/gcc-arm-embedded or maybe with my own compilation 
- bleeding-edge-toolchain - http://sourceforge.net/projects/bleeding-edge/

Regards,
FCh



More information about the Newlib mailing list