How to configure VS Code to build and debug STM32 projects using cubeMX - Windows 10

clixxclixx picture clixxclixx · Jul 18, 2018 · Viewed 22k times · Source

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

Answer

Bence Kaulics picture Bence Kaulics · Jul 19, 2018
  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.