I am a first-year student majoring in Electronic Information Engineering. Currently, I am self-studying microcontrollers. One day, while browsing Bilibili, I came across a video on developing STM32 with VSCode: https://www.bilibili.com/video/BV1nr4y1R7Jb/?vd_source=e836ee461d07a48f2161731d0ca031f0. I found it very interesting, so I tried to set up the environment myself according to the tutorial in the video.
(1) Download VSCode#
First, download VSCode; you can find it by searching for VSCode online.
Click to download and you can install it.
(2) Download Extensions#
After downloading VSCode, we need to download several extensions, which are the ones outlined in the box below. The other plugins should be bundled with these, totaling 12 extensions.
I also added a bookmark extension, which is helpful for viewing code.
(3) Install Utility Tools#
Install the following three utility tools:
(4) Configure Compiler Path#
Like in the video, I have developed STM32 projects with Keil, so I can find two compilers in the folder below.
Keil is in the learning materials under Jiangxie’s video:
https://www.bilibili.com/video/BV1th411z7sn/?spm_id_from=333.1007.top_right_bar_window_custom_collection.content.click&vd_source=e836ee461d07a48f2161731d0ca031f0
Then open the settings of the EIDE plugin in VSCode and add the paths of the two files.
(5) Import Project#
Next, we import the project created with Keil. This project was created while I was studying Jiangxie’s STM32 tutorial, so I will import this one directly.
Import the project.
Select MDK.
Select ARM (later I tried compiling for the 51 microcontroller and found that selecting the one below works).
Find the project file.
Choose to place it in the same folder.
The project is now imported.
(6) Add Chip Support Package and Programming Configuration#
Click to add the chip support package, select the option to add the offline support package below. The offline support package is from Jiangxie’s video, so I added it directly.
After installation, you also need to select the specific chip model; otherwise, it cannot be compiled.
Next, configure the programming settings. We choose openocd; my programmer is ST-Link, so there’s no need to change the interface configuration.
(7) Compile and Program#
Once everything is configured, we are ready to compile.
First, we need to open the plugin settings, search for elf, and check the box to convert alf to elf.
Then we open the builder options, click on the linker, and uncheck the option to not generate HEX; we want to generate it.
Now we can compile.
A lot of green text will appear, and if this appears at the end, it means success.
Then programming can proceed.
(8) Debugging#
The debugging in the video is directly accessible by clicking on the debug page, but when I clicked, I found there were no matching options, so I had to explore the debugging configuration myself.
First, we click on the debug page to create a launch file.
Find the openocd debugging configuration.
Next, modify these two items. The executable is the path of the file; you can find where your compiled .elf file is located and paste its path here. I found some information here, knowing that the project folder path can be replaced with a “.”, and “\” is used for Windows file paths, while “/” is used for Linux file paths. However, there is no difference here; it’s just that “\” needs to be typed one more time.
The effect looks like this.
Then we need to configure configFiles. I searched for a long time to figure out how to configure it (many articles online just gloss over it). Here we need to configure the interface and chip files; you can copy the format from the internet, and the names of the interface and chip files can be copied from the programming configuration. The effect looks like this.
Finally, select the openocd debugging mode to debug.
So, this is how to set up the STM32 development environment using VSCode and the EIDE plugin. I originally didn't plan to write this, but a few days ago, while learning how to create a GitHub repository, I encountered some issues that caused me to lose all my previous templates, so I had to redo it. During the process, I felt inspired to write this as my first blog post.