EmbeddedRelated.com
Forums

Okay, now crossworks question

Started by Micah March 31, 2006
Thanks everyone for the feedback on the terminal programs.

New problem with crossworks. I'm trying to redefine __putchar() to send 
out the SPI port, instead of to the virtual terminal. So according to 
the instructions, I should just be able to redirect the linker to use my 
function instead of the __putchar() function, right? I did this:

-D___putchar=_my_putchar

in the additional linker options. This should utilize my_putchar() 
instead of the standard one, right? However, when I compile, I get a 
duplicate __printchar error now.

Any ideas? Is there a better way to do this?

-Micah

Beginning Microcontrollers with the MSP430

Hello Micah,

Simply use the __putchar() function with the same prototype as in the library,
and
your own __putchar() code will be linked in, instead of the Library code.

You _must_ use the same prototype to have your own function linked in ie.

int __putchar (int);

If you're using SPI, just return the parameter you were called with :

int __putchar (int spi_data)
{
	//.... do your SPI stuff
 return (spi_data);
}

If there's an error you can elect to return EOF or IOW (-1)


B rgds
Kris


-----Original Message-----
From: msp430@msp4... [mailto:msp430@msp4...] On Behalf Of Micah
Sent: Saturday, 1 April 2006 9:25 AM
To: msp430@msp4...
Subject: [msp430] Okay, now crossworks question

Thanks everyone for the feedback on the terminal programs.

New problem with crossworks. I'm trying to redefine __putchar() to send 
out the SPI port, instead of to the virtual terminal. So according to 
the instructions, I should just be able to redirect the linker to use my 
function instead of the __putchar() function, right? I did this:

-D___putchar=_my_putchar

in the additional linker options. This should utilize my_putchar() 
instead of the standard one, right? However, when I compile, I get a 
duplicate __printchar error now.

Any ideas? Is there a better way to do this?

-Micah


.

 
Yahoo! Groups Links



 




Oh, also note that once you have directed low level stdout to your SPI
with __putchar(), that you can eg. use this :

printf ("Now I'm sending on my SPI port");

and the whole stdio.h family.

-- Kris

-----Original Message-----
From: msp430@msp4... [mailto:msp430@msp4...] On Behalf Of Microbit
Sent: Saturday, 1 April 2006 9:56 AM
To: msp430@msp4...
Subject: RE: [msp430] Okay, now crossworks question

Hello Micah,

Simply use the __putchar() function with the same prototype as in the library,
and
your own __putchar() code will be linked in, instead of the Library code.

You _must_ use the same prototype to have your own function linked in ie.

int __putchar (int);

If you're using SPI, just return the parameter you were called with :

int __putchar (int spi_data)
{
	//.... do your SPI stuff
 return (spi_data);
}

If there's an error you can elect to return EOF or IOW (-1)


B rgds
Kris


-----Original Message-----
From: msp430@msp4... [mailto:msp430@msp4...] On Behalf Of Micah
Sent: Saturday, 1 April 2006 9:25 AM
To: msp430@msp4...
Subject: [msp430] Okay, now crossworks question

Thanks everyone for the feedback on the terminal programs.

New problem with crossworks. I'm trying to redefine __putchar() to send 
out the SPI port, instead of to the virtual terminal. So according to 
the instructions, I should just be able to redirect the linker to use my 
function instead of the __putchar() function, right? I did this:

-D___putchar=_my_putchar

in the additional linker options. This should utilize my_putchar() 
instead of the standard one, right? However, when I compile, I get a 
duplicate __printchar error now.

Any ideas? Is there a better way to do this?

-Micah


.

 
Yahoo! Groups Links



 





.

 
Yahoo! Groups Links



 




On Fri, Mar 31, 2006 at 02:25:08PM -0800, Micah wrote:
> New problem with crossworks. I'm trying to
redefine __putchar() to send 
> out the SPI port, instead of to the virtual terminal. So according to 
> the instructions, I should just be able to redirect the linker to use my 
> function instead of the __putchar() function, right?

Micah,

What I have done to implement my own low level serial routine was to define
two functions, __putchar() and _putchar().  The first function here is the
one that Crossworks printf() function makes calls to:

void __putchar(int c)
{
#ifdef SERIAL_PORT
	_putchar(c);
#endif // SERIAL_PORT
#ifdef RADIO_PORT
	rf_send(c);
#endif // RADIO_PORT
}

Crossworks will use your __putchar() routine above if it exists, instead of
its own.

The second function is the actual low-level serial output routine that gets
called by the one above:

void _putchar(int c)
{
	...bleh
}

I did not define anything else, nor did I have to add any linker switches.
It just _works_. :)

Take care,
-Chris

-- 
 /> Christopher Cole                         <\                          
<\
<<  Cole Design and Development               \\  email: cole@cole...   \\
 \\ Computer Networking & Embedded Electronics \\ web: http://coledd.com   
>>
  \>                                            \>                        
</

Still not working.

Okay, so I added this function to common.c:

int __putchar (int spi_data)
{
    if (spi_data == '\n')
    spi_data = 0x0a;
  WRITE_TX_BUF2 (spi_data & 0xff);
  WAIT_SPI_FREE2;
 
 return (spi_data);
}

And this to common.h:

int __putchar (int);

and included <stdio.h> in common.c and main.c. And I still get the 
duplicate __putchar error.

What's up?

-Micah


Microbit wrote:

>Hello Micah,
>
>Simply use the __putchar() function with the same prototype as in the
library, and
>your own __putchar() code will be linked in, instead of the Library code.
>
>You _must_ use the same prototype to have your own function linked in ie.
>
>int __putchar (int);
>
>If you're using SPI, just return the parameter you were called with :
>
>int __putchar (int spi_data)
>{
>	//.... do your SPI stuff
> return (spi_data);
>}
>
>If there's an error you can elect to return EOF or IOW (-1)
>
>
>B rgds
>Kris
>
>
>-----Original Message-----
>From: msp430@msp4... [mailto:msp430@msp4...] On Behalf Of Micah
>Sent: Saturday, 1 April 2006 9:25 AM
>To: msp430@msp4...
>Subject: [msp430] Okay, now crossworks question
>
>Thanks everyone for the feedback on the terminal programs.
>
>New problem with crossworks. I'm trying to redefine __putchar() to send

>out the SPI port, instead of to the virtual terminal. So according to 
>the instructions, I should just be able to redirect the linker to use my 
>function instead of the __putchar() function, right? I did this:
>
>-D___putchar=_my_putchar
>
>in the additional linker options. This should utilize my_putchar() 
>instead of the standard one, right? However, when I compile, I get a 
>duplicate __printchar error now.
>
>Any ideas? Is there a better way to do this?
>
>-Micah
>
>
>.
>
> 
>Yahoo! Groups Links
>
>
>
> 
>
>
>
>
>
>.
>
> 
>Yahoo! Groups Links
>
>
>
> 
>
>
>  
>


Huh ?
Weird that this works, you MUST match the prototype (or should have to) :
int __putchar (int);

I'll try this next time I'm on MSP430, I'm coding on ARM for the
moment.

-- Kris

-----Original Message-----
From: msp430@msp4... [mailto:msp430@msp4...] On Behalf Of Christopher Cole
Sent: Saturday, 1 April 2006 10:05 AM
To: msp430@msp4...
Subject: Re: [msp430] Okay, now crossworks question

On Fri, Mar 31, 2006 at 02:25:08PM -0800, Micah wrote:
> New problem with crossworks. I'm trying to redefine __putchar() to
send 
> out the SPI port, instead of to the virtual terminal. So according to 
> the instructions, I should just be able to redirect the linker to use my 
> function instead of the __putchar() function, right?

Micah,

What I have done to implement my own low level serial routine was to define
two functions, __putchar() and _putchar().  The first function here is the
one that Crossworks printf() function makes calls to:

void __putchar(int c)
{
#ifdef SERIAL_PORT
	_putchar(c);
#endif // SERIAL_PORT
#ifdef RADIO_PORT
	rf_send(c);
#endif // RADIO_PORT
}

Crossworks will use your __putchar() routine above if it exists, instead of
its own.

The second function is the actual low-level serial output routine that gets
called by the one above:

void _putchar(int c)
{
	...bleh
}

I did not define anything else, nor did I have to add any linker switches.
It just _works_. :)

Take care,
-Chris

-- 
 /> Christopher Cole                         <\                          
<\
<<  Cole Design and Development               \\  email: cole@cole...   \\
 \\ Computer Networking & Embedded Electronics \\ web: http://coledd.com   
>>
  \>                                            \>                        
</


.

 
Yahoo! Groups Links



 




Have you included the crossworks IO header file :

#include <__cross_studio_io.h>

???

-- Kris


-----Original Message-----
From: msp430@msp4... [mailto:msp430@msp4...] On Behalf Of Micah
Sent: Saturday, 1 April 2006 10:10 AM
To: msp430@msp4...
Subject: Re: [msp430] Okay, now crossworks question


Still not working.

Okay, so I added this function to common.c:

int __putchar (int spi_data)
{
    if (spi_data == '\n')
    spi_data = 0x0a;
  WRITE_TX_BUF2 (spi_data & 0xff);
  WAIT_SPI_FREE2;
 
 return (spi_data);
}

And this to common.h:

int __putchar (int);

and included <stdio.h> in common.c and main.c. And I still get the 
duplicate __putchar error.

What's up?

-Micah


Microbit wrote:

>Hello Micah,
>
>Simply use the __putchar() function with the same prototype as in the
library, and
>your own __putchar() code will be linked in, instead of the Library code.
>
>You _must_ use the same prototype to have your own function linked in ie.
>
>int __putchar (int);
>
>If you're using SPI, just return the parameter you were called with :
>
>int __putchar (int spi_data)
>{
>	//.... do your SPI stuff
> return (spi_data);
>}
>
>If there's an error you can elect to return EOF or IOW (-1)
>
>
>B rgds
>Kris
>
>
>-----Original Message-----
>From: msp430@msp4... [mailto:msp430@msp4...] On Behalf Of Micah
>Sent: Saturday, 1 April 2006 9:25 AM
>To: msp430@msp4...
>Subject: [msp430] Okay, now crossworks question
>
>Thanks everyone for the feedback on the terminal programs.
>
>New problem with crossworks. I'm trying to redefine __putchar() to send

>out the SPI port, instead of to the virtual terminal. So according to 
>the instructions, I should just be able to redirect the linker to use my 
>function instead of the __putchar() function, right? I did this:
>
>-D___putchar=_my_putchar
>
>in the additional linker options. This should utilize my_putchar() 
>instead of the standard one, right? However, when I compile, I get a 
>duplicate __printchar error now.
>
>Any ideas? Is there a better way to do this?
>
>-Micah
>
>
>.
>
> 
>Yahoo! Groups Links
>
>
>
> 
>
>
>
>
>
>.
>
> 
>Yahoo! Groups Links
>
>
>
> 
>
>
>  
>



.

 
Yahoo! Groups Links



 




Yep, in main.c and common.c.


-Micah

Microbit wrote:

>Have you included the crossworks IO header file :
>
>#include <__cross_studio_io.h>
>
>???
>
>-- Kris
>
>
>-----Original Message-----
>From: msp430@msp4... [mailto:msp430@msp4...] On Behalf Of Micah
>Sent: Saturday, 1 April 2006 10:10 AM
>To: msp430@msp4...
>Subject: Re: [msp430] Okay, now crossworks question
>
>
>Still not working.
>
>Okay, so I added this function to common.c:
>
>int __putchar (int spi_data)
>{
>    if (spi_data == '\n')
>    spi_data = 0x0a;
>  WRITE_TX_BUF2 (spi_data & 0xff);
>  WAIT_SPI_FREE2;
> 
> return (spi_data);
>}
>
>And this to common.h:
>
>int __putchar (int);
>
>and included <stdio.h> in common.c and main.c. And I still get the 
>duplicate __putchar error.
>
>What's up?
>
>-Micah
>
>
>Microbit wrote:
>
>  
>
>>Hello Micah,
>>
>>Simply use the __putchar() function with the same prototype as in the
library, and
>>your own __putchar() code will be linked in, instead of the Library
code.
>>
>>You _must_ use the same prototype to have your own function linked in
ie.
>>
>>int __putchar (int);
>>
>>If you're using SPI, just return the parameter you were called with
:
>>
>>int __putchar (int spi_data)
>>{
>>	//.... do your SPI stuff
>>return (spi_data);
>>}
>>
>>If there's an error you can elect to return EOF or IOW (-1)
>>
>>
>>B rgds
>>Kris
>>
>>
>>-----Original Message-----
>>From: msp430@msp4... [mailto:msp430@msp4...] On Behalf Of Micah
>>Sent: Saturday, 1 April 2006 9:25 AM
>>To: msp430@msp4...
>>Subject: [msp430] Okay, now crossworks question
>>
>>Thanks everyone for the feedback on the terminal programs.
>>
>>New problem with crossworks. I'm trying to redefine __putchar() to
send 
>>out the SPI port, instead of to the virtual terminal. So according to 
>>the instructions, I should just be able to redirect the linker to use my

>>function instead of the __putchar() function, right? I did this:
>>
>>-D___putchar=_my_putchar
>>
>>in the additional linker options. This should utilize my_putchar() 
>>instead of the standard one, right? However, when I compile, I get a 
>>duplicate __printchar error now.
>>
>>Any ideas? Is there a better way to do this?
>>
>>-Micah
>>
>>
>>.
>>
>>
>>Yahoo! Groups Links
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>.
>>
>>
>>Yahoo! Groups Links
>>
>>
>>
>>
>>
>>
>> 
>>
>>    
>>
>
>
>
>.
>
> 
>Yahoo! Groups Links
>
>
>
> 
>
>
>
>
>
>.
>
> 
>Yahoo! Groups Links
>
>
>
> 
>
>
>  
>


If it helps, here's the error:

C:/Program Files/Rowley Associates Limited/CrossWorks MSP430 1.3/bin/hld 
HW_debug/nRF2401_MAC.hzo HW_debug/sys_init.hzo HW_debug/mulaw.hzo 
HW_debug/pn_tables.hzo HW_debug/interrupts.hzo HW_debug/common.hzo 
HW_debug/timers.hzo HW_debug/charging.hzo HW_debug/signal.hzo 
HW_debug/led.hzo HW_debug/main.hzo HW_debug/channel.hzo 
HW_debug/sys_debug.hzo HW_debug/crt0.hzo C:/Program Files/Rowley 
Associates Limited/CrossWorks MSP430 1.3/lib/lib_vfprintf_int_hf.hza 
C:/Program Files/Rowley Associates Limited/CrossWorks MSP430 
1.3/lib/lib_vfscanf_int_hf.hza -g C:/Program Files/Rowley Associates 
Limited/CrossWorks MSP430 1.3/lib/libc_hf.hza C:/Program Files/Rowley 
Associates Limited/CrossWorks MSP430 1.3/lib/libm_hf.hza -Oph -Ofl -Odc 
-Ojt -GCODE=L -GCONST=L -TINTVECe0 -GINTVEC=L -TCODE,CONST00-ffdf 
-GINFO=L -TINFO00-10ff -DRAM_Start_AddressQ2 -DRAM_Size 48 
-T.abs=0 -G.abs=L -TIDATA0,UDATA0 0-9ff -o HW_debug/FHSS_RC1.hzx

C:/Program Files/Rowley Associates Limited/CrossWorks MSP430 
1.3/bin/hld: duplicate symbol '___putchar'

-Micah


Micah wrote:

>Yep, in main.c and common.c.
>
>
>-Micah
>
>Microbit wrote:
>
>  
>
>>Have you included the crossworks IO header file :
>>
>>#include <__cross_studio_io.h>
>>
>>???
>>
>>-- Kris
>>
>>
>>-----Original Message-----
>>From: msp430@msp4... [mailto:msp430@msp4...] On Behalf Of Micah
>>Sent: Saturday, 1 April 2006 10:10 AM
>>To: msp430@msp4...
>>Subject: Re: [msp430] Okay, now crossworks question
>>
>>
>>Still not working.
>>
>>Okay, so I added this function to common.c:
>>
>>int __putchar (int spi_data)
>>{
>>   if (spi_data == '\n')
>>   spi_data = 0x0a;
>> WRITE_TX_BUF2 (spi_data & 0xff);
>> WAIT_SPI_FREE2;
>>
>>return (spi_data);
>>}
>>
>>And this to common.h:
>>
>>int __putchar (int);
>>
>>and included <stdio.h> in common.c and main.c. And I still get the

>>duplicate __putchar error.
>>
>>What's up?
>>
>>-Micah
>>
>>
>>Microbit wrote:
>>
>> 
>>
>>    
>>
>>>Hello Micah,
>>>
>>>Simply use the __putchar() function with the same prototype as in
the library, and
>>>your own __putchar() code will be linked in, instead of the Library
code.
>>>
>>>You _must_ use the same prototype to have your own function linked
in ie.
>>>
>>>int __putchar (int);
>>>
>>>If you're using SPI, just return the parameter you were called
with :
>>>
>>>int __putchar (int spi_data)
>>>{
>>>	//.... do your SPI stuff
>>>return (spi_data);
>>>}
>>>
>>>If there's an error you can elect to return EOF or IOW (-1)
>>>
>>>
>>>B rgds
>>>Kris
>>>
>>>
>>>-----Original Message-----
>>>From: msp430@msp4... [mailto:msp430@msp4...] On Behalf Of Micah
>>>Sent: Saturday, 1 April 2006 9:25 AM
>>>To: msp430@msp4...
>>>Subject: [msp430] Okay, now crossworks question
>>>
>>>Thanks everyone for the feedback on the terminal programs.
>>>
>>>New problem with crossworks. I'm trying to redefine __putchar()
to send 
>>>out the SPI port, instead of to the virtual terminal. So according
to 
>>>the instructions, I should just be able to redirect the linker to
use my 
>>>function instead of the __putchar() function, right? I did this:
>>>
>>>-D___putchar=_my_putchar
>>>
>>>in the additional linker options. This should utilize my_putchar() 
>>>instead of the standard one, right? However, when I compile, I get a

>>>duplicate __printchar error now.
>>>
>>>Any ideas? Is there a better way to do this?
>>>
>>>-Micah
>>>
>>>
>>>.
>>>
>>>
>>>Yahoo! Groups Links
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>.
>>>
>>>
>>>Yahoo! Groups Links
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>   
>>>
>>>      
>>>
>>
>>.
>>
>>
>>Yahoo! Groups Links
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>.
>>
>>
>>Yahoo! Groups Links
>>
>>
>>
>>
>>
>>
>> 
>>
>>    
>>
>
>
>
>.
>
> 
>Yahoo! Groups Links
>
>
>
> 
>
>
>  
>


If you take over that function, you shouldn't include the crossworks
io header file,
just use the prototype in your common.h file IIRC.
It's been a while I've done this.
I'd have to dig up old code to check.

-- Kris

-----Original Message-----
From: msp430@msp4... [mailto:msp430@msp4...] On Behalf Of Micah
Sent: Saturday, 1 April 2006 10:15 AM
To: msp430@msp4...
Subject: Re: [msp430] Okay, now crossworks question


Yep, in main.c and common.c.


-Micah

Microbit wrote:

>Have you included the crossworks IO header file :
>
>#include <__cross_studio_io.h>
>
>???
>
>-- Kris
>
>
>-----Original Message-----
>From: msp430@msp4... [mailto:msp430@msp4...] On Behalf Of Micah
>Sent: Saturday, 1 April 2006 10:10 AM
>To: msp430@msp4...
>Subject: Re: [msp430] Okay, now crossworks question
>
>
>Still not working.
>
>Okay, so I added this function to common.c:
>
>int __putchar (int spi_data)
>{
>    if (spi_data == '\n')
>    spi_data = 0x0a;
>  WRITE_TX_BUF2 (spi_data & 0xff);
>  WAIT_SPI_FREE2;
> 
> return (spi_data);
>}
>
>And this to common.h:
>
>int __putchar (int);
>
>and included <stdio.h> in common.c and main.c. And I still get the 
>duplicate __putchar error.
>
>What's up?
>
>-Micah
>
>
>Microbit wrote:
>
>  
>
>>Hello Micah,
>>
>>Simply use the __putchar() function with the same prototype as in the
library, and
>>your own __putchar() code will be linked in, instead of the Library
code.
>>
>>You _must_ use the same prototype to have your own function linked in
ie.
>>
>>int __putchar (int);
>>
>>If you're using SPI, just return the parameter you were called with
:
>>
>>int __putchar (int spi_data)
>>{
>>	//.... do your SPI stuff
>>return (spi_data);
>>}
>>
>>If there's an error you can elect to return EOF or IOW (-1)
>>
>>
>>B rgds
>>Kris
>>
>>
>>-----Original Message-----
>>From: msp430@msp4... [mailto:msp430@msp4...] On Behalf Of Micah
>>Sent: Saturday, 1 April 2006 9:25 AM
>>To: msp430@msp4...
>>Subject: [msp430] Okay, now crossworks question
>>
>>Thanks everyone for the feedback on the terminal programs.
>>
>>New problem with crossworks. I'm trying to redefine __putchar() to
send 
>>out the SPI port, instead of to the virtual terminal. So according to 
>>the instructions, I should just be able to redirect the linker to use my

>>function instead of the __putchar() function, right? I did this:
>>
>>-D___putchar=_my_putchar
>>
>>in the additional linker options. This should utilize my_putchar() 
>>instead of the standard one, right? However, when I compile, I get a 
>>duplicate __printchar error now.
>>
>>Any ideas? Is there a better way to do this?
>>
>>-Micah
>>
>>
>>.
>>
>>
>>Yahoo! Groups Links
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>.
>>
>>
>>Yahoo! Groups Links
>>
>>
>>
>>
>>
>>
>> 
>>
>>    
>>
>
>
>
>.
>
> 
>Yahoo! Groups Links
>
>
>
> 
>
>
>
>
>
>.
>
> 
>Yahoo! Groups Links
>
>
>
> 
>
>
>  
>



.

 
Yahoo! Groups Links