Page 1 of 1

Why is the observed variable displayed as “not in scope” in Debug mode under the Keil development environment?

Posted: 29 Mar 2017, 10:30
by Dylan Hsieh
When interrupted in Debug mode, the user wants to check the variable value but see ”not in scope” on the Watch window, as shown below:

Image

This is because the compiler would put variables into R1 registers after optimization, but the Watch window could only get the value from the internal memory. Therefore, “not in scope” will be displayed.

There are three solutions:
  • Set the variable as a global variable.
  • Set the variable as volatile.
  • Set ”Optimization“ of ”C/C++” in the ”Options for Target…” as ”Level 0 (-O0)”, as shown below:
Image