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.

C2000-CGT: ti-cg-c2000_20.2.5.LTS optimises variable when optimisations are disabled

Part Number: C2000-CGT
Other Parts Discussed in Thread: TMS320F280049C

Hi,

I am trying to define some data in memory using the #pragma PERSISTENT.

e.g. 

#pragma PERSISTENT(bootloaderVersion)
const version_t bootloaderVersion = {
.major = MAJOR_VERSION,
.minor = MINOR_VERSION,
.patch = PATCH_VERSION,
.build = BUILD_NO,
.sha = SHA_NO
};

If i don't use this variable anywhere in the code, the values are not stored in flash.

However, if I add something like

if (bootloaderVersion.major == MAJOR_VERSION) {

  /// dummy code

}

Then the memory gets initialised correctly.

Is there any clean way of telling the compiler not to optimise that away? 

Thank you