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: