<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.arm.com/utility/feedstylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>USART: use of printf();</title><link>https://community.arm.com/developer/tools-software/tools/f/keil-forum/22658/usart-use-of-printf</link><description> 
Hello, 

 
I&amp;#39;m working with the AT91RM9200 - the USART is already
configurated and works but I don&amp;#39;t know how I could use the
printf-function for the usart. 

 
Now I&amp;#39;m sending a character with this function - it works, but
it&amp;#39;s ver uncomfortable if</description><dc:language>en-US</dc:language><generator>Telligent Community 10</generator><item><title>RE: USART: use of printf();</title><link>https://community.arm.com/thread/153367?ContentTypeID=1</link><pubDate>Thu, 25 Oct 2007 08:54:48 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:3e4243af-7cfc-4b77-8126-a817c67e835f</guid><dc:creator>Johannes meier</dc:creator><description>&lt;p&gt;&lt;p&gt;
yes that&amp;#39;s the reason... I forget to delete cpp from the
linker...&lt;/p&gt;

&lt;p&gt;
best regards&lt;br /&gt;
Johannes&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: USART: use of printf();</title><link>https://community.arm.com/thread/152692?ContentTypeID=1</link><pubDate>Thu, 25 Oct 2007 08:36:01 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:2bff3018-4a22-430b-93ac-e7c47848cb90</guid><dc:creator>Patrick Noonan</dc:creator><description>&lt;p&gt;&lt;p&gt;
The errors that you show are consistent with you compiling this C
file as a CPP file. Notice the reference in the error message to the
std namespace.&lt;/p&gt;

&lt;p&gt;
There is a switch to the compiler to compile .c files as cpp
files. Are you using it?&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: USART: use of printf();</title><link>https://community.arm.com/thread/151912?ContentTypeID=1</link><pubDate>Thu, 25 Oct 2007 08:31:18 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:4d91bbc2-bb28-4438-9a45-c697870c5c4d</guid><dc:creator>Johannes meier</dc:creator><description>&lt;p&gt;&lt;p&gt;
right, at the beginning of the retarget.c file there are comments,
I don&amp;#39;t posted...&lt;/p&gt;

&lt;p&gt;
But the error message says which things are not correct... I
created a complete new protect file and now it is working... I only
copy the whole c-code in the new project file..&lt;/p&gt;

&lt;p&gt;
But it would be very interesting what the error was / or is.&lt;/p&gt;

&lt;p&gt;
best regards&lt;br /&gt;
Johannes&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: USART: use of printf();</title><link>https://community.arm.com/thread/151171?ContentTypeID=1</link><pubDate>Thu, 25 Oct 2007 08:15:54 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:3e782d2a-64d9-452f-a530-7e9822c35859</guid><dc:creator>Per Westermark</dc:creator><description>&lt;p&gt;&lt;p&gt;
Don\t you notice something strange.&lt;/p&gt;

&lt;p&gt;
You have posted what you claim is your Retarget.c file. It doesn&amp;#39;t
have many source lines. The compiler complains about line 19. Line 19
does not match your source file. Have you really posted a verbatim
copy of Retarget.c?&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: USART: use of printf();</title><link>https://community.arm.com/thread/146135?ContentTypeID=1</link><pubDate>Thu, 25 Oct 2007 07:40:49 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:23bc1a5e-3367-4c0f-8509-c2cafb4fc67e</guid><dc:creator>Johannes meier</dc:creator><description>&lt;p&gt;&lt;p&gt;
thanks for your reply, but there is no problem with the retarget.c
file...&lt;/p&gt;

&lt;p&gt;
there must be another problem, because the retarget.c file from
the AT91SAM7S-EK is identical with the retarget.c file I use.&lt;/p&gt;

&lt;p&gt;
I don&amp;#39;t know where could be the error that FILE __stdout; is not
allowed&lt;/p&gt;

&lt;p&gt;
best regards&lt;br /&gt;
Johannes&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: USART: use of printf();</title><link>https://community.arm.com/thread/150634?ContentTypeID=1</link><pubDate>Thu, 25 Oct 2007 07:40:49 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:09dbaf31-f8c3-4731-8996-1a0ad6afe0dd</guid><dc:creator>Johannes meier</dc:creator><description>&lt;p&gt;&lt;p&gt;
thanks for your reply, but there is no problem with the retarget.c
file...&lt;/p&gt;

&lt;p&gt;
there must be another problem, because the retarget.c file from
the AT91SAM7S-EK is identical with the retarget.c file I use.&lt;/p&gt;

&lt;p&gt;
I don&amp;#39;t know where could be the error that FILE __stdout; is not
allowed&lt;/p&gt;

&lt;p&gt;
best regards&lt;br /&gt;
Johannes&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: USART: use of printf();</title><link>https://community.arm.com/thread/144304?ContentTypeID=1</link><pubDate>Thu, 25 Oct 2007 07:26:55 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:aaf3a933-24c1-4206-8943-50abd0f375a2</guid><dc:creator>Martin G&amp;#195;&amp;#188;nther</dc:creator><description>&lt;p&gt;&lt;p&gt;
Hello Johannes Meier,&lt;/p&gt;

&lt;p&gt;
please take a look at Project
&lt;i&gt;C:\Keil\ARM\Boards\Atmel\AT91SAM7S-EK\Hello&lt;/i&gt;. This example
program uses UART with retargetting. It is not the microcontroller
you are using but it is also an Atmel.&lt;/p&gt;

&lt;p&gt;
Best Regards,&lt;br /&gt;
Martin Guenther&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: USART: use of printf();</title><link>https://community.arm.com/thread/144306?ContentTypeID=1</link><pubDate>Thu, 25 Oct 2007 07:20:34 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:11058804-541d-43cc-bb23-cdf56ceceaf1</guid><dc:creator>Johannes meier</dc:creator><description>&lt;p&gt;&lt;p&gt;
Is there nobody who could help me?&lt;/p&gt;

&lt;p&gt;
Now I have only the startup file from Keil, a empty main-routine
and a short retarget.c file - that&amp;#39;s all...&lt;/p&gt;

&lt;pre&gt;
#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;rt_misc.h&amp;gt;

#pragma import(__use_no_semihosting_swi)

struct __FILE { int handle; /* Add whatever you need here */ };
FILE __stdout;
FILE __stdin;


void _sys_exit(int return_code) {
label:  goto label;  /* endless loop */
}
&lt;/pre&gt;

&lt;p&gt;
error messages:&lt;/p&gt;

&lt;p&gt;
compiling Retarget.c...&lt;br /&gt;
Retarget.c(19): warning: #2681-D: name linkage conflicts with
previous declaration of variable &amp;quot;std::__stdout&amp;quot; (declared at line 87
of &amp;quot;D:\Keil\ARM\RV31\INC\stdio.h&amp;quot;)&lt;br /&gt;
Retarget.c(19): error: #70: incomplete type is not allowed&lt;br /&gt;
Retarget.c(20): warning: #2681-D: name linkage conflicts with
previous declaration of variable &amp;quot;std::__stdin&amp;quot; (declared at line 87
of &amp;quot;D:\Keil\ARM\RV31\INC\stdio.h&amp;quot;)&lt;br /&gt;
Retarget.c(20): error: #70: incomplete type is not allowed&lt;br /&gt;
Retarget.c(23): error: #734: function &amp;quot;fputc(int, std::FILE *)&amp;quot;
conflicts with using-declaration of function &amp;quot;std::fputc(int,
std::FILE *) C&amp;quot;&lt;br /&gt;
Retarget.c(47): error: #734: function &amp;quot;ferror(std::FILE *)&amp;quot; conflicts
with using-declaration of function &amp;quot;std::ferror(std::FILE *) C&amp;quot;&lt;br /&gt;
Retarget.c - 4 Error(s), 2 Warning(s).&lt;/p&gt;

&lt;p&gt;
Johannes&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: USART: use of printf();</title><link>https://community.arm.com/thread/141881?ContentTypeID=1</link><pubDate>Thu, 25 Oct 2007 06:00:13 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:f7f756f8-1080-4e28-b248-0451a8fe95de</guid><dc:creator>Johannes meier</dc:creator><description>&lt;p&gt;&lt;p&gt;
Are there any other files I have to use with retarget.c??? Or are
there any links, header-files - anything like that... there must be
the error...&lt;/p&gt;

&lt;p&gt;
Johannes&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: USART: use of printf();</title><link>https://community.arm.com/thread/138587?ContentTypeID=1</link><pubDate>Thu, 25 Oct 2007 05:15:28 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:bad50f63-dfa0-43b7-b2c1-b3887a9c31f4</guid><dc:creator>Johannes meier</dc:creator><description>&lt;p&gt;&lt;p&gt;
I don&amp;#39;t know what I&amp;#39;m doing wrong.&lt;/p&gt;

&lt;p&gt;
I work with the Realview Compiler and probably the compiler don&amp;#39;t
understand such defintions as FILE __stdout; (incomplete type is not
allowed is the error message)...&lt;/p&gt;

&lt;p&gt;
And I get warnings, that std::__stdin and std::__stdout functions
are declared in stdio.h&lt;/p&gt;

&lt;p&gt;
Could anybody tell me a solution for this problem?&lt;/p&gt;

&lt;p&gt;
best regards&lt;br /&gt;
Johannes&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: USART: use of printf();</title><link>https://community.arm.com/thread/135185?ContentTypeID=1</link><pubDate>Thu, 25 Oct 2007 04:43:53 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:32bd0fca-00f6-4176-8020-025adb2660bd</guid><dc:creator>Johannes meier</dc:creator><description>&lt;p&gt;&lt;pre&gt;
#include &amp;lt;stdio.h&amp;gt;
//#include &amp;lt;time.h&amp;gt;
#include &amp;lt;rt_misc.h&amp;gt;

#pragma import(__use_no_semihosting_swi)


extern int  COM1_putchar(int ch);  /* in Serial.c */


struct __FILE { int handle; /* Add whatever you need here */ };
FILE __stdout;
FILE __stdin;


int fputc(int ch, FILE *f) {

        volatile unsigned int i;

        while (COM1_putchar (ch) != 0) {
        for (i=0; i&amp;lt;1000; i++) {
                /*** DO NOTHING ***/
        }
        }
        return (ch);
}
/*
int fgetc(FILE *f) {
  return (sendchar(getkey()));
}

*/

int ferror(FILE *f) {
  /* Your implementation of ferror */
  return EOF;
}


void _ttywrch(int ch) {
  volatile unsigned int i;

  while (COM1_putchar (ch) != 0) {
    for (i=0; i&amp;lt;1000; i++) {
      /*** DO NOTHING ***/
    }
  }
}


void _sys_exit(int return_code) {
  while (1);    /* endless loop */
}
&lt;/pre&gt;

&lt;p&gt;
I get still the same errors...&lt;/p&gt;

&lt;p&gt;
best regards&lt;br /&gt;
Johannes&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: USART: use of printf();</title><link>https://community.arm.com/thread/124184?ContentTypeID=1</link><pubDate>Thu, 25 Oct 2007 04:34:50 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:2ea27a9c-95a5-4e36-81df-1f89c95585fb</guid><dc:creator>Martin G&amp;#195;&amp;#188;nther</dc:creator><description>&lt;p&gt;&lt;p&gt;
Hello Johannes Meier,&lt;/p&gt;

&lt;p&gt;
you just have to change fputc, fgetc and _ttywrch. _ttywrch should
be the same as fputc. Leave the rest as it is.&lt;/p&gt;

&lt;p&gt;
Best Regards,&lt;br /&gt;
Martin Guenther&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: USART: use of printf();</title><link>https://community.arm.com/thread/124183?ContentTypeID=1</link><pubDate>Thu, 25 Oct 2007 04:28:38 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:95930ae3-0fa4-4d1f-a714-0ae53f0d2a50</guid><dc:creator>Johannes meier</dc:creator><description>&lt;p&gt;&lt;p&gt;
There are many name linkage conflicts with previous declaration of
variable &amp;quot;std::__stdin&amp;quot; (declared in stdio.h)&lt;/p&gt;

&lt;p&gt;
FILE __stdout; (incomplete type is not allowed)&lt;/p&gt;

&lt;p&gt;
I take a look into one example from keil - but I don&amp;#39;t see the
differences between these two projects&lt;/p&gt;

&lt;p&gt;
my code in the retarget.c is&lt;/p&gt;

&lt;pre&gt;
#include &amp;lt;stdio.h&amp;gt;
//#include &amp;lt;time.h&amp;gt;
#include &amp;lt;rt_misc.h&amp;gt;

#pragma import(__use_no_semihosting_swi)


extern int  COM1_putchar(int ch);

struct __FILE { int handle; /* Add whatever you need here */ };
FILE __stdout;
FILE __stdin;


int fputc(int ch, FILE *f) {

        volatile unsigned int i;

        while (COM1_putchar (ch) != 0) {
        for (i=0; i&amp;lt;1000; i++) {
                /*** DO NOTHING ***/
        }
        }
        return (ch);
}
&lt;/pre&gt;

&lt;p&gt;
it&amp;#39;s the same as in the example from keil - only to test it.&lt;/p&gt;

&lt;p&gt;
best regards&lt;br /&gt;
Johannes&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: USART: use of printf();</title><link>https://community.arm.com/thread/113328?ContentTypeID=1</link><pubDate>Thu, 25 Oct 2007 03:47:12 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:d0df01ea-1df9-4648-8a71-df37c3b79d0e</guid><dc:creator>Johannes meier</dc:creator><description>&lt;p&gt;&lt;p&gt;
ok, that must be the function fputc...&lt;/p&gt;

&lt;pre&gt;
struct __FILE { int handle; /* Add whatever you need here */ };
FILE __stdout;
FILE __stdin;


int fputc(int ch, FILE *f) {
  return (sendchar(ch));
}
&lt;/pre&gt;

&lt;p&gt;
But what about the lines FILE __stdout; and FILE __stdin;?&lt;/p&gt;

&lt;p&gt;
best regards&lt;br /&gt;
Johannes&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: USART: use of printf();</title><link>https://community.arm.com/thread/99839?ContentTypeID=1</link><pubDate>Thu, 25 Oct 2007 03:41:23 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:2a091696-d751-4444-aa26-0cd91677a143</guid><dc:creator>Martin G&amp;#195;&amp;#188;nther</dc:creator><description>&lt;p&gt;&lt;p&gt;
Hello Johannes Meier,&lt;/p&gt;

&lt;p&gt;
just change the function that prints a single character on the
UART with the one you already have and leave the other functions
empty. A lot of the Keil examples use retargetting. Search the
examples for the use of RETARGET.c&lt;/p&gt;

&lt;p&gt;
Best Regards,&lt;br /&gt;
Martin Guenther&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: USART: use of printf();</title><link>https://community.arm.com/thread/75640?ContentTypeID=1</link><pubDate>Thu, 25 Oct 2007 03:35:16 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:ef7385ed-ef91-4dc7-b023-e0cf877fc485</guid><dc:creator>Johannes meier</dc:creator><description>&lt;p&gt;&lt;p&gt;
thanks for your answer...&lt;/p&gt;

&lt;p&gt;
could you show me a small example how I have to configurate this
c-file for my controller?&lt;/p&gt;

&lt;p&gt;
best regards&lt;br /&gt;
Johannes&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: USART: use of printf();</title><link>https://community.arm.com/thread/48830?ContentTypeID=1</link><pubDate>Thu, 25 Oct 2007 03:19:36 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:2f47a4e5-a49a-4626-a7e3-968f33014edc</guid><dc:creator>Martin G&amp;#195;&amp;#188;nther</dc:creator><description>&lt;p&gt;&lt;p&gt;
Hello Johannes Meier,&lt;/p&gt;

&lt;p&gt;
you have to enable &lt;b&gt;Retargetting&lt;/b&gt; to use printf.&lt;/p&gt;

&lt;p&gt;
Adapt file RETARGET.c to your microcontroller and add it to your
project. File RETARGET.C can be found in
&lt;b&gt;..\Keil\ARM\Startup&lt;/b&gt;.&lt;/p&gt;

&lt;p&gt;
Best Regards,&lt;br /&gt;
Martin Guenther&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>