[Top][All Lists]

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

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

From: Vincent Trouilliez
Subject: [avr-gcc-list] How to force GCC to not to remove "nop" statements ?
Date: Thu, 19 Feb 2009 19:01:34 +0100

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

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



reply via email to

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