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

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

RE: [avr-gcc-list] Gcc bug??


From: Brian Cuthie
Subject: RE: [avr-gcc-list] Gcc bug??
Date: Wed, 3 Mar 2004 09:11:55 -0500

BTW, I should have mentioned in my original post that turning on
optimization (-O) seems to avoid the problem.

-brian 

> -----Original Message-----
> From: Dave Hylands [mailto:address@hidden 
> Sent: Wednesday, March 03, 2004 8:59 AM
> To: address@hidden; Peter Hierholzer; address@hidden
> Subject: RE: [avr-gcc-list] Gcc bug??
> 
> Based on the conditions you've described, it doesn't sound 
> like volatile is the problem.
> 
> The typical problem with volatile is that the ISR changes the 
> value and the non-ISR doesn't see the change because the 
> variable has been optimized into a register.
> 
> --
> Dave Hylands
> Vancouver, BC, Canada
> http://www.DaveHylands.com/
> 
> 
> > -----Original Message-----
> > From: address@hidden
> > [mailto:address@hidden On Behalf Of Brian Cuthie
> > Sent: Wednesday, March 03, 2004 5:21 AM
> > To: 'Peter Hierholzer'; address@hidden
> > Subject: RE: [avr-gcc-list] Gcc bug??
> > 
> > 
> > 
> > I'll do some tests and let you know. I know I did forget to add 
> > volatile to at least one variable that I'm using in my interrupt 
> > handler, and I fixed this already. Since I don't recall 
> which one I'll 
> > need to explicitly test this theory.
> > I'll be a little surprised (although happy) if this turns 
> out the be 
> > the cause. It's not quite the code I'd expect the compiler to emit, 
> > even without the volatile keyword. I mean, 0 is still 0.
> > 
> > Thanks
> > 
> > -brian
> > 
> > > -----Original Message-----
> > > From: Peter Hierholzer [mailto:address@hidden
> > > Sent: Wednesday, March 03, 2004 5:52 AM
> > > To: address@hidden
> > > Cc: address@hidden
> > > Subject: AW: [avr-gcc-list] Gcc bug??
> > > 
> > > > I'm having some problems with an app that uses AvrX and gcc
> > > (v. 3.3.1)
> > > > on an ATmega16. In the interrupt routine for the TWI  I
> > > write a static
> > > > with a code that indicates its current state. In an effort
> > > to debug a
> > > > different problem I compiled the code without any optimization.
> > > > 
> > > > While I did discover the original problem I had been hunting, I 
> > > > started to see some very unreliable behavior with the TWI.
> > > After some
> > > > investigation I determined that the state variable
> > > (mentioned above)
> > > > was getting written with an unreasonable value (not a
> > valid state).
> > > > The correct state value that should have been written into the 
> > > > variable is "0". Further experiments revealed that memory
> > > corruption
> > > > (at least directly into the variable's memory location)
> > was not the
> > > > problem.
> > > > 
> > > > What I then determined is that the "0" register (r1) 
> contained the 
> > > > value 8!
> > > > This, not coincidentally (and looking at the disassembled
> > code) is
> > > > exactly the value that's being incorrectly written into the
> > > static state variable.
> > > > Interestingly, turning on any level of optimization seems
> > > to fix it,
> > > > at least as observed by the TWI port handler not hanging.
> > > > 
> > > > I was wondering if anyone else has seen anything like this,
> > > or has any
> > > > advice or suggestions.
> > > > 
> > > > Thanks
> > > > 
> > > > -brian
> > > 
> > > 
> > > Hi Brian,
> > > 
> > > Did you declare the state variable as volatile?
> > > If you access a variable in your normal program AND in 
> the interrupt 
> > > routine you must declare it as volatile. Otherwise the 
> compiler is 
> > > not aware that the variable is modified in the interrupt 
> routine and 
> > > generates wrong code.
> > > 
> > > Peter
> > > 
> > > 
> > 
> > 
> > _______________________________________________
> > avr-gcc-list mailing list
> > address@hidden
> > http://www.avr1.org/mailman/listinfo/avr-gcc-> list
> > 
> > 
> 


_______________________________________________
avr-gcc-list mailing list
address@hidden
http://www.avr1.org/mailman/listinfo/avr-gcc-list


reply via email to

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