Hi @simmania ,
Thank you so much for your interest in our products and for using our community.
Question: In the demos of the MIMXRT1010 all global variables seem to be preceded by the 'volatile' keyword. And sometimes also the 'static' keyword. Why is that? These are global variables, not hard ware registers. And MIMXRT1010 has only one core (demos are written for one core anyway), so no problem if the value stays in cache. So why are these keywords needed?
Answer: Please see the explain these two 'volatile' and 'static' keyword
1: "static" keyword: It is used for limiting the scope and maintaining the variable value.
2: "volatile" keyword: Even though the MIMXRT1010 has only one Arm Cortex®-M7 Core, It is still need use "volatile" keyword.
a: The global variables may be changed in interrupt ISR. In this case, "volatile" keyword is needed.
b: As you said these are not hardware registers, but it still need "volatile" keyword, because global variables may be used as an indirect means of interacting with hardware, for example, through memory-mapped I/O ,and so on.
c: If you use FREERTOS or other RTOS , global variables shared with multi tasks, In this case, "volatile" keyword is needed.
Question: I ask this because I like to understand the code. But also when I put these keywords before some of my own global variables (that are structures) and I use a pointer to them, I get warnings.
Answer: It might be because pointer operations do not compatible with the semantic definition of keyword volatile.
Wish it helps you.
If you still have question about it, please kindly let me know.
Best Regards
mayliu