Reputation: 197
I am new to the realm of STM32 programming and have been trying to find a suitable IDE for quite a while now. I know of all the other IDEs, like Keil and IAR, but the cost of buying them just to learn is far too steep for me at this point in time.
I have started using Visual Studio Code for a growing amount of my development work and I thought it would be a good IDE to use for STM32 development. I have found many examples online over the past few days on how to configure the IDE to build STM32 projects, but they all seem to be missing important information that I need to properly get the project to compile. It is rather frustrating,
Is there a complete setup guide on how to set up Visual Studio Code to work with STM32CubeMX and the ARM toolchain? Or is there a sample project that I can use as a base learn from?
Just some background information, I know how to use STM32CubeMX to generate the base project as well as the associated makefile, I also have the latest GNU-Tools-Arm-Embedded installed.
Upvotes: 18
Views: 47466
Reputation: 594
There is already a very good answer by Bence Kaulics. Based on it, I add my recent findings.
The make
command somehow did not work for me in Visual Studio Code Terminal. To solve this, I installed "Makefile Tools" extension from Microsoft.
The instruction link does not work, and therefore I add steps how to configure debugging for J-Link.
Install the Cortex-Debug extension. Download and install the J-Link software from Segger. Get the SVD file if you want to see peripheral registers. Edit the launch.json file (see the code below). Set your executable, paths and device.
{
"version": "0.2.0",
"configurations": [
{
"cwd": "${workspaceRoot}",
"executable": "./build/STM32F103RBT6_Test1.elf",
"name": "Debug Microcontroller",
"request": "launch",
"type": "cortex-debug",
"servertype": "jlink",
"serverpath": "C:/Program Files/SEGGER/JLink/JLinkGDBServerCL.exe",
"armToolchainPath": "C:/Program Files (x86)/GNU Arm Embedded Toolchain/10 2021.10/bin",
"device": "STM32F103RB",
"interface": "swd",
//"serialNumber": "", // If multiple debuggers attached
"runToMain": true,
"svdFile": "${workspaceRoot}/device/STM32F103xx.svd",
}
]
}
Upvotes: 1
Reputation: 106
A while ago I had the same question, but I did not find anything that I really liked. So I created STM32 for Visual Studio Code. It is an extension for Visual Studio Code which works with STM32CubeMX-generated files and sets up building and debugging for you.
Upvotes: 9
Reputation: 7271
Install GNU Arm Embedded toolchain and add its bin folder to your PATH environment variable.
You will also need a make
to execute your makefiles, so download Make for Windows. The easiest way is to download the binaries and extract it somewhere on your system. Add it (C:\make-3.81-bin\bin
) to your PATH as well.
Create an STM32CubeMX project and select Makefile
as Toolchain/IDE.
At this point, you will be able to build the generated project by simply using make
in the project's root folder.
If you open the project in Visual Studio Code, you can build using its terminal or you can create a Visual Studio Code task to execute the make
command. You can bind your task to a hotkey as well to spare some time.
To debug, the easiest way is to install Cortex-Debug Visual Studio Code extension. Follow the instructions to configure your debug sessions.
Upvotes: 11
Reputation: 8676
There is a library of Python scripts that does just this. It has been released recently with excellent documentation and after testing I can say it works as advertised.
The process is quite straightforward:
"ideScripts" directory
to your project folderHere is a video on how it works:
Visual Studio Code STM32 IDE - Getting Started
Upvotes: 1