# Forum: ARM programming with GCC/GNU tools Printf and serial port

 Author: Giuseppe M. (xardomain) Posted on: 2008-04-22 12:54

Rate this post
 0 ▲ useful ▼ not useful
Hi all,
just bought a Xylo-LM FPGA board with a LPC2138 onboard. I have a very
simple question, I use Yagarto/Eclipse/OpenOCD etc. etc I don't know how
to get the printf messages out.
which is supposed to be the default sdtout for them? Is it a serial port
and is it configurable?

TIA,

Giuseppe Marullo

 Author: Martin T. (mthomas) (Moderator) Posted on: 2008-04-22 17:50

Rate this post
 0 ▲ useful ▼ not useful
Giuseppe Marullo wrote:
> Hi all,
> just bought a Xylo-LM FPGA board with a LPC2138 onboard. I have a very
> simple question, I use Yagarto/Eclipse/OpenOCD etc. etc I don't know how
> to get the printf messages out.
Yagarto includes the newlib which offer stdio-functions like printf (and
the smaller variant iprintf). You have to "bind" the stdio-system with
the serial-port and provide some low-level functions for initialize and
send characters to the UART. It may be easier to avoid stdio and use
simple functions like uart1_puts() to output characters. For real stdio
the newlib needs some hardware-interface-functions (syscalls, some kind
of simpel BIOS). You may use the ready-made newlib-lpc or create your
own simple set of syscalls.

> which is supposed to be the default sdtout for them?
There is no default since this depends on the used lower-level
interface. See the newlib libc.pdf.

> Is it a serial port and is it configurable?
Not by default, it can be "anything". Configuration and usage depends on
the interface-layer between newlib-stdio-functions and the LPC2138
hardware.

 Author: Giuseppe M. (xardomain) Posted on: 2008-04-22 19:00

Rate this post
 0 ▲ useful ▼ not useful
Martin Thomas wrote:
> Giuseppe Marullo wrote:
>> Hi all,
>> just bought a Xylo-LM FPGA board with a LPC2138 onboard. I have a very
>> simple question, I use Yagarto/Eclipse/OpenOCD etc. etc I don't know how
>> to get the printf messages out.
> Yagarto includes the newlib which offer stdio-functions like printf (and
> the smaller variant iprintf). You have to "bind" the stdio-system with
> the serial-port and provide some low-level functions for initialize and
> send characters to the UART. It may be easier to avoid stdio and use
> simple functions like uart1_puts() to output characters. For real stdio
> the newlib needs some hardware-interface-functions (syscalls, some kind
> of simpel BIOS). You may use the ready-made newlib-lpc or create your
> own simple set of syscalls.
>
>> which is supposed to be the default sdtout for them?
> There is no default since this depends on the used lower-level
> interface. See the newlib libc.pdf.
>
>> Is it a serial port and is it configurable?
> Not by default, it can be "anything". Configuration and usage depends on
> the interface-layer between newlib-stdio-functions and the LPC2138
> hardware.

I was thinking it was a newbie thing. I will take a look at the docs.

Thanks,

Giuseppe

 Author: Javier R. (fjrg76) Posted on: 2008-04-24 01:55

Rate this post
 0 ▲ useful ▼ not useful
Giuseppe Marullo wrote:
> Martin Thomas wrote:
>> Giuseppe Marullo wrote:
>>> Hi all,
>>> just bought a Xylo-LM FPGA board with a LPC2138 onboard. I have a very
>>> simple question, I use Yagarto/Eclipse/OpenOCD etc. etc I don't know how
>>> to get the printf messages out.
>> Yagarto includes the newlib which offer stdio-functions like printf (and
>> the smaller variant iprintf). You have to "bind" the stdio-system with
>> the serial-port and provide some low-level functions for initialize and
>> send characters to the UART. It may be easier to avoid stdio and use
>> simple functions like uart1_puts() to output characters. For real stdio
>> the newlib needs some hardware-interface-functions (syscalls, some kind
>> of simpel BIOS). You may use the ready-made newlib-lpc or create your
>> own simple set of syscalls.
>>
>>> which is supposed to be the default sdtout for them?
>> There is no default since this depends on the used lower-level
>> interface. See the newlib libc.pdf.
>>
>>> Is it a serial port and is it configurable?
>> Not by default, it can be "anything". Configuration and usage depends on
>> the interface-layer between newlib-stdio-functions and the LPC2138
>> hardware.
>
> I was thinking it was a newbie thing. I will take a look at the docs.
>
> Thanks,
>
> Giuseppe

Hi!!

This works for me:

int __putchar(int ch){
if (ch == '\n')
UARTWriteChar('\r');
UARTWriteChar(ch);
}

__putchar() is a function that send out single characteres to whatever
you want, in my case to a serial port, and this is used as a primitive
by functions like printf(), puts(), etc.

Just add it to your source code and write inside the code to do
something with the characteres (serial port, LCD, usb, etc)

 Author: Martin T. (mthomas) (Moderator) Posted on: 2008-04-25 15:31

Rate this post
 0 ▲ useful ▼ not useful
> This works for me:
>
> int __putchar(int ch){

What toolchain/toolset/package are you using?

 Author: Javier R. (fjrg76) Posted on: 2008-04-29 00:12

Rate this post
 0 ▲ useful ▼ not useful
Martin Thomas wrote:
>> This works for me:
>>
>> int __putchar(int ch){
>
> What toolchain/toolset/package are you using?

Hi!!

I'm using CrossWorks 1.5. There's must something similar for the GNU
toolchain (e.g. winarm) and, for 8 bits, the CodeWarrior for HCS08 has
functions alike

 Author: Giuseppe M. (xardomain) Posted on: 2008-08-15 00:10

Rate this post
 0 ▲ useful ▼ not useful
Javier Rod wrote:
> Martin Thomas wrote:
>>> This works for me:
>>>
>>> int __putchar(int ch){
>>
>> What toolchain/toolset/package are you using?
>
> Hi!!
>
> I'm using CrossWorks 1.5. There's must something similar for the GNU
> toolchain (e.g. winarm) and, for 8 bits, the CodeWarrior for HCS08 has
> functions alike

Hi all, sorry for the extreme delay.

>This works for me:
I tried to understand where to redefine a similar function but failed.
At this point is not even clear to me if yagarto already uses newlib-lpc
or simply newlib.

AFAIK, newlib-lpc does not use _putchar etc. so this is not the right
way to do it, there should be something line write function or so.

Actually, I tried to use this much simpler demo of iprintf/printf, that
should do the trick (from a Martin Thomas page):
http://www.siwawi.arubi.uni-kl.de/avr_projects/arm_projects/#gcc_stdio

If I understand correctly, this will implment a simple iprintf/printf on
a uart using a subset of the newlib-lpc (basically newlib-lpc is not
needed).

Initially, I was not able to build in Eclipse, just on command line.
Actually, I am able to build (I have imported the whole directory into a
new project), but not yet tested with the real hw (that is a LPC2138 and
not a LPC2129).

Giuseppe

 Author: Martin T. (mthomas) (Moderator) Posted on: 2008-08-16 10:17

Rate this post
 0 ▲ useful ▼ not useful
Giuseppe Marullo wrote:
> Javier Rod wrote:
>> Martin Thomas wrote:
>>>> This works for me:
>>>>
>>>> int __putchar(int ch){
>>>
>>> What toolchain/toolset/package are you using?
>>
>> Hi!!
>>
>> I'm using CrossWorks 1.5. There's must something similar for the GNU
>> toolchain (e.g. winarm) and, for 8 bits, the CodeWarrior for HCS08 has
>> functions alike
>
> Hi all, sorry for the extreme delay.
>
>>This works for me:
> I tried to understand where to redefine a similar function but failed.
> At this point is not even clear to me if yagarto already uses newlib-lpc
> or simply newlib.

As far as I know newlib-lpc is not included in Yagarto. I have in
included it in WinARM. But you could build the library yourself. The
source is available (google for newlib-lpc). newlib-lpc is not a
replacement for the newlib. It's just a implementation of the syscalls
for the "real" newlib and some additional utility-code for most (older)
LPC2000.

> AFAIK, newlib-lpc does not use _putchar etc. so this is not the right
> way to do it, there should be something line write function or so.

newlib-lpc provides syscalls, everything else comes from newlib. See the
libc.pdf from newlib.

> Actually, I tried to use this much simpler demo of iprintf/printf, that
> should do the trick (from a Martin Thomas page):
> http://www.siwawi.arubi.uni-kl.de/avr_projects/arm_projects/#gcc_stdio
>
> If I understand correctly, this will implment a simple iprintf/printf on
> a uart using a subset of the newlib-lpc (basically newlib-lpc is not
> needed).

It implements some syscalls. Yes, I have used the newlib-lpc code to
learn how this can be done.

 Author: Giuseppe M. (xardomain) Posted on: 2008-08-18 01:20

Rate this post
 0 ▲ useful ▼ not useful
Martin,

> As far as I know newlib-lpc is not included in Yagarto. I have in
> included it in WinARM. But you could build the library yourself. The
Ok, I am testing with my board but without luck. I am able to build the
project but (I guess) since I have a .ld for the LPC2129 need to have it
I am not able to debug it.

I took the file from another sample on your pages
(http://www.siwawi.arubi.uni-kl.de/avr_projects/arm_projects/lpc2138_mcb2130_freeRTOSdemo_20060519.zip).
I have changed:

SUBMDL   = LPC2138
into Makefile but it gives me these errors:

**** Build of configuration Default for project p ****

...

arm-elf-gcc -mthumb -mcpu=arm7tdmi-s -mthumb-interwork -I. -gdwarf-2
-DROM_RUN -D__WinARM__  -Os -Wall -Wcast-align -Wimplicit
-Wl,-Map=ADC.map,--cref -lc  -lm -lc -lgcc     -T./LPC2138-ROM.ld
crt0.o: In function abort':
C:\data\eclipse\p/crt0.S:216: undefined reference to _stack'
C:\data\eclipse\p/crt0.S:216: undefined reference to __bss_start'
C:\data\eclipse\p/crt0.S:216: undefined reference to _etext'
C:\data\eclipse\p/crt0.S:216: undefined reference to _data'
C:\data\eclipse\p/crt0.S:216: undefined reference to _edata'
C:\data\eclipse\p/crt0.S:216: undefined reference to __ctors_start__'
C:\data\eclipse\p/crt0.S:216: undefined reference to __ctors_end__'
collect2: ld returned 1 exit status

I guess I may need a different crt.S lpc2138 specific (I was not able to
locate another one, beside the one provided with the board but seems to
use different names so I dubt it would do).

> source is available (google for newlib-lpc). newlib-lpc is not a
> replacement for the newlib. It's just a implementation of the syscalls
> for the "real" newlib and some additional utility-code for most (older)
> LPC2000.

It is far beyond my skills to compile it at the moment, I don't even
know where to start

> It implements some syscalls. Yes, I have used the newlib-lpc code to
> learn how this can be done.

Any chance you could do it for the lpc2138 too? :)

Giuseppe

• $formula (LaTeX syntax)$