14

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 IDE's like Keil and IAR but the cost of buying them just to learn is far to steep for me at this point in time.

I have started using VS Code for a growing amount of my development work and I though 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,

I was wondering if there is anyone that can point me to a complete setup guide on how to set up VS code to work with cubeMX and the arm tool-chain, or if you are feeling really kind, send me a sample project that I can use as a base learn from.

Just some background information, I know how to use cubeMX to generate the base project as well as the associated makefile, I also have the latest GNU-Tools-Arm-Embedded installed.

Thank you in advance for your help

Bence Kaulics
  • 7,066
  • 7
  • 33
  • 63
clixxclixx
  • 147
  • 1
  • 1
  • 7
  • 1
    While I don't have details regarding VS Code in conjunction with STM32, have you thought of Atollic TrueSTUDIO? It's based on Eclipse, actively supported by ST and CubeMX should generate ready projects for it. And most importantly - it's free. – J_S Jul 18 '18 at 06:24
  • I have not heard of this, I will definitely check this option out as well then, thank you very much. – clixxclixx Jul 18 '18 at 12:17
  • What have you tried? What was not working? I don't use VS Code, but setting compiler to gcc-arm-none-eabi, pointing include and source dirs with CMSIS, HAL, and LL, and defining linker script should be enough. [Here](https://github.com/ObKo/stm32-cmake) is a CMake based version I use in Emacs. – pan-mroku Jul 19 '18 at 12:05
  • I know this is an old topic, and I like VSC a lot but for this purpose, a free package that works just out of the box is SW4STM32: https://www.openstm32.org/HomePage. In the cubeMX set the toolchain for it and it just compiles easy. Also has a strong debugging tool, trust me you gonna need them. – anishtain4 Apr 30 '20 at 17:48

4 Answers4

11
  1. Install GNU Arm Embedded toolchain and add its bin folder to your PATH environment variable.
  2. You will also need a make to execute your makefiles so download Make for Windows. 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.
  3. Create an STM32CubeMX project and select Makefile as Toolchain/IDE. enter image description here
  4. At this point you will be able to build the generated project by simply using make in the project's root folder.
  5. If you open the project in VS Code you can build using its terminal or you can create a VS Code task to execute the make command. You can bind your task to a hotkey as well to spare some time.
  6. To debug, the easiest way is to install Cortex-Debug VS Code extension. Follow the instructions to configure your debug sessions.
Bence Kaulics
  • 7,066
  • 7
  • 33
  • 63
  • This comment was also a large help thank you, this in combination with the answer that I checked makes up the full solution. I just can check both off. – clixxclixx Jan 13 '22 at 17:29
  • @clixxclixx That is alright. What important is that you could solve it and came back to accept an answer after more than 3 years. Not many do that. :) Your question was a great hit anyway with more than 30k views, great contribution. – Bence Kaulics Jan 14 '22 at 13:44
8

A while ago I had the same question, but did not find anything that I really liked. So I created STM32 for VSCode, it is an extension for VSCode which works with STM32CubeMX generated files and sets up building and debugging for you.

Jort
  • 96
  • 1
  • 1
  • I tried this extension, however it did not work. Seems that toolchain installation fails. – Creek Drop Jan 12 '22 at 22:23
  • @CreekDrop the automatic toolchain installation didn't work for me either, but installing GNUWin, OpenOCD and the arm toolchain manually and adding them to PATH made the extension start properly. – Klickmann Jan 26 '22 at 10:39
1

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.

VSCode STM32 IDE

The process is quite straight forward:

  1. Export the files using STM32CubeMX
  2. Cpen the VSCode folder and save it as workspace
  3. Copy the scripts "ideScripts" directory to your project folder
  4. Run update.py

Here is a video on how it works:

VSCode STM32 IDE - Getting Started

Ali80
  • 6,333
  • 2
  • 43
  • 33
0

There is already very good answer by @Bence Kaulics, based on it add my recent findings.

  1. make command somehow did not work for me in VS Code Terminal. To solve this I installed "Makefile Tools" extension from Microsoft.
  2. instruction link does not work, therefore I add steps how to configure debugging for J-Link.

-> Install Cortex-Debug Extention. -> Download and install J-Link Software from Segger. -> Get SVD file if you want to see peripheral registers. -> Edit launch.json file (see 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",
        }
    ]
}
Creek Drop
  • 464
  • 3
  • 13