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.

Compiler/LAUNCHXL-F28069M: volatile keyword, guideline?

Part Number: LAUNCHXL-F28069M
Other Parts Discussed in Thread: C2000WARE

Tool/software: TI C/C++ Compiler

https://e2e.ti.com/support/microcontrollers/c2000/f/171/t/739348?tisearch=e2e-quicksearch&keymatch=volatile and https://barrgroup.com/embedded-systems/how-to/c-volatile-keyword

In ARM MCU (ie TM4C, 2640R2), it seems to suggest a volatile keyword is a waste of time and not applicable in use.

In TI-RTOS, volatile is not used, do they encourage the use?

In 28x MCU, it seems to suggest it has important relevance, especially when dealing with ISR. 

In other MCU has mixed message about volatile.

I was wondering if there clear guidelines about this topic, some recommendations of use under specific MCU and OS from the TI product range. 

R. 

  • I think that Barr Group article does a pretty good job of listing the guidelines. It really isn't an MCU or OS-specific situation--I know I've needed to use it on ARM devices running TI-RTOS as well as C28x devices with no OS. It's a general embedded programming practice. As the article says, you may not see its effects when you have compiler optimization turned off, but when you turn optimization on, it can be critical.

    If the Barr Group article isn't explaining in a way that's helpful to you, a web search should pretty easily turn up more information. If you still have questions about particular points it makes or specific uses of volatile in our C2000Ware code, I can help explain those though.

    Whitney

  • Thank you for your reply , much appreciated. 

    There so much garbage/discussion about volatile with different viewpoints and solutions in webs and especially books, it hard to estbalished who is actually right. From you, I just learn new that it is optimization dependents :-). 

    Barr Group's article is best I've seen so far. 

    It would be best for me to if you may explain specifically to C2000Ware (with optimization 2,3,4 level). 

    I put all volatile on typedef struct variable (not reg) to keep track of flags and stuff to ensure all correctly modified anywhere in code.

    R. 

  • The compiler guide (http://www.ti.com/lit/pdf/SPRU514) has the details of the different optmization levels in chapter 3. There are some discussions of volatile throughout the document as well.

    It sounds like you're on the right track. Flags that get read/updated in both the background loop and the ISR often do need to be made volatile.

    Whitney