EmbeddedRelated.com
Forums
Memfault State of IoT Report

Simple printf() example?

Started by Douglas March 10, 2010
I am a long time PIC user but a 430 newbie. For some quick debugging I want to use printf(). The IAR Kickstart compiler takes my code without errors or warnings but there is no output. I can put bytes in UCA0TXBUF and they get transmitted fine. I think I need to tell the compiler which serial interface to use for STDOUT, but how? I am using a MSP430F2274.

Can someone point me to a simple example of how to use printf() with IAR?

Thanks,
SherpaDoug

Beginning Microcontrollers with the MSP430

Douglas wrote:
> I am a long time PIC user but a 430 newbie. For some quick debugging I want to use printf(). The IAR Kickstart compiler takes my code without errors or warnings but there is no output. I can put bytes in UCA0TXBUF and they get transmitted fine. I think I need to tell the compiler which serial interface to use for STDOUT, but how? I am using a MSP430F2274.
>
> Can someone point me to a simple example of how to use printf() with IAR?
>
I believe printf is a plain old lib call. It doesn't inherently know
where to send the data because it doesn't know what your hardware output
is all about. I think it is putc( ) that you have to supply code for. I
don't use printf so can't be sure why you didn't get a linker error.

Found this:


Best, Dan.

You can use the sprintf() and send data out manually.

-----Mensagem original-----
De: m... [mailto:m...] Em nome de Dan
Bloomquist
Enviada em: quarta-feira, 10 de mar de 2010 20:57
Para: m...
Assunto: Re: [msp430] Simple printf() example?

Douglas wrote:
> I am a long time PIC user but a 430 newbie. For some quick debugging I
want to use printf(). The IAR Kickstart compiler takes my code without
errors or warnings but there is no output. I can put bytes in UCA0TXBUF and
they get transmitted fine. I think I need to tell the compiler which serial
interface to use for STDOUT, but how? I am using a MSP430F2274.
>
> Can someone point me to a simple example of how to use printf() with IAR?
>
I believe printf is a plain old lib call. It doesn't inherently know
where to send the data because it doesn't know what your hardware output
is all about. I think it is putc( ) that you have to supply code for. I
don't use printf so can't be sure why you didn't get a linker error.

Found this:


Best, Dan.

Delfos wrote:
> You can use the sprintf() and send data out manually.
>

Yes, and I've done that too. But way back when, I recall overriding
something like putc, (putchar?), which is one step less than buffer and
send. Buffer and send when doing roll your own printf, I'd say.

On the use of an output for debugging, I don't really see the gain with
a device that you can actually emulate in silicon.. The debugger is so
vastly full of info as you develop. I never got how arduino got so
popular but for the cheap/easy entry; and that it is really c++. But to
debug seems to only be through creating outputs from your code. So
archaic. And maybe why I don't see much more than 'hello world' with leds.

I have not looked at PIC in some time, but I thought they had real JTAG
tools. (Maybe I'm thinking of the wrong chip.) Or that you had to move
to PICXXX > to get it?(Now I'm recalling atmel does, PIC does not?)

But Douglas, that you can be part of the chip instead of an outsider,
don't use your old paradigm to develop; use the debugger!

Here is the kind of stuff I used an extra output for:


The fuzz is the difference between the IR/Vis detection, (the AC
component). But this one is on the shelf for awhile...

Best, Dan.

Douglas wrote:
> I am a long time PIC user but a 430 newbie. For some quick debugging I
> want to use printf(). The IAR Kickstart compiler takes my code without
> errors or warnings but there is no output. I can put bytes in UCA0TXBUF
> and they get transmitted fine. I think I need to tell the compiler which
> serial interface to use for STDOUT, but how? I am using a MSP430F2274.
>
> Can someone point me to a simple example of how to use printf() with IAR?

Hi Douglas!

It should be quite straight-forward to override the low-level function
to perform the output using any device.

The only thing that complicates the matter is that we supply two
different runtime environments, and each of them has its own way of
performing the low-level output.

------

In the DLib runtime environment, you should override the function
__write(). This function supports sending data to a number of files
(where 0, 1, and 2 corresponds to "stdin", "stdout", and "stderr").
Also, it supports emitting a whole buffer.

/*
* When buf is NULL the handle should be flushed. When the handle is -1
then
* all open handles should be flushed.
*/

size_t __write(int handle, const unsigned char *buf, size_t size)
{
/* DO WHATEVER YOU WANT HERE */
}

-----

In the legacy CLib runtime-environment, you should override __putchar, e.g.

int __putchar(int ch)
{
/* SEND IT TO SOMEBODY */
return ch;
}

For more information on the matter, please see the manual, and the
example source files provided with the product.

-- Anders Lindgren, IAR Systems
--
Disclaimer: Opinions expressed in this posting are strictly my own and
not necessarily those of my employer.

Here is a flow to say "Hello world".

1.include
2.Copy the two functions to your code.

// low level character function to support the printf() command
void __low_level_put(int c)
{
while ((IFG2 & UTXIFG0) != UTXIFG0);
UCA0TXBUF=c;
}

int putchar(int c)
{
if (c == '\n') /* Convert EOL to CR/LF */
__low_level_put('\r');
__low_level_put(c);
return c;
}
3.The printf funcion could be used.

--- In m..., "Douglas" wrote:
>
> I am a long time PIC user but a 430 newbie. For some quick debugging I want to use printf(). The IAR Kickstart compiler takes my code without errors or warnings but there is no output. I can put bytes in UCA0TXBUF and they get transmitted fine. I think I need to tell the compiler which serial interface to use for STDOUT, but how? I am using a MSP430F2274.
>
> Can someone point me to a simple example of how to use printf() with IAR?
>
> Thanks,
> SherpaDoug
>

Thanks to all who replied. niri12002's code worked, once I found a typo: UTXIFG0 => UCA0TXIFG.

I am mostly an analog guy. My part of this project is from the sensor, through signal conditioning, the A/D (at the right time), and ploping data into RAM. Then the software guy takes the data and applies mysterious multi-layered wireless protocols, flings it through the ether and it ends up in Labview on somebody's desk.

To make sure my little bit works I find it easiest to send the A/D counts to a UART. Then I get not just the value, but also the timing of when the value arrives.

SherpaDoug

--- In m..., "nlri12002" wrote:
>
> Here is a flow to say "Hello world".
>
> 1.include
> 2.Copy the two functions to your code.
>
> // low level character function to support the printf() command
> void __low_level_put(int c)
> {
> while ((IFG2 & UTXIFG0) != UTXIFG0);
--- typo: UTXIFG0 should be UCA0TXIFG ---
> UCA0TXBUF=c;
> }
>
> int putchar(int c)
> {
> if (c == '\n') /* Convert EOL to CR/LF */
> __low_level_put('\r');
> __low_level_put(c);
> return c;
> }
> 3.The printf funcion could be used.
>
> --- In m..., "Douglas" wrote:
> >
> > I am a long time PIC user but a 430 newbie. For some quick debugging I want to use printf(). The IAR Kickstart compiler takes my code without errors or warnings but there is no output. I can put bytes in UCA0TXBUF and they get transmitted fine. I think I need to tell the compiler which serial interface to use for STDOUT, but how? I am using a MSP430F2274.
> >
> > Can someone point me to a simple example of how to use printf() with IAR?
> >
> > Thanks,
> > SherpaDoug
>

Ahhh, LabVIEW. This developer's first choice for years, when the task
at hand is grabbing stuff that's been flung to the ether.

;-)

David J. Boyd

Senior Test Engineer

Home Respiratory Care

Home Healthcare Solutions

Philips Healthcare

175 Chastain Meadows Court NW

Kennesaw GA USA 30144-3724

Office: 770-429-2809

d...@philips.com

From: m... [mailto:m...] On Behalf
Of Douglas
Sent: Thursday, March 11, 2010 10:07
To: m...
Subject: [msp430] Re: Simple printf() example?

Thanks to all who replied. niri12002's code worked, once I found a typo:
UTXIFG0 => UCA0TXIFG.

I am mostly an analog guy. My part of this project is from the sensor,
through signal conditioning, the A/D (at the right time), and ploping
data into RAM. Then the software guy takes the data and applies
mysterious multi-layered wireless protocols, flings it through the ether
and it ends up in Labview on somebody's desk.

To make sure my little bit works I find it easiest to send the A/D
counts to a UART. Then I get not just the value, but also the timing of
when the value arrives.

SherpaDoug

--- In m... ,
"nlri12002" wrote:
>
> Here is a flow to say "Hello world".
>
> 1.include
> 2.Copy the two functions to your code.
>
> // low level character function to support the printf() command
> void __low_level_put(int c)
> {
> while ((IFG2 & UTXIFG0) != UTXIFG0);
--- typo: UTXIFG0 should be UCA0TXIFG ---
> UCA0TXBUF=c;
> }
>
> int putchar(int c)
> {
> if (c == '\n') /* Convert EOL to CR/LF */
> __low_level_put('\r');
> __low_level_put(c);
> return c;
> }
> 3.The printf funcion could be used.
>
> --- In m... ,
"Douglas" wrote:
> >
> > I am a long time PIC user but a 430 newbie. For some quick debugging
I want to use printf(). The IAR Kickstart compiler takes my code without
errors or warnings but there is no output. I can put bytes in UCA0TXBUF
and they get transmitted fine. I think I need to tell the compiler which
serial interface to use for STDOUT, but how? I am using a MSP430F2274.
> >
> > Can someone point me to a simple example of how to use printf() with
IAR?
> >
> > Thanks,
> > SherpaDoug
>
=======================================================================The information contained in this message may be confidential and legally protected under applicable law. The message is intended solely for the addressee(s). If you are not the intended recipient, you are hereby notified that any use, forwarding, dissemination, or reproduction of this message is strictly prohibited and may be unlawful. If you are not the intended recipient, please contact the sender by return e-mail and destroy all copies of the original message.



Memfault State of IoT Report