Re: AVR-GCC-list Digest, Vol 157, Issue 2

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Re: AVR-GCC-list Digest, Vol 157, Issue 2

Bob von Knobloch-2
On 08/02/2020 18:00, [hidden email] wrote:

> Send AVR-GCC-list mailing list submissions to
> [hidden email]
>
> To subscribe or unsubscribe via the World Wide Web, visit
> https://lists.nongnu.org/mailman/listinfo/avr-gcc-list
> or, via email, send a message with subject or body 'help' to
> [hidden email]
>
> You can reach the person managing the list at
> [hidden email]
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of AVR-GCC-list digest..."
>
>
> Today's Topics:
>
>     1. Re: Where is the error (stdout) (Col)
>     2. Re: Where is the error (stdout) (David Kelly)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Sat, 8 Feb 2020 12:58:19 +1300
> From: Col <[hidden email]>
> To: [hidden email]
> Subject: Re: Where is the error (stdout)
> Message-ID: <[hidden email]>
> Content-Type: text/plain; charset=utf-8; format=flowed
>
>
>>
>> void uart_putchar(char c, FILE *stream)
>> {
>>   if (c == '\n')
>> uart_putchar('\r', stream);
>>   loop_until_bit_is_set(UCSRA, UDRE);
>>   UDR = c;
>>   return ;
>> }
>>
> I suspect it's because your returning a void instead of an int,
>
> Here is some code that I used to test stdio on avrlibc ( atmega128 )
>
> which compiles fine with gcc 5.4.0
>
>
> static int uart_putchar(char c, FILE *stream)
> {
>       if (c == '\n')
>           uart_putchar('\r', stream);
>       loop_until_bit_is_set(UCSR0A, UDRE);
>       UDR0 = c;
>       return 0;
> }
>
>
>
>
> Cheers
>
> Colin
>
>
>
>
>
> ------------------------------
>
> Message: 2
> Date: Fri, 7 Feb 2020 18:56:41 -0600
> From: David Kelly <[hidden email]>
> To: [hidden email]
> Subject: Re: Where is the error (stdout)
> Message-ID: <[hidden email]>
> Content-Type: text/plain; charset=us-ascii
>
>
> On Feb 7, 2020, at 5:58 PM, Col <[hidden email]> wrote:
>
>>> void uart_putchar(char c, FILE *stream)
>>> {
>>>   if (c == '\n')
>>> uart_putchar('\r', stream);
>>>   loop_until_bit_is_set(UCSRA, UDRE);
>>>   UDR = c;
>>>   return ;
>>> }
>>
>> I suspect it's because your returning a void instead of an int,
>
> In Unix convention its
>
> int putc( int, FILE* )
> int putchar( int )
>
> Where upon success one returns the character put or -1 or EOF for failure. If replacing standard function one should return the expected value else something will break.
>
> --
> David Kelly N4HHE, [hidden email]
> ============================================================
> Whom computers would destroy, they must first drive mad.
>
>
>
>
> ------------------------------
>
> Subject: Digest Footer
>
> _______________________________________________
> AVR-GCC-list mailing list
> [hidden email]
> https://lists.nongnu.org/mailman/listinfo/avr-gcc-list
>
>
> ------------------------------
>
> End of AVR-GCC-list Digest, Vol 157, Issue 2
> ********************************************
>

I use a similar function on a Mega1284:

/**
  *******************************************************************************
  * Wait until USART free, then send character to the terminal.
  * Pad LF to CR,LF.
  *******************************************************************************
  */

static void term_putchar(uint8_t c)
{
     if (c == '\n')
        term_putchar('\r');
     loop_until_bit_is_set(UCSR0A, UDRE0);
     UDR0 = c;
}

Compiles and works fine (for me), possible the spurious 'return;' is doing something that the compiler doesn't like (need a GCC guru).

Cheers,
Bob