[D-Flash] How to set initial value

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

[D-Flash] How to set initial value

Jump to solution
566 Views
Pogo
Contributor III

Hi, 

I want to set a const variable with initial value in D-Flash segment and use this variable in some funtion. But if I set this variable with initial value and use it in other function. When I change this variable using writing D-Flash with user's input, this variable will not change. I checked the complier code, all code which using this variable will replace by the initial value. The following example code will express my issue.

#pragma DATA_SEG __EPAGE MYDFlashconst unsinged int uVariable = 10;#pragma DATA_SEG DEFAULTvoid main(void){   if( uVariable == 10 )  //<-- this line complier will not use uVariable, it will use 10      printf("OK");   WriterToDFlash();   if( uVariable == 5 )  // same above      printf("ok");   else      printf("write to D-flash failed");}void WriteToDFlash(){   //Write 5 to uVarialbe's address}

The run result will be

OK

write to D-flash failed.

My expection is OK and OK.

My question is how can I tell to complier don't using const value to replace variable and just use the value in varible's address. Please help me! Thanks a lot.

 

Pogo

Labels (1)
0 Kudos
1 Solution
353 Views
kef
Specialist I

If I understand your request

 

1) use volatile keyword, like volatile const int var;

2) Go to compiler options and check "Disable CONST variable by constant replacement" optimization.

3) move variable definition to different source file. When compiling different source files, where variable is just declared, compiler won't see variable initializer and won't replace variable access with constant.

View solution in original post

0 Kudos
2 Replies
354 Views
kef
Specialist I

If I understand your request

 

1) use volatile keyword, like volatile const int var;

2) Go to compiler options and check "Disable CONST variable by constant replacement" optimization.

3) move variable definition to different source file. When compiling different source files, where variable is just declared, compiler won't see variable initializer and won't replace variable access with constant.

0 Kudos
353 Views
Pogo
Contributor III

Hi kef,

Thanks a lot.  

 

 

Pogo

0 Kudos