Attaching debugger to Marlin (to inspect vars, set breakpoints, step through, etc...)

Curious if anyone’s using VS Code (on Windows), or something else (STM Cube IDE? ) to attach a debugger to debug Marlin? Trying to figure out whether stlink, jlink, jtag or something else should be used.

Looks like debugger dongle should be attached to SWDIO header.

SWDIO header on SKR Pro 1.1/1.2 Schematic
image

SWDIO header on Octopus V1.1

Am digging around Marlin repo, and YouTube, but figured some curious folks here are already doing this… Any pointers appreciated. Cheers!

I’ve never liked debuggers, but I know a lot of people live by them. Just curious what you are trying to do? A lot of the worl from Marlin is done in real time and a lot of the stepping is done in interrupts.

Should work for the main logic though.

Mainly trying to understand the code structure better, when possible stepping through helps me grasp what’s going on better than just reading and skipping around the code base. Stepping through new/modified code is always helpful.

I appreciate debugging some areas (interrupt/time-sensitive) will be invasive/disruptive to functionality and will probably be better understood by maybe temporarily adding a bunch of SERIAL_ECHO messages to generate debug spew to console or SD file? This is my plan B if a debugger dongle is required. I have a ESP Programmer board that can be used to debug ESP32 via JTAG, no idea if that can be used for SWDIO as well, I need to ST*W more…

Curious if there’s some other approach folks use when modding firmware?

Related commands:
Start SD Logging | Marlin Firmware Start SD Logging
Stop SD write | Marlin Firmware Stop SD Write
Debug Level | Marlin Firmware Debug Level, get/set
Debug Pins | Marlin Firmware Debug Pins, list/watch pins

1 Like

Most of my development is on linux, in C++. So I use a lot of log statements and record data for plotting. Maybe I am weird :slight_smile:.

There is a HAL for linux/sim in Marlin. That might be easier to learn the common Marlin code.

1 Like

Yeah, writing code that spews intentionally considered traces/logs containing the right amount of context rich information has helped me/colleagues too. On the other hand, have seen mindlessly coded tracing kill performance, and functionality even.

Logs/traces are required to debug Dev, and Production scenarios. If you’re weird, it’s not because of using log statements, probably :slight_smile:

1 Like