How to replace printf?

665 views
Skip to first unread message

Jakob Engblom

unread,
Jun 4, 2009, 6:41:39 AM6/4/09
to CoreMark
Another question on how to configure coremark. If we run on a platform
that does not support a Linux-style complex environment with stdio.h,
printf, etc., you should clearly set PRINTF and HAS_STDIO defines in
core_portme.h to 0.

But what does the code do then? I cannot find any mention in the code
of an alternative output method, nor any requirements to provide any
such.

A typical platform would have a CPU, memory, and a simple serial port
(it would be simulated). Thus, it would typically support a simple
character-by-character output model, and the coremark program could
not rely on any libraries to implement it.

The existing "simple/core_portme.h" has PRINTF set to 1, which is a
bit strange for a simple platform.

Best regards

Jakob Engblom
Technical Marketing Manager
Virtutech, Sweden

Shay (Ella's Father)

unread,
Jun 4, 2009, 12:40:56 PM6/4/09
to CoreMark
Hello Jakob,

All prints are done by calling ee_printf. If you do not have printf,
you need to implement something that can print.
Just as an example if you have sprintf.
ee_printf(char *fmt, ...) {
char buf[128];
va_start( args, fmt );
vsprintf(buf, fmt, args );
va_end( args );
while (*buf) uart_send_character(*buf);
}

It seems like most embedded kits actually include support for printf.
Printf at the end of the day resolves to a putc call, which can easily
be implemented via UART.
Could you give details of the compiler you are using and settings?
Perhaps you simply need to implement the putc() call to get printf
support for your platform?

Thanks,
- Shay

Jakob Engblom

unread,
Jun 5, 2009, 10:08:31 AM6/5/09
to CoreMark
> All prints are done by calling ee_printf. If you do not have printf,
> you need to implement something that can print.

OK. I hoped you would have done that.

> Just as an example if you have sprintf.
> ee_printf(char *fmt, ...) {
>        char buf[128];
>         va_start( args, fmt );
>        vsprintf(buf, fmt, args );
>        va_end( args );
>        while (*buf) uart_send_character(*buf);
>
> }

Assuming you can pull in sprintf without getting into library
headaches.

> It seems like most embedded kits actually include support for printf.
> Printf at the end of the day resolves to a putc call, which can easily
> be implemented via UART.
> Could you give details of the compiler you are using and settings?

The CodeSourcery G++ Lite for Power Architecture/Linux, which I have
little idea on how to extend to include a custom putc() for a bare-
metal simulated target. I use this compiler with no C includes at all
for my bare-metal targets usually, so I just wanted to understand the
landscape.

> Perhaps you simply need to implement the putc() call to get printf
> support for your platform?

That might well be the case, but it was good to know about ee_printf,
which I was looking for in the source code.

/jakob

Shay (Ella's Father)

unread,
Jun 5, 2009, 1:46:10 PM6/5/09
to CoreMark
Hello Jakob,

The intention for CoreMark was to make it as simple as possible.
I will added PORT_DIR that will not require any library, but will not
work as is - you will need to actually implement a method to send char
to uart and a method to measure time.
Let me know if this helps you.
The new PORT_DIR name is barebones. There is no modification to any
other file.

Thanks,
- Shay

Shay (Ella's Father)

unread,
Jun 5, 2009, 1:54:40 PM6/5/09
to CoreMark
A little more clarification - the new port dir includes a file that
has an implementation of vsprintf so you do not need to pull in a
library for that.
When you try to compile with PORT_DIR=barebones, you will see compiler
errors for the functions that you MUST implement.

To use a cross compiler, try to edit the file core_portme.mak, and
perhaps compile with SEPARATE_COMPILE=1.

Thanks,
- Shay

Jakob Engblom

unread,
Jun 8, 2009, 3:54:04 PM6/8/09
to Shay (Ella's Father), CoreMark
> A little more clarification - the new port dir includes a file that
> has an implementation of vsprintf so you do not need to pull in a
> library for that.
> When you try to compile with PORT_DIR=barebones, you will see compiler
> errors for the functions that you MUST implement.
>
> To use a cross compiler, try to edit the file core_portme.mak, and
> perhaps compile with SEPARATE_COMPILE=1.
>

I think that sounds excellent!

Best regards,

/jakob

_______________________________________________________

Jakob Engblom, PhD, Technical Marketing Manager

Virtutech                   Direct: +46 8 690 07 47   
Drottningholmsvägen 22      Mobile: +46 709 242 646  
11243 Stockholm             Web:    www.virtutech.com 
Sweden
________________________________________________________
 
Also http://jakob.engbloms.se

Reply all
Reply to author
Forward
0 new messages