Printf etc

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

Printf etc

2,757 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by timexton on Wed Jun 30 02:06:58 MST 2010
Has anyone tried using PRINTF in their code and got it to compile?
0 Kudos
Reply
22 Replies

2,540 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by bmentink on Mon Sep 13 17:56:03 MST 2010
Now that was VERY useful :D It seems my startup_LPC17.c was the problem, I replaced with your one (cr_startup_lpc17.c) and semihosting works .... :)

Thanks for the help.
0 Kudos
Reply

2,540 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by CodeRedSupport on Mon Sep 13 13:05:32 MST 2010
Here is a very simple Makefile project that uses semihosting and prints to the console.
0 Kudos
Reply

2,540 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by bmentink on Mon Sep 13 12:36:34 MST 2010

Quote: CodeRedSupport
Your original post just says "I am having trouble getting printf to work via semihosting" - it doesn't actually say in what way it doesn't work :cool: I just wanted to ensure I wasn't misunderstanding.



Well actually I did say in what way it doesn't work: :mad:


Quote:
I still do not get any [B]output in the console window[/B].



and I DID say it was a makefile project: :p


Quote:
I have a [B]makefile[/B] project with my own loader file




Quote: CodeRedSupport

You are invoking the linker via the compiler. The --gc-sections option therefore needs to be prefixed with the -Xlinker option to cause the compiler to pass it directly through to the linker. Your makefile does this for the -map option, but not for --gc-sections.



And I did already mention that in my edit:


Quote:
Edit: Actually I see I have used -Xlinker incorrectly, it can only pass one argument to the linker, I should be using -wl,arg,arg, etc or putting -Xlinker in front of each linker option..



It would be very helpful if you could tell me if you have ever tested semihosting support with a makefile project ....... and if you have, how about posting an example makefile/loader file combo .. that would be useful :D

I have attached the correct makefile (not the one I supplied from home which was using CodeSourcery tools on a Linux box .... because you do not provide Linux support ... )

Cheers,
B
0 Kudos
Reply

2,541 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by bmentink on Mon Sep 13 02:49:39 MST 2010

Quote: CodeRedSupport

Anyway, I think that your makefile has given me a possible clue. Can you confirm what actual tools you are using to build you code here? There is reference at the top of your makefile to "/home/bmentink/opt/arm-2010q1/bin". This makes me suspicious that you might have "hacked" a different version of the GNU tools into your LPCXpresso installation.

Regards,
CodeRedSupport



Hi, sorry I gave you the wrong makefile, the make file I gave you was one I hacked for home use using some other tools ... I will post the correct makefile when I get to work tomorrow ..

Cheers,
B
0 Kudos
Reply

2,541 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by CodeRedSupport on Mon Sep 13 02:09:11 MST 2010

Quote: bmentink

As mentioned in my original post, I am not getting any output to the console window .. no errors.


Your original post just says "I am having trouble getting printf to work via semihosting" - it doesn't actually say in what way it doesn't work :cool: I just wanted to ensure I wasn't misunderstanding.


Quote:

I have attached my makefile for reference .. I am not sure why you think the linker is not envoking the --gc-sections" option correctly, it is passed as a linker option, remember this is a makefile project, not a gui one .. please re-read my original post.

You are invoking the linker via the compiler. The --gc-sections option therefore needs to be prefixed with the -Xlinker option to cause the compiler to pass it directly through to the linker. Your makefile does this for the -map option, but not for --gc-sections.


Quote:

By the way, I notice in the map file, that the printf functions are called from the libcr_c.a library, should they not be called out of the semihosting version of that lib? Do I need to remove libcr_c.a from the GROUP( ... line in my loader file perhaps ??

No - the two libraries work in collaboration. The main C library code for printf (in libcr_c.a) calls out to the function "__write" (in libcr_semihost.a) which actually handles the interaction up the debug link up to the debugger.

[Aside, for future proofing, I would suggest switching your group so that the semihosting library is specified before the main C library:
[FONT=Courier New][SIZE=1]GROUP(libcr_semihost.a libcr_c.a libcr_eabihelpers.a)[/SIZE][/FONT]
]

Anyway, I think that your makefile has given me a possible clue. Can you confirm what actual tools you are using to build you code here? There is reference at the top of your makefile to "/home/bmentink/opt/arm-2010q1/bin". This makes me suspicious that you might have "hacked" a different version of the GNU tools into your LPCXpresso installation.

If you have done this, then you should note that this is not a means of operation of LPCXpresso that we cannot provide support on.  If you have done this, it makes it very likely that you are actually including newlib header files, but then, due to your library script, linking with redlib library code. This is likely to lead to the sorts of problems that you are having.

Regards,
CodeRedSupport
0 Kudos
Reply

2,541 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by bmentink on Mon Sep 13 01:03:49 MST 2010
Hi there,

As mentioned in my original post, I am not getting any output to the console window .. no errors.

I have attached my makefile for reference .. I am not sure why you think the linker is not envoking the --gc-sections" option correctly, it is passed as a linker option, remember this is a makefile project, not a gui one .. please re-read my original post.

Edit: Actually I see I have used -Xlinker incorrectly, it can only pass one argument to the linker, I should be using -wl,arg,arg, etc or putting -Xlinker in front of each linker option..

By the way, I notice in the map file, that the printf functions are called from the libcr_c.a library, should they not be called out of the semihosting version of that lib? Do I need to remove libcr_c.a from the GROUP( ... line in my loader file perhaps ??

Thanks,
Bernie
0 Kudos
Reply

2,541 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by CodeRedSupport on Sun Sep 12 23:38:52 MST 2010
One other thought - are you mixing Newlib and Redlib? You need to ensure that if you link with Newlib, you must make sure that you use Newlib headers, and the same for Redlib. To do this, you need to ensure that the compiler Target tab has the correct headers set.

From the Group() statement you have supplied, it looks like you are using Redlib, so make sure that you have Redlib set in the compiler Target tab.
0 Kudos
Reply

2,541 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by CodeRedSupport on Sun Sep 12 23:22:26 MST 2010

Quote: bmentink
Thanks, I fixed that ... I had #include <stdio.h> but it needed to be #include "stdio.h" those warnings are gone .... but it still does not work.


#include <stdio.h> was correct, so the change you made here would seem to indicate that there is something else incorrect in your main.c file. Hard to say what this might be without looking at your source code though.

The only other thing I can spot from the map/build log is that the linker is not invoking the "--gc-sections" option correctly. This option needs to be added to the linker command under the "-Xlinker" options (in Properties->MCU Linker->Miscellaneous) - currently it appears you have it directly on the command line. However I can't imagine this actually causing the problem you are having here - it just means your image will be a bit bigger as unused code and data sections won't be being removed by the linker.

One other thing that you could clarify for me - how exactly does semihosting not work for you? Does it just not print anything to the console, or do you get a runtime error/fault?

Regards,
CodeRedSupport.
0 Kudos
Reply

2,541 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by bmentink on Sun Sep 12 14:21:21 MST 2010
Thanks, I fixed that ... I had #include <stdio.h> but it needed to be #include "stdio.h" those warnings are gone .... but it still does not work.

Any other suggestions?
0 Kudos
Reply

2,541 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by CodeRedSupport on Sun Sep 12 13:39:00 MST 2010
So first suspicious thing, in your build log you have....

main.c: In function 'main':
main.c:47: warning: implicit declaration of function 'printf'
main.c:47: warning: incompatible implicit declaration of built-in function 'printf'
which suggests that you are not including stdio.h ???

Please try fixing this, and report back on whether this helps.

Regards,
CodeRedSupport.
0 Kudos
Reply

2,541 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by bmentink on Sun Sep 12 13:26:41 MST 2010
Thanks for the reply.

I have uploaded the following:

1. Trial.zip .... zipped map file.
2. build_log.txt ... console printout of a full build after clean.

Yes, the "Hello World" semihosting project prints to the console fine ..

Thanks for the help.
Bernie
0 Kudos
Reply

2,541 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by CodeRedSupport on Fri Sep 10 00:14:13 MST 2010
Please can you do a clean of your project, then a build, and then copy'n'paste the build log into a text file and post that here.

In addition, please post the .map file generated by your build.

Also, can you confirm that a "standard semihosting project", for example the "hello world" generated by the C semihosting project wizard, or the consoleprint example correctly prints to the console when you execute it?

Regards,
CodeRedSupport
0 Kudos
Reply

2,541 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by bmentink on Thu Sep 09 15:18:44 MST 2010
Hi, I am having trouble getting printf to work via semihosting.

I have a makefile project with my own loader file based off the ones generated by the tools, it includes the line:


Quote:
GROUP(libcr_c.a libcr_semihost.a libcr_eabihelpers.a)



at the top. (My binary is much bigger now with the inclusion of the semihost lib)I then made sure semihosting was turned on in the debugger for my target (debug) but I still do not get any output in the console window.

My project compiles and links ok with printf() lines included.

I notice as the debugger connects, it prints out "semihosting enabled" down the bottom of the page.

Is there anything else I must do to get this working?
0 Kudos
Reply

2,541 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by timexton on Thu Jul 01 03:41:48 MST 2010
Sorted. It's the amount of RAM I'm using (7864) if I reduce this by 1024 then all is well. Thanks for your help.
0 Kudos
Reply

2,541 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by CodeRedSupport on Thu Jul 01 02:55:17 MST 2010
What is the actual address that you see in VECTPC?

Create an actual disassembly file of your .axf file (right click over .axf in project explorer view, and select [I]Binary utilities -> Disassemble[/I])  - more on this in

http://lpcxpresso.code-red-tech.com/LPCXpresso/node/29

What are the 20 (or so) assembly instructions either side of that address in your disassembly file?

Regards,
CodeRedSupport
0 Kudos
Reply

2,541 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by timexton on Thu Jul 01 02:45:30 MST 2010
I see it here at__main() in cr_startup_lpc11.c but it gets to Hard Fault before it reaches my main(). The disassembly seems to be initialising memory so is in a long loop which is difficult to step over. Any ideas?

#if defined (__REDLIB__)
    // Call the Redlib library, which in turn calls main()
    __main() ;
#else
0 Kudos
Reply

2,541 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by timexton on Thu Jul 01 02:04:09 MST 2010
I'm using the LPC1114. And you are correct the NoHost link option works (I was supposed to have tested all combinations this morning - finger trouble again). I'm tracking down the Hard Fault now as you suggested.
0 Kudos
Reply

2,541 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by CodeRedSupport on Thu Jul 01 00:51:41 MST 2010
Which MCU are you using? I don't currently have access to an LPC13 or LPC11 board with a serial port on it to try out, only an LPC17 - as per the example I pointed you at previously (which works here for me). Remember you will need UART code appropriate for your MCU.

As far as which library to link with, you should be able to link against Redlib (nohost) rather than Redlib (semihost)  - unless something else in your code is trying to carry out a semihosting operation. What link errors do you get?

For details of how to go about tracking down the cause of your hard fault, take a look at the knowledgebase entry:

http://lpcxpresso.code-red-tech.com/LPCXpresso/node/52 [login required]

Regards,
CodeRedSupport.
0 Kudos
Reply

2,541 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by timexton on Thu Jul 01 00:20:11 MST 2010
I implemented the __write as you said. Problem, I can only get it to build now with the semihost library but when I come to debug it starts at Hard Fault Handler, like the reset vector is wrong. Is it me?
I am asking myself if this is going to end in a stand alone application, semihost seems the wrong road to me.
0 Kudos
Reply

2,541 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by CodeRedSupport on Wed Jun 30 03:07:37 MST 2010
The way that the Redlib library is structured in a slightly different way to this.

There is an example which shows printf via the UART in the LPC17xx examples provided with LPCXPresso (RDB1768cmsis_UART_printf). The same principle can be used with LPC11/ 13 too - you basically need to provide a function called __write().

Regards,
CodeRedSupport.
0 Kudos
Reply