Topic : volatile and gcc in ride

Forum : ARM

Original Post
Post Information Post
July 9, 2009 - 7:45pm
Guest

Hi,

Version used :

- IDE Ride 7.20
- ARM rlink 1.20

Target:

- cortex ST103R

I have followinf code in my main():

vu16 B; (stacked here)
...
BKP_WriteBackupRegister(BKP_DR1,0xBEEF);
B = BKP_ReadBackupRegister(BKP_DR1); ( read here )
BKP_WriteBackupRegister(BKP_DR2,B+1); (use here)
B = BKP_ReadBackupRegister(BKP_DR2); ( reread here)
....

When I debug this code the variable B is never been updated always (0xFFFF) in debug view. When I say never this means with Os, O1 or O2. Most likely this will be OK when having no optimization but that's not the point here.

When I change the stack variable in main to have

static vu16 B; Its OK

When I move the variable to the global variable area it's also OK even without the static keyword.

Maybe I have wrong interpretation of the "volatile" but I expected it to be sufficient when using it on some automatic stack variable to skip compiler optimizations. This is apparently not the case ! I didn't checked the assembler output yet but at least I would like to see the value changed in the debug view.

Can this be a bug or a bad understanding of me ?

Regards
Guy

Replies
Post Information Post
+1
0
-1
July 10, 2009 - 11:20am
Raisonance Support Team

Hi,

'volatile' means it is possible that the variable changes asynchronously from the function flow, so the function should re-read it every time it reads it, and must 'really write it' every time it writes it. volatile does not force the compiler to place the variable in a place where it can be watched by the debugger. 'static' does, as you saw. In fact, the volatile keyword does not mean anything on a local variable, unless you pass the variable's address to a sub-function. To be 100% sure that you will be able to watch a variable it must be volatile, and also either global, or local and static. (even in O0)

Now, what you describe could still be a problem in Ride (or GCC), but for checking that we will need a complete project (with sources, includes, listings, etc.) that shows the problem. Maybe you should take a look at the assembler and if that doesn't answer your questions, send us a project.

Best Regards,

Vincent