printf() is a library routine provided by keil library.
So whenever we use printf in our code I assume what it
might be doing is calls a routine which places characters
of the printf statement in the UART buffer to get it
transmitted from there.
Now in LPC2000 we have two UARTs UART0 and UART1. So the
routine called for printf must be placing characters in one
of these UART buffers. Now I dont find any method to force the
printf tatement to place characters in buffer of specific UART
of our choice.
SO I assumed keil printf statement may be using UART1 data
buffer as default. Because it works fine with UART1 but not
While testing in our code I configured UART0 to transmitte
the data and than used printf statement to send the data. Than I
connected RS232 port of the PC with UART0 of our controller and
observed that it was receiving no data at all.
But when I connected the port to UART1 it was receving garbej
data. Data was garbej because I didnt configure UART1(I assume)
Code and other configuration was same in both the cases except
connection of the PC Rs232 port with UART1 instead of
So I am Concluding that keil uses UART1 as default for printf
statments. AM I CORRECT?
Plz guide me if my conclusion is wrong and plz suggest some
to use UART0 with printf statements because I cant use UART1 in
if you want to use printf in your project you have use
retargetting and must also provide lowlevel routines for
sending / receiving one character over UART.
Please take a look at example project
C:\Keil\ARM\Boards\Keil\MCB2300\Blinky, especially file
Retarget.c, to see how retargetting is used.
Author Niraj chavda
Posted 20-Nov-2007 06:32 GMT
RE: UART - printf - keil
Thanks for all replies
I have found the solution.
Just simply create and putchar function in
your main.c file. in that function place the
data into transmitt buffer of uart0 instead of
Now wheneveer you use printf in your code printf statment will use
your putchar function rather than
library putchar function.
This way you can send data easily to PC using UART0 and printf
Suggestions comments are always invited
Author Andy Neil
Posted 20-Nov-2007 07:02 GMT
"create a putchar function in your main.c file."
Don't have it in your main.c file.
Instead, have it in its own putchar.c file.
That way, it will be easier to re-use in other projects!
Author Niraj chavda
Posted 22-Nov-2007 05:16 GMT
There is something more I would like to know
I implemented the scheme as described above but one thing I
noticed that the scheme works fine when code is compiled for thumb
i.e. compiler settings are set for generating code in thumb mode
(options for target->C->use thumb mode)
If I set this option to generate code in ARM mode than compiler is
generating an error such as
*** ERROR L104: MULTIPLE PUBLIC DEFINITIONS
MODULE: C:\KEIL\ARM\LIB\CALFP.LIB (putchar)
DEFINED: .\Obj\main.obj (main)
Is it that I cant redirect printf to use my putchar routin in ARM
mode? Can anybody put some light on it?
Acquisition of ARM Holdings plc. by SoftBank Group Corp.
We are pleased to inform you that on 5 September 2016, SoftBank Group Corp. acquired ARM Holdings Plc. ARM will continue to operate as an independent business within the SoftBank group.
Any current agreements between ARM Ltd (or other ARM group companies, as applicable) you / your company remain in effect as between the parties, and the parties will continue to be bound by and perform the obligations in such agreements. If you have any queries please direct these to ARMSoftbank-Notifications@arm.com.