cancel
Showing results for 
Search instead for 
Did you mean: 

CubeIDE - debugging - LiveExpression - Function variable

Viktor_Sawtschenko
Associate II

Hello community,

I just started to work with CubeIDE.

CubeIDE offer a functionality to watch the variables during debugging in the LiveExpression-TAB.

My issue is, that I don't know how to watch the variables defined in functions:

Eg: Variable i inside function , see second picture.

 

 

static void f1(void){
	int i = 3;
	HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, 1);
	HAL_Delay(500);
	HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, 0);
	HAL_Delay(500);
}

 

 

Viktor_Sawtschenko_0-1733078904129.png

Thanks in advance for any support you can offer.

 

4 REPLIES 4
STM_Thirty2
ST Employee

Variables declared inside a function are local to that function, meaning they exist only while the function is active (on the call stack) and are destroyed when the function exits. Due to this limited scope, watching them in the Live Expressions tab can be challenging.

The Live Expressions feature in STM32CubeIDE is designed primarily to track variables or symbols with a global or static scope that persist throughout the program execution. For local variables, you can still inspect their values while the function is executing by pausing execution and checking the Variables tab or adding them temporarily to the Expressions tab.

If the variable needs to be monitored continuously, consider using a global or static variable as a workaround. This allows the variable to persist beyond the function's execution and can then be easily tracked in the Live Expressions tab.

If you feel a post has answered your question, please click "Accept as Solution"

Hello STM_Thirty2,

thanks a lot for your support!

I created a global Struct 'Person'.

But still can't acess the struct in debug-mode via LifeExpression.

What am I doing wrong?

Viktor_Sawtschenko_0-1733174037756.png

 

STM_Thirty2
ST Employee

The struct object is global but your p1 is still a local variable you made it in the main function. This will still work through the life of your program because technically the program always be in the main function , so your issue now is probably you are not really doing anything with p1 , so the compiler is optimizing it out. 

try this:

 

volatile struct Person p1;

 

Additionally make sure you have live expressions enabled:

STM_Thirty2_0-1733200491334.png

 

 

If you feel a post has answered your question, please click "Accept as Solution"

STM_Thirty2,

thank you very much for your help, now it works!