EmbeddedRelated.com
Forums
Memfault Beyond the Launch

Printf statement used on IAR compiler / MSP430 processor

Started by JS October 4, 2007
This is a multi-part message in MIME format.

------=_NextPart_000_01D7_01C80657.F2583E90
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

I have been looking for a code sample written by IAR compiler
for TI  MSP430 processor  especially when utilizing PRINTF statement
for the purpose of transmitting/receiving  characters serially to/from =
PC terminal program .
i.e  "Hello world"    for instance.

I have searched TI website but there was no luck.

Thanks in advance,


JIMMY
------=_NextPart_000_01D7_01C80657.F2583E90
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.6000.16481" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>I have been looking for a code sample =
written by=20
IAR compiler</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>for TI&nbsp; MSP430 processor&nbsp; =
especially when=20
utilizing PRINTF statement</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>for the purpose of =
transmitting/receiving=20
&nbsp;characters serially to/from PC terminal program .</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>i.e&nbsp; "Hello =
world"&nbsp;&nbsp;&nbsp; for=20
instance.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I have searched TI website but there =
was no=20
luck.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Thanks in advance,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>JIMMY</FONT></DIV></BODY></HTML>

------=_NextPart_000_01D7_01C80657.F2583E90--

JS wrote:

> for TI MSP430 processor especially when utilizing PRINTF statement > for the purpose of transmitting/receiving characters serially to/from PC terminal program .
This has no meaning. printf by definition prints to stdout, which is the console. There is no console on an MSP430 unless you put together an operating system that defines what a console is, and provides an I/ O driver to talk to one. You can certainly write a serial I/O driver and use sprintf to format strings that you then send with that driver. Some compiler vendors by default have printf communicate with the debugger to show a virtual console in the debug window. I believe IAR does this. But it is not "serial to PC terminal program".
Sure, it does make sense.  I come from the ARM world utilizing KEIL IDE 
tool.
We have done something like this all the time.
I am looking for IAR equivalent of the following:

int main (void)
  {

    configure_pll_clk();
    config_uarts(); 
//setup UART port
    EIC_IRQConfig(ENABLE);                                  // Configure ALL 
IRQ's
   GPIO_Config(GPIO2, 0xff00, GPIO_OUT_PP);
    printf("\n\rARM PROCESSOR TEST PROGRAM\n");
    printf("\rCompiled: %s %s\r\n", __DATE__, __TIME__);  ///DATE + TIME 
displayed on PC termninal
   lcd_initialize();                           //initialize  LCD
 }

The printf statements above would send the character to PC terminal program 
via RS232 interface.
Hardware must consist of the followings:
1.     2 pins ( RX and TX)
2.     RS232 translator chip ..i.e    MAX232   or equivalent
3.    9-pin D connector to be connected to PC serial port.
4.    RS232 cable



Thanks,


JIMMY


"larwe" <zwsdotcom@gmail.com> wrote in message 
news:1191502775.457465.202750@50g2000hsm.googlegroups.com...
> > JS wrote: > >> for TI MSP430 processor especially when utilizing PRINTF statement >> for the purpose of transmitting/receiving characters serially to/from PC >> terminal program . > > This has no meaning. printf by definition prints to stdout, which is > the console. There is no console on an MSP430 unless you put together > an operating system that defines what a console is, and provides an I/ > O driver to talk to one. You can certainly write a serial I/O driver > and use sprintf to format strings that you then send with that driver. > > Some compiler vendors by default have printf communicate with the > debugger to show a virtual console in the debug window. I believe IAR > does this. But it is not "serial to PC terminal program". >
On Oct 4, 9:25 am, "JS" <x...@yahoo.com> wrote:

> The printf statements above would send the character to PC terminal program > via RS232 interface.
So Keil includes a library that directs printf output to a serial port. That is a proprietary feature, where Keil has arbitrarily defined a serial port to be the console. In effect they have made an OS decision for you. It is not standard printf behavior, and IAR's library does not (to the best of my knowledge) do it this way. Certainly the default behavior is to connect to the proprietary debug console.
JS wrote:
> I have been looking for a code sample written by IAR compiler > for TI MSP430 processor especially when utilizing PRINTF statement > for the purpose of transmitting/receiving characters serially to/from PC terminal program . > i.e "Hello world" for instance. > > I have searched TI website but there was no luck. >
This isn't a TI problem but an IAR one. Look through the stdio.h and anything referenced on by that, to find out what they've defined printf as. Often you'll find it's something like "_printf( _print_char(),...)" and that _print_char() is just a stub in the library. Adding something like "#define _print_char(c) uart0_out(c)" to your project header or whatever will then get you your output.
On 2007-10-04, larwe <zwsdotcom@gmail.com> wrote:

>> for TI MSP430 processor especially when utilizing PRINTF >> statement for the purpose of transmitting/receiving characters >> serially to/from PC terminal program . > > This has no meaning. printf by definition prints to stdout, which is > the console. There is no console on an MSP430 unless you put together > an operating system that defines what a console is, and provides an I/ > O driver to talk to one. You can certainly write a serial I/O driver > and use sprintf to format strings that you then send with that driver.
IIRC, the IAR libc expects the user to provide a putchar function of some sort for printf to use. The OP should check his compiler's manual. -- Grant Edwards grante Yow! LOOK!! Sullen at American teens wearing visi.com MADRAS shorts and "Flock of Seagulls" HAIRCUTS!
On Oct 4, 10:47 am, Grant Edwards <gra...@visi.com> wrote:

> IIRC, the IAR libc expects the user to provide a putchar > function of some sort for printf to use. The OP should
Huh. On the ez430 at least I thought it defaulted to debugger output. But I so rarely use printf in any form, on a tiny system like that!
On 2007-10-04, larwe <zwsdotcom@gmail.com> wrote:
> On Oct 4, 10:47 am, Grant Edwards <gra...@visi.com> wrote: > >> IIRC, the IAR libc expects the user to provide a putchar >> function of some sort for printf to use. The OP should > > Huh. On the ez430 at least I thought it defaulted to debugger output.
You could be right. I might be remembering the wrong compiler. The compiler's manual would know for sure.
> But I so rarely use printf in any form, on a tiny system like > that!
printf isn't too useful On the ones with 2K of codespace and 128-256 bytes of RAM. On ones with 60KB of codespace and 4K of RAM, it can be very useful. Since I rarely have a spare HW UART, I ususally bit-bang the printf output. I also use a carefully optimized, custom printf function that's only a couple KB of code and requires very little RAM. -- Grant Edwards grante Yow! A shapely CATHOLIC at SCHOOLGIRL is FIDGETING visi.com inside my costume..
"Grant Edwards" <grante@visi.com> wrote in message 
news:13g9v8cbount8e5@corp.supernews.com...
> On 2007-10-04, larwe <zwsdotcom@gmail.com> wrote: > >>> for TI MSP430 processor especially when utilizing PRINTF >>> statement for the purpose of transmitting/receiving characters >>> serially to/from PC terminal program . >> >> This has no meaning. printf by definition prints to stdout, which is >> the console. There is no console on an MSP430 unless you put together >> an operating system that defines what a console is, and provides an >> I/ >> O driver to talk to one. You can certainly write a serial I/O driver >> and use sprintf to format strings that you then send with that >> driver. > > IIRC, the IAR libc expects the user to provide a putchar > function of some sort for printf to use. The OP should check > his compiler's manual.
This is fairly standard stuff (providing a stub for a putchar, usually implemented with a serial port send). Certainly the IAR compiler (and its more recent replacements) for the H8 does this, and I'm sure I've seen this on other compilers too. So the OP is basically asking for a serial port support routine. My answer: read the UART section(s) of the manual(s). It ain't hard - and if you do find it hard, consider it an ideal learning exercise for embedded CPU work. (Hint: an interrupt-driven circular FIFO is a good way to do this, but for starting out just poll the port...) Steve http://www.fivetrees.com
One of the basic example which I think it is quite useful is
for instance if you want to find out what the output pins
of  PORT1  are at certain point in the program --- that way
you don't have to physically put the scope probe on them.

void read_port_value(void)
{
   uchar value;
   value = PORT1;       //read  CPU port1
   printf(" Display Port1 value = %X", value);      //Display port1 in hex 
on PC terminal
}



> > printf isn't too useful On the ones with 2K of codespace and > 128-256 bytes of RAM. On ones with 60KB of codespace and 4K of > RAM, it can be very useful. Since I rarely have a spare HW > UART, I ususally bit-bang the printf output. I also use a > carefully optimized, custom printf function that's only a > couple KB of code and requires very little RAM. >

Memfault Beyond the Launch