cancel
Showing results for 
Search instead for 
Did you mean: 

Debug a basic C++ program on STMCube IDE

TechyAry
Associate II

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.

 

13 REPLIES 13
TechyAry
Associate II

@Andrew Neil 

>> NUCLEO-F411RE board?

Yes, sorry for the inconsistency. 

@TDK 

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? 

TechyAry
Associate II

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.

 

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

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.

@STTwo-32 perhaps this is something which needs to be made clearer in the UM?

AndrewNeil_1-1748855167589.png

 

 

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.