[avr-gcc-list] How to force GCC to not to remove nop statements ?

2009-02-19 Thread Vincent Trouilliez
Hi list,

Like many people I guess, I am using in-lined nop asm statements to
respect the timing of external devices, when toggling their control
lines.

In the case at hand I am driving a text LCD module, and the 
Enable line must be pulsed low for 250ns.

void lcd_send_nibble(uint8_t data)
{
...
//pulse Enable line
LCD_PORT |= LCD_E;
__asm__ volatile(nop);
__asm__ volatile(nop);
__asm__ volatile(nop);
__asm__ volatile(nop);
LCD_PORT = ~LCD_E;

}


My AVR was running at 8MHz, so an instruction cycle of 125ns, so two nop
in-lined were spot on, just perfect, and it ran fine.

Today I pushed the AVR (ATmega32) up to its maximum of 16MHz.
So I now need 4 nops not two. So I did that.. and the LCD doesn't work
reliably. Suspecting the problem, I went straight to the generated
assembly, and horror, my 4 nop statements have disappeared !

I made a few trials. It appears that up to and including 3 nop
statements, GCC leaves them alone. But if I put 4 of them, it removes
them all ! 

Any way to instruct GCC to leave my 4 nops ?

Am using avr-gcc 4.3.2


Regards,

--
Vince


___
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list


RE: [avr-gcc-list] How to force GCC to not to remove nop statements ?

2009-02-19 Thread Weddington, Eric
 

 -Original Message-
 From: 
 avr-gcc-list-bounces+eweddington=cso.atmel@nongnu.org 
 [mailto:avr-gcc-list-bounces+eweddington=cso.atmel@nongnu.
 org] On Behalf Of Vincent Trouilliez
 Sent: Thursday, February 19, 2009 11:02 AM
 To: avr-gcc-list@nongnu.org
 Subject: [avr-gcc-list] How to force GCC to not to remove 
 nop statements ?
 
 Hi list,
 
 Like many people I guess, I am using in-lined nop asm statements to
 respect the timing of external devices, when toggling their control
 lines.
 
snip 
 Am using avr-gcc 4.3.2
 

If you are using WinAVR 20081205 then you can use one of the new builtin 
functions:

void __builtin_avr_delay_cycles(unsigned long __n);

The prototype can be found in avr/builtins.h, but you shouldn't need the 
prototype to call it.

The parameter is expecting the number of cycles that you want to delay, so in 
your case this should be:

__builtin_avr_delay_cycles(4);

And then let gcc handle generating the code for you. ;-)

Eric Weddington


___
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list


Re: [avr-gcc-list] How to force GCC to not to remove nop statements ?

2009-02-19 Thread Ruud Vlaming
On Thursday 19 February 2009 19:01, Vincent Trouilliez wrote:

 I made a few trials. It appears that up to and including 3 nop
 statements, GCC leaves them alone. But if I put 4 of them, it removes
 them all ! 
Are you absolutely sure they are really left out?  I assume they are
just not shown in the assembly file. Four or more nops are replaced
by ellipses, but are present allright. Have a close look at the addresses.

Otherwise you could use 
  __asm__ volatile(
nop \n\t
nop \n\t
nop \n\t
nop \n\t);
in which gcc cannot start to optimize.

Ruud


___
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list


Re: [avr-gcc-list] How to force GCC to not to remove nop statements ?

2009-02-19 Thread Parthasaradhi Nayani
Hi Vincent,
If I understand correctly, the word volatile itself is to tell the compiler 
not to ignore the statement. I am not sure if your statement is correct, but I 
have used

 asm volatile (nop::);

and the compiler never removed the nops from code. 

Nayani

--- On Thu, 2/19/09, Vincent Trouilliez vincent.trouill...@modulonet.fr wrote:
From: Vincent Trouilliez vincent.trouill...@modulonet.fr
Subject: [avr-gcc-list] How to force GCC to not to remove nop statements ?
To: avr-gcc-list@nongnu.org avr-gcc-list@nongnu.org
Date: Thursday, February 19, 2009, 11:31 PM

Hi list,

Like many people I guess, I am using in-lined nop asm statements to
respect the timing of external devices, when toggling their control
lines.

In the case at hand I am driving a text LCD module, and the 
Enable line must be pulsed low for 250ns.

void lcd_send_nibble(uint8_t data)
{
...
//pulse Enable line
LCD_PORT |= LCD_E;
__asm__ volatile(nop);
__asm__ volatile(nop);
__asm__ volatile(nop);
__asm__ volatile(nop);
LCD_PORT = ~LCD_E;

}


My AVR was running at 8MHz, so an instruction cycle of 125ns, so two nop
in-lined were spot on, just perfect, and it ran fine.

Today I pushed the AVR (ATmega32) up to its maximum of 16MHz.
So I now need 4 nops not two. So I did that.. and the LCD doesn't work
reliably. Suspecting the problem, I went straight to the generated
assembly, and horror, my 4 nop statements have disappeared !

I made a few trials. It appears that up to and including 3 nop
statements, GCC leaves them alone. But if I put 4 of them, it removes
them all ! 

Any way to instruct GCC to leave my 4 nops ?

Am using avr-gcc 4.3.2


Regards,

--
Vince


___
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list



  ___
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list


Re: [avr-gcc-list] How to force GCC to not to remove nop statements ?

2009-02-19 Thread Vincent Trouilliez
On Thu, 19 Feb 2009 11:14:40 -0700
Weddington, Eric ewedding...@cso.atmel.com wrote:

 If you are using WinAVR 20081205 then you can use one of the new builtin 
 functions:
 void __builtin_avr_delay_cycles(unsigned long __n);

Hmm, sweet !
Unfortunately I am on Linux so no WinAVR for me ! ;-)

--
Vince


___
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list


[avr-gcc-list] introducing a new section in data memory

2009-02-19 Thread Parthasaradhi Nayani

Hello all,
I needed to create a buffer of 256 bytes starting at a page boundary (xx00) in 
the RAM memory (Mega8). 

I added this line in the makefile

LDFLAGs = -wl,--section-start=.test=0x800200

and defined a variable in the .C file (shown below)

unsigned char mem3 __attribute__ ((section(.test)));

However variable mem3 is being assigned address 0x60 in the controller???

also if I define another global in next line to mem3 I get error that .data and 
.bss overlap lma 0xa0?? 

I am of the opinion that all variable defined with attribute .test will be 
located in that memory area and all other global variables will be located in 
their native memory. Perhaps if I ma able locate the .test section properly the 
overlap error may vanish. Can you correct the problem please? Thank you.


Nayani




  ___
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list


Re: [avr-gcc-list] How to force GCC to not to remove nop statements ?

2009-02-19 Thread Vincent Trouilliez
On Thu, 19 Feb 2009 10:22:23 -0800 (PST)
Parthasaradhi Nayani partha_nay...@yahoo.com wrote:

 Hi Vincent,
 If I understand correctly, the word volatile itself is to tell the compiler 
 not to ignore the statement. I am not sure if your statement is correct, but 
 I have used
 
  asm volatile (nop::);

I used this too, because it's what the avr-libc manual shows, however
when I do this, GCC caughs :

lcd.c:96: error: ‘asm’ undeclared (first use in this function)
lcd.c:96: error: (Each undeclared identifier is reported only once
lcd.c:96: error: for each function it appears in.)
lcd.c:96: error: expected ‘;’ before ‘volatile’
make: *** [lcd.o] Error 1

the same avr manual (section 9.6.5, macros) suggests that using
__asm__ instead of asm (and same for volatile) might help get rid of
warnings. So I tried that and it worked.. so I stick with it ;-)


--
Vince


___
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list


Re: [avr-gcc-list] How to force GCC to not to remove nop statements ?

2009-02-19 Thread David Kelly
On Thu, Feb 19, 2009 at 11:14:40AM -0700, Weddington, Eric wrote:
  
 If you are using WinAVR 20081205 then you can use one of the new
 builtin functions:
 
 void __builtin_avr_delay_cycles(unsigned long __n);
 
 The prototype can be found in avr/builtins.h, but you shouldn't need
 the prototype to call it.

Hey Joerg, you must be busy! FreeBSD's avr-gcc used to track WinAVR
closer than this.  :-)

-- 
David Kelly N4HHE, dke...@hiwaay.net

Whom computers would destroy, they must first drive mad.


___
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list


RE: [avr-gcc-list] How to force GCC to not to remove nop statements?

2009-02-19 Thread Weddington, Eric
 

 -Original Message-
 From: 
 avr-gcc-list-bounces+eweddington=cso.atmel@nongnu.org 
 [mailto:avr-gcc-list-bounces+eweddington=cso.atmel@nongnu.
 org] On Behalf Of David Kelly
 Sent: Thursday, February 19, 2009 12:36 PM
 To: avr-gcc-list@nongnu.org
 Subject: Re: [avr-gcc-list] How to force GCC to not to remove 
 nop statements?
 
 On Thu, Feb 19, 2009 at 11:14:40AM -0700, Weddington, Eric wrote:
   
  If you are using WinAVR 20081205 then you can use one of the new
  builtin functions:
  
  void __builtin_avr_delay_cycles(unsigned long __n);
  
  The prototype can be found in avr/builtins.h, but you 
 shouldn't need
  the prototype to call it.
 
 Hey Joerg, you must be busy! FreeBSD's avr-gcc used to track WinAVR
 closer than this.  :-)

He has been busy. He's been working on support for the new ATmega128RFA1 
device, which has been added recently to the toolchain. Joerg will be including 
all of the WinAVR patches in his next update of the avr toolchain in FreeBSD 
Ports.

Joerg and I are working closely on the next release. There's been a lot of 
activity recently on avr-libc and avrdude, with releases of both coming up very 
soon.


___
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list


Re: [avr-gcc-list] How to force GCC to not to remove nop statements?

2009-02-19 Thread David Kelly
On Thu, Feb 19, 2009 at 12:46:50PM -0700, Weddington, Eric wrote:
  
  Hey Joerg, you must be busy! FreeBSD's avr-gcc used to track WinAVR
  closer than this.  :-)
 
 He has been busy. He's been working on support for the new
 ATmega128RFA1 device, which has been added recently to the toolchain.
 Joerg will be including all of the WinAVR patches in his next update
 of the avr toolchain in FreeBSD Ports.
 
 Joerg and I are working closely on the next release. There's been a
 lot of activity recently on avr-libc and avrdude, with releases of
 both coming up very soon.

Thought I ought to reply to make sure its clear that I'm not complaining
and very much appreciate the work Eric and Joerg are doing and have done
for avr-gcc.

Related to another thread: as to why *not* to use an 8051:
Doesn't have avr-gcc.

-- 
David Kelly N4HHE, dke...@hiwaay.net

Whom computers would destroy, they must first drive mad.


___
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list


RE: [avr-gcc-list] introducing a new section in data memory

2009-02-19 Thread Weddington, Eric
 

 -Original Message-
 From: 
 avr-gcc-list-bounces+eweddington=cso.atmel@nongnu.org 
 [mailto:avr-gcc-list-bounces+eweddington=cso.atmel@nongnu.
 org] On Behalf Of Parthasaradhi Nayani
 Sent: Thursday, February 19, 2009 11:37 AM
 To: avr-gcc-list
 Subject: [avr-gcc-list] introducing a new section in data memory
 
 
 Hello all,
 I needed to create a buffer of 256 bytes starting at a page 
 boundary (xx00) in the RAM memory (Mega8). 
 
 I added this line in the makefile
 
 LDFLAGs = -wl,--section-start=.test=0x800200
 

First off, is that a typo above? It's suppose to be an uppercase 'W' like so:
LDFLAGs = -Wl,--section-start=.test=0x800200


___
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list


Re: [avr-gcc-list] How to force GCC to not to remove nop statements?

2009-02-19 Thread Jim Brain

David Kelly wrote:

Related to another thread: as to why *not* to use an 8051:
Doesn't have avr-gcc.
  
So true.  Althought it's pointless to add to the recent Freaks AVR vs 
PIC thread, this is one of the most significant reasons why I prefer 
the AVR line.  They are inexpensive, the programmers can be very 
inexpensive, and the C toolchain is easily within reach of the hobbyist.


I have $40.00 in PICs and a nice programmer sitting usb programmer for 
them I have never used.  I just can't find the value in jumping back to 
ASM to make use of them.


Jim


___
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list


[avr-gcc-list] Preferred ICE (was: How to force GCC to not to remove nop statements?)

2009-02-19 Thread Graham Davies

David Kelly wrote:
I have a Microchip 1000 or 2000 ICE thingy that cost about $2000 and  was 
used for one project.  Given a choice I much prefer the ECROS

ICE Cube, avr-gcc, and of  course an AVR.


Could I possibly quote that on the User Testimonials page, please?

Now that Atmel have replaced the ATmega16L that the AVR ICE-Cube uses with 
the ATmega16A, when I get through what I have in stock the next batch will 
draw *even less* power from the target.


For those that are not familiar with the AVR ICE-Cube, let me save you a bit 
of research and point out that it is a JTAG ICE clone and only works with 
the small, but very useful, set of devices supported by that debugger 
interface.  It does not support the newer devices for which you need a 
JTAGICE MkII.  But, unlike the AVR Dragon, it does not have a 32 Kbyte 
limit.


Graham.
http://www.ecrostech.com




___
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list


[avr-gcc-list] introducing a new section in data memory

2009-02-19 Thread Parthasaradhi Nayani
Hello all,

I sent a mail on the subject but it seems to have got lost   and therefore 
posting again

I need to have a buffer of about 256 bytes starting at a page boundary in the 
ram of Mega8. To get this I introduced a new section and assigned it an address 
in makefile. I defined variables, to test, using attribute section. However 
when I try to debug the code I see the variables are allotted memory locations 
other than specified in the section? 

My makefile has the following statement

LDFLAGs = -wl,--section-start=.test=0x800100

My .C file has the following statements

unsigned char mem3 __attribute__ ((section(.test)));
int mem5 __attribute__ ((section(.test)));

I have also noticed, if I declare a global variable I get overlap error. Please 
help me solve this problem. Thank you.


Nayani



  ___
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list


Re: [avr-gcc-list] Preferred ICE (was: How to force GCC to not to remove nop statements?)

2009-02-19 Thread David Kelly


On Feb 19, 2009, at 9:44 PM, Graham Davies wrote:


David Kelly wrote:
I have a Microchip 1000 or 2000 ICE thingy that cost about $2000  
and  was used for one project.  Given a choice I much prefer the  
ECROS

ICE Cube, avr-gcc, and of  course an AVR.


Could I possibly quote that on the User Testimonials page, please?


Yes you may. But rather than call it a Microchip 1000 or 2000 ICE  
thingy I checked the closet and its an MPLAB ICE-2000. And appears  
the current price is $1000 but requires external pods or personality  
modules. Its significantly more capable than AVR JTAG as its a full  
emulator that replaces the target MCU. Its just that the software  
(back then) resembled Windows 3.0 and DOS. And turned out some of its  
instruction execution times were not the same as a stand alone chip.


Microchip has/had a ICD which is similar to Freescale BDM and AVD  
DebugWire but consumed some program space. But the ICD executed all  
code with proper timing as it was an enhanced monitor program. As I  
remember in the end I had to use a mix of the two Microchip  
development tools to get the job done.


--
David Kelly N4HHE, dke...@hiwaay.net

Whom computers would destroy, they must first drive mad.





___
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list


Re: [avr-gcc-list] How to force GCC to not to remove nop statements?

2009-02-19 Thread Joerg Wunsch
David Kelly dke...@hiwaay.net wrote:

 Strangely the JTAGICE mkII didn't work on the above hardware where the  
 ICE Cube did. I put a small 50 mA or maybe 100 mA linear regulator on  
 the 3.3V supply and the mkII drew more power off the target than the  
 regulator would provide.

The JTAG ICE mkII cannot be powered from the target circuitry.  It
needs either a separate power supply, or can be powered directly from
USB.

-- 
cheers, Jorg   .-.-.   --... ...--   -.. .  DL8DTL

http://www.sax.de/~joerg/NIC: JW11-RIPE
Never trust an operating system you don't have sources for. ;-)


___
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list


Re: [avr-gcc-list] How to force GCC to not to remove nop statements ?

2009-02-19 Thread Joerg Wunsch
Vincent Trouilliez vincent.trouill...@modulonet.fr wrote:

 Unfortunately I am on Linux so no WinAVR for me ! ;-)

Once I'm done with updating the FreeBSD toolchain (see the other
part of this thread), Bingo600's Linux build script will also
track that as well.

-- 
cheers, Jorg   .-.-.   --... ...--   -.. .  DL8DTL

http://www.sax.de/~joerg/NIC: JW11-RIPE
Never trust an operating system you don't have sources for. ;-)


___
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list


Re: [avr-gcc-list] How to force GCC to not to remove nop statements ?

2009-02-19 Thread Joerg Wunsch
Vincent Trouilliez vincent.trouill...@modulonet.fr wrote:

 lcd.c:96: error: »asm« undeclared (first use in this function)

That's because you are using a -std setting the prevents GCC from
using its extensions by a name (asm) that is in the application name
space, like -std=c99.  Either use -std=gnu99, or (as you already did)
use the implementation namespace counterpart __asm__.

-- 
cheers, Jorg   .-.-.   --... ...--   -.. .  DL8DTL

http://www.sax.de/~joerg/NIC: JW11-RIPE
Never trust an operating system you don't have sources for. ;-)


___
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list


RE: [avr-gcc-list] introducing a new section in data memory

2009-02-19 Thread Parthasaradhi Nayani

--- On Fri, 2/20/09, Weddington, Eric ewedding...@cso.atmel.com wrote:
First off, is that a typo above? It's suppose to be an uppercase
'W' like so:
LDFLAGs = -Wl,--section-start=.test=0x800200

It was a typo. Will test and reply. Thank you for your time. 

Regards
Nayani




  ___
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list