2025-05-29 1:16 PM - edited 2025-05-29 1:21 PM
Here's my infinite loop in a cpp file
#include "main.h"
#include "lib.hpp"
void run() {
auto cnt = 0u;
while (1) {
if(!HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_13))
cnt++;
}
}
I run the Debugger and execute the statements until I get to the "if" statement above then when pressing F6 another time the execution stops waiting to read the value of pin 13 (the blue button on the board). But while I have also added "cnt" onto the "live expressions" its value doesn't go beyond 0 even though I press the button couple of times.
My purpose is to see the value of "cnt" after pressing the button no matter how much it is.
Solved! Go to Solution.
2025-05-30 11:34 AM
>> NUCLEO-F411RE board?
Yes, sorry for the inconsistency.
I exactly did the following step-by-step:
1- Run debugger
2- Hit F8 (Resume)
3- Press the blue button a few times
4- Pause the execution
Still no change in the value of `cnt` in the "live expressions". (It's blank)
Have you tested this on your board?
2025-05-30 2:14 PM
Apparently the problem is with `cnt` being a local variable. When I make it global, i.e., declared before `void run() { }` it works properly and Live Expressions shows a big number for it after pressing the button even only once.
2025-06-02 2:00 AM - edited 2025-06-02 2:11 AM
That's another issue with using "Live Expressions" - the things you're watching need to be permanently visible.
Making it static (but still local) might work;
Making it static at file scope should work ...
PS:
This is not specific to C++
The same would apply to plain C.
#LiveExpression #GlobalData
2025-06-02 2:10 AM
@STTwo-32 perhaps this is something which needs to be made clearer in the UM?