LpcXpresso and Redlib vprintf() problems

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

LpcXpresso and Redlib vprintf() problems

1,743 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by micronpn on Thu Mar 27 09:39:55 MST 2014
I am testing and comparing the same project built with Redlib, Newlib and Newlib-Nano. During the tests related to stdio I found that vprintf() doesn't work as I expected if the project is compiled using Redlib.

I think to have correctly designed __sys_write to redirect the output to the UART, same redirection, with different function name, worked with the 2 newlibs (_write in their case).

Is there any trick related to it or is it a known problem?
0 Kudos
Reply
6 Replies

1,628 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by OldManVimes on Sat Mar 29 03:27:24 MST 2014
Hi support,

You are correct. I stand corrected on both issues. Thanks for the update. I've adapted my build settings and code comments accordingly.

Best regards.
0 Kudos
Reply

1,628 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by lpcxpresso-support on Fri Mar 28 05:03:37 MST 2014

Quote: OldManVimes

Note that __sys_write is not used when the pre-processor symbol CR_PRINTF_CHAR is defined (possibly only in combination with CR_INTEGER_PRINTF), so make sure you do not use that one.



__sys_write() should still be used in this case. Can you provide an example where it doesn't??



Quote:

* Note that this trick requires the -Xlinker --allow-multiple-definition
* flag when linking the binary.



You should not need this option.

Regards,
LPCXpresso Support
0 Kudos
Reply

1,628 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by lpcxpresso-support on Fri Mar 28 04:57:01 MST 2014
@micronpn.

Your project works fine here for me, using LPCXpresso 7.0.2 and running on an RDB1768 board. I see the output from the call to vprintf routine output via your _sys_write() routine to the UART in the terminal window on my PC as expected. And just to double check, I can set a breakpoint on your __sys_write(), which gets hit for each character being output.

So explain what your problem is!

Regards,
LPCXpresso Support
0 Kudos
Reply

1,628 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by micronpn on Thu Mar 27 14:27:13 MST 2014
I need to change what I said before because I made an example program that works.  I created a new project to send you; instead, the project where vprintf doesn't work was done with a previous release of LpcXpresso, today I add this feature and it doesn't work The example project is a copy and paste of the relevant parts of the project where vprintf doesn't work so... may be related to a linker file or other things because the project wasn't create using LpcXpresso 7.0.2?

Attached there is my example project that works (I put all the files needed to compile and debug instead that the library to link).
0 Kudos
Reply

1,628 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by OldManVimes on Thu Mar 27 13:08:02 MST 2014
Hi,

Here's my version that works. It may give you a hint. I use it in combination with the CR_INTEGER_PRINTF pre-processor symbol though, since I do not need floating point support for printf() and related functions.
Note that __sys_write is not used when the pre-processor symbol CR_PRINTF_CHAR is defined (possibly only in combination with CR_INTEGER_PRINTF), so make sure you do not use that one.

Note that DEBUG_CONSOLE is one of my project flags and is not related to RedLib.

/*
 * __sys_write is overridden here. It is part of the RedLib "C"
 * library and used by printf() and related functions to write
 * to some output. We send everything to the console, provided
 * that it has been enabled with DEBUG_CONSOLE.
 * Note that this trick requires the -Xlinker --allow-multiple-definition
 * flag when linking the binary.
 * If the debug console is disabled, __sys_write defaults to a
 * stub (inside the nohost RedLib library version) that does very little.
 */
#ifdef DEBUG_CONSOLE
int __sys_write(int iFileHandle, char *pcBuffer, int iLength)
{
if (iLength > 0)
{
serialChannelWrite(DEBUG_CHANNEL, (uint8_t*)pcBuffer, iLength);
if ((pcBuffer[iLength - 1] != '\r') && (pcBuffer[iLength - 1] != '\n'))
{
serialChannelWrite(DEBUG_CHANNEL, (uint8_t*)"\n\r", 2);
}
}
return (iLength);
}
#endif

0 Kudos
Reply

1,628 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by lpcxpresso-support on Thu Mar 27 12:45:36 MST 2014
It would help to get a bit more information here:

Does your vprintf() call work correctly when linking with Redlib and using standard semihosted output, rather than trying to redirect to UART?

Does your implementation of __sys_write() actually get called when you call vprintf(). ie if you set a breakpoint on your implementation, is that breakpoint hit?

Please can you tell us what MCU you are targeting and which version of LPCXpresso you are using?

And also, please zip up and post the map file from your build to take a look at.

Regards,
LPCXpresso Support
0 Kudos
Reply