AnsweredAssumed Answered

volatile variables and "functions"

Question asked by karpavicius.linas on Nov 20, 2014
Latest reply on Nov 20, 2014 by Ivan Ivanov
Hello,
i am running compile (IAR AMR) in highest optimization settting, but sometimes it does ignores my code, or even functions that does have purpose;

as example, DataRx[] is loaded by DMA with data from computer, and it is used for triggering ( software based), 160 is free running mode, 168 is external trigger
if((DataRx[0])==168)
{
  while((GPIOA->IDR&GPIO_Pin_3)==0)
  {
    if(DataRx[0]==160)
    {
      break;
    }
  }
}

if i use uint8_t as my variable, this code is ignored, adding volatile uint8_t does solve problem, but then, compiler states that is problem in my other code ( but it works)
A_offset=DataRx[2]+(DataRx[3]<<8);
D_offset=(DataRx[4]+(DataRx[5]<<8))&1023;
integration=DataRx[6]+(DataRx[7]<<8);
error code says for all lines:
Warning[Pa082]: undefined behavior: the order of volatile accesses is undefined in this statement

any idea how to tell compiler, that it must execute my trigger code, or should i move this code to outside main(), and create volatile function ? ( just tryed, it does work, but i should know what kind of programming error i am creating)


Outcomes