'Problem understanding cortex-debug configurations in Visual Studio Code (STM32)
I'm currently trying to get a better understanding of the embedded toolchain by leaving the common out-of-the-box IDEs and create my own inside of Visual Studio Code.
With the help of some tutorials I managed to get my blinky LED project for an STM32L433 Nucleo board up and running.
The last step I had to do was implementing the debug functionality. As I only did this via an IDE in the past this part is a bit tricky for me. Nonetheless I managed to get it work but I still have some problems of wrapping my head around what is actually going on.
Therefore I hope you guys can help me get a better understanding of this.
Im using Visual Studio Code with the C/C++ and Cortex-debug extensions. Hardwarewise I'm using a STM32L433 Nucleo-Board with the build in ST-Link debugger probe.
I created my project in VSC and created a launch.json for the debug settings, it looks like this:
{
"version":"0.2.0",
"configurations": [
{
"name": "Cortex ST-Link",
"cwd": "${workspaceRoot}",
"executable": "./build/Test.elf",
"request": "launch",
"type": "cortex-debug",
"servertype": "stlink",
"stlinkPath": "D:/CubeIDE/STM32CubeIDE_1.8.0/.../bin/ST-LINK_gdbserver.exe",
"stm32cubeprogrammer": "D:/CubeProgrammer/bin",
"device": "STM32L433RC",
"configFiles": [
"interface/stlink.cfg",
"target/stm32l4x.cfg"
],
"svdFile": "STM32L4x3.svd"
},
{
"name": "Cortex Debug",
"cwd": "${workspaceRoot}",
"executable": "./build/Test.elf",
"request": "launch",
"type": "cortex-debug",
"servertype": "openocd",
"device": "STM32L433RC",
"configFiles": [
"interface/stlink.cfg",
"target/stm32l4x.cfg"
],
"svdFile": "STM32L4x3.svd"
}
]
}
Both configurations work, I don't know if this is the right/professional way to do this but this is all I found from examples and the Cortex-debug documentation. If I did something wrong, please tell me what I should do differently.
What I learned thus far regarding Debugging is the following:
- I need a debugging probe that can communicate with the debug access port of my MCU.
- I need a GDB server that handles communication between the debugger and my PC.
- And I need a client tool that connects to the GDB server and gives me an interface to read and write debug instructions and informations.
So lets start with the OpenOCD configuration. The used debugger is the st-link from the nucleo board. My GDB server would be OpenOCD and my client is the arm-none-eabi-gdb utility if I get this right from the debug console. I use the stlink.cfg to tell the server which debugger I use so it knows how to communicate with it. Is this correct this far?
Next the ST-Link config. Instead of OpenOCD I now use the ST-Link-GDB server. And for the client again the arm-none-eabi-gdb. But when I start to execute it like this, the ST-Link-GDB server throws an error that it can't find the STCubeProgrammer utility. So I also give the path to this utility and it works. My question now is, what is the CubeProgrammers role in this chain? I obviously doesn't need an additional component with OpenOCD, so why do I need the CubeProgrammer? I firstly thought that the CubeProgrammer is the client in this case but I can see that arm-none-eabi-gdb still gets called in this debug config. Even ST's GDB userguide only shows the server, debugger and client and no programmer in the overview...
Can someone help me understand what is going on behind the scene and what the role of the CubeProgrammer is? Or maybe point out if I have some false configuration/understanding in this matter?
Thanks in advance :)
Best regards
Evox402
Solution 1:[1]
Yes, for ST-Link server you do need to specify the path to the programmer and it is rather complicated, especially on Linux/Mac. Why that is not just built in is something I don't get. There have been some changes to cortex-debug to autodetect but it can be confusing when you have multiple versions of the ST software included.
You can explicitly specify which programmer to use using the "cortex-debug.stm32cubeprogrammer" User/Workspace setting or in the launch.json.
Hint: You can see the path to the programmer in Eclipse if you look at the Debug Configuration and click on the "Show Command" (or something like that).
If you are using OpenOCD, then try to use the one distributed by ST and not something from the Internet.
Your other question? What is the difference between STLink and OpenOCD. The feature set is different, but you might not notice that using VSCode.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | bluefox |
