Hello everyone,
I’m facing an issue with real-time variable monitoring while debugging with VS Code and PlatformIO. My setup is a Blue Pill STM32 board programmed using the Arduino framework, and I’m using an ST-Link debugger.
Problem:
- I can’t view variable values in real-time while the program is running. I need to pause the execution to see the values, which is inconvenient for my application involving an optical encoder.
- When using the “WATCH” feature in the debugger, it shows “not available” during runtime, but values appear once I pause the execution.
What I’m Trying to Achieve:
- I want to debug and read variable values in real-time without pausing the program, similar to using
Serial.print
.
Here’s a snippet of my basic code for context:
const int encoderPinA = PB10; // Pin with interrupt
const int encoderPinB = PB11; // Second pin without interrupt
const int ledPin = PC13; // Built-in LED on Blue Pill
volatile int encoderValue = 0;
volatile bool wasTurned = false;
void handleEncoder() {
int A = digitalRead(encoderPinA);
int B = digitalRead(encoderPinB);
encoderValue += (A == HIGH) ? ((B == LOW) ? 1 : -1) : ((B == HIGH) ? 1 : -1);
wasTurned = true;
}
void setup() {
HAL_Init();
Serial.begin(9600);
pinMode(encoderPinA, INPUT_PULLUP);
pinMode(encoderPinB, INPUT_PULLUP);
pinMode(ledPin, OUTPUT);
attachInterrupt(digitalPinToInterrupt(encoderPinA), handleEncoder, CHANGE);
}
void loop() {
if (wasTurned) {
digitalWrite(ledPin, HIGH);
delay(100);
digitalWrite(ledPin, LOW);
delay(100);
wasTurned = false;
}
Serial.println(encoderValue);
}```
Here’s my platformio.ini configuration:
```platform = ststm32
board = bluepill_f103c8
framework = arduino
upload_protocol = stlink
debug_tool = stlink
debug_extra_cmds =
monitor reset init
monitor halt
set breakpoint pending off
continue
debug_init_break = tbreak setup```
How can I achieve real-time feedback for variable values using an ST-Link debugger in this setup? Any advice or workarounds would be greatly appreciated!
Thanks in advance for your help!