This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMS320F28075 Odd Behavior using compiler optimizations.

I am currently using an F2807x Control Card with a dock for evaluation purposes and have been noticing some strange behavior when using compiler optimizations. Running the following code with no optimizations, the variable g_test increments as expected.  However, when setting "Optimization level" to "2 Global Optimizations", the variable remains 0.  My first assumption was that the optimizations were restricting debug capabilities.  However, I tried replacing the code with toggling GPIO's and once again, the GPIO's toggled when optimizations were off and stopped toggling when optimizations were on.  It appears that the processor never makes it to the while loop, but I can't seem to figure out why.  Any pointers would be appreciated.  (I am using compiler TI v6.4.3 on Code Composer Version 6.1.1.00022)

Uint32 g_test = 0;


void main(void)
{
   InitSysCtrl();

  while(TRUE) {
    g_test++;
  }
}

  • When I compile that with 6.4.3, I get an empty forever loop in place of the while loop, so there is actually a loop there. It's empty because the optimizer knows that this function is main, so it thinks there are no other functions to read the global variable g_test. Thus, the value of g_test is unused, and it does not need to bother to set it. If you really want it to be incremented, make it volatile.