This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Complier V6 optimization problem

Dear All,

 

I have been using arm complier V5 for a couple of years and it works very good actually. I finished one complete project using V5 -O3 optimization level. However, I started new project and I would like to use V6. I read some notes like how to migrate or what should I consider when I write C code which will be complied V6.  I developed a very simple code just blinking a LED. It is "Hello World" code and it should work.  However, it doesn't work V6 with any optimization level except -O0. I complied the code again with V5 -O3 and -Otime and it worked well.

Let me write my simple code and then explain what happens:

-----------------------------

Counter = 0;

 while (1)
  {
        if (Counter < 5)
        {
            GPIOD->BSRR = GPIO_PIN_5;               // Output is set and LED should give light.
         }
        else
        {
            GPIOD->BSRR = (uint32_t)GPIO_PIN_5<< 16  ;              // Output is set and LED should give light.
        }
        if(Counter > 10)
        {
            Counter = 0;
        }    
  }

//************************************************************************
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)    // Timer 3 Interrupt subroutine It hits every 100ms.
{
    if(htim == &htim3)
    {
        Counter++;
    }
}

-------------------------------------------------------------------------------------

Counter increments every 100ms with Timer-3 interrupt in the related interrupt subroutine. So, every 500ms LED should be gives light and turn off again. However, it is continuously gives light and never turn off. I think that the complier optimizes the code and Counter is zero at the beginning and it never changes in While(1) loop. So the complier decided Counter won't be greater than 5 so no need to compile remaining code and it only builds “GPIOD->BSRR = GPIO_PIN_5;” line. If I change "if condition" that Counter is greater than 5 then the complier takes only "GPIOD->BSRR = (uint32_t)GPIO_PIN_5<< 16  ;   " this line and removes others. So, this time LED stays off...

I complied with V6 -O0 and it worked but -O1,-O2,-Oz etc... it doesn't work. It works V5 -O3 with -Otime. So, what should I do? Is there any option that I don't know?

Most of my code run inside interrupt subroutines. Many variables are changed inside these subroutines and they are used in main loop which are not time critical. So, if V6 removes all my code like mentioned above I cannot use V6. I don't except that Arm made this kind of mistake. I am sure there are options that I haven't known yet.

 

Please help me about the issue.

 

Best Regards

 

 

 

Parents Reply Children
No data