avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] Program Space String & optimization


From: Dimitar Dimitrov
Subject: Re: [avr-gcc-list] Program Space String & optimization
Date: Wed, 14 Dec 2005 18:22:47 +0200
User-agent: KMail/1.8.2

On 14.12.2005 11:42, bolet (sent by Nabble.com) wrote:
>  The program works OK without optimization. It doesn't work with
> optimization (-o1). The code is:
>
> ...includes...
> const char P_Txt[] PROGMEM = "Just a test..";
> volatile PGM_P txt= P_Txt;
>
> int main (void)
> {
>
>   ...Init code ... (reg setup & enable int)
>
>    do{} while( (a=pgm_read_byte(txt)) );  // Wait for null char
>    cli();                                 //Disable int
>    for (;;);                              // Do nothing
>    return(0);
> }
>
> SIGNAL (SIG_USART_DATA)
> {
>     UDR0=pgm_read_byte(txt++);  //Send a byte and increment  pointer
> }

Hi, 
Your problem seems to be in this line:
>   do{} while( (a=pgm_read_byte(txt)) );
In spite of txt being declared as volatile, the pgm_read_byte macro evaluates 
it as a plain uint16_t. To see what I mean, check out these two macros from 
<avr/pgmspace.h> :
#define pgm_read_byte_near(address_short) __LPM((uint16_t)(address_short))
#define pgm_read_byte(address_short)    pgm_read_byte_near(address_short)

A solution I would propose is to change the offending line like this (I 
haven't checked this, though):
>   do{} while( (a=(volatile char)(pgm_read_byte(txt))) );





reply via email to

[Prev in Thread] Current Thread [Next in Thread]