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

Post Reply
Dylan Hsieh
Posts: 31
Joined: 22 Mar 2017, 09:54

29 Mar 2017, 10:30

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:


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:

Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 1 guest