Topic : Ride7 optimization bug ?

Forum : ARM

Original Post
Post Information Post
July 8, 2008 - 4:20pm
Guest

Hello, using Ride 7 (7.01.0002 / RKit 1.03.0004) on a Win XP Pro system, i got a strange bug while compiling the following code :

--- start ----
#include "71x_lib.h"
u32 T;

int main()
{
// PLL Config
RCCU_Div2Config (DISABLE); // enable input divider
RCCU_PLL1Config (RCCU_PLL1_Mul_16,RCCU_Div_1); // 64MHz(1) //32MHz(2)
while(RCCU_FlagStatus(RCCU_PLL1_LOCK) == RESET)
{
/* Wait for PLL to lock */
}
RCCU_RCLKSourceConfig (RCCU_PLL1_Output); // select PLL1 clock
RCCU_MCLKConfig (RCCU_Div_1); // disable divider
RCCU_PCLK1Config (RCCU_Div_2); // Serial interfaces clock
RCCU_PCLK2Config (RCCU_Div_2); // IO,ADC,Timer,Watchdog clock

// GPIO Config
GPIO_Config(GPIO1,(1<<8),GPIO_OUT_OD); // PORT 1 pin 8

while(1)
{
GPIO_BitWrite (GPIO1,8,1);
for(T=0;T<100;T++);

GPIO_BitWrite (GPIO1,8,0);
for(T=0;T<100;T++);

}
}
--- end ---

Compile and run OK when optimization is disabled, but as soon as i enable optimisation (any level), the code still compile, but won't run properly.

Let me explain : when optimization is enable, the software won't enter the FOR loops, and the GPIO is toggling way too fast. I know for sure, as i checked the GPIO with an oscilloscope, and i also checked with NOICE, and the FOR loops are never entered.

Once again, disabling optimisation (with ALL other settings being the same) instantly makes the code run properly.

Any ideas ?

Regards,
Dave

Replies
Post Information Post
+1
0
-1
July 8, 2008 - 7:22pm
Guest

It seems to be an expected behavior (the optimizer just does its job).
A workaround consists in doing something that cannot be optimized in the loop. Typically, you could call an external function.
If you need to wait for an exact delay, you must use a timer (if not, you code will be dependent on the version of the compiler).

+1
0
-1
July 9, 2008 - 9:46am
Guest

I think it's a normal behavior since the T variable is not declare as volatile.
So if you declare this variable as volatile your code should work correctly.
Rgds

+1
0
-1
July 9, 2008 - 3:21pm
Guest

Thank you, you were right, declaring variable T as volatile did the trick.

I'm just an EE who's trying to run some test code before handling the project to some 'real' software guy (not found yet...)

Best regards,

Dave