ashwatermelon

ashwatermelon

[Learning Notes] Setting up STM32 development environment with vscode + EIDE plugin and successfully debugging

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 by following the tutorial in the video.

(1) Download VSCode#

First, download VSCode; you can find it by searching for VSCode online.
image
Click to download and install.

(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.
image
I also added a bookmark extension, which is helpful for viewing code.
image

(3) Install Utility Tools#

Install the following three utility tools:
image

(4) Configure Compiler Path#

As in the video, I have developed STM32 projects using Keil, so I can find two compilers in the folder below.
image
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.
image

(5) Import Project#

Next, we import the project created with Keil. This project was set up while I was learning Jiangxie’s STM32 tutorial, so I will directly import this one.
image
Import the project
image
Select MDK
image
Select ARM (later I tried compiling for the 51 microcontroller and found that selecting the one below works)
image
Find the project file
image
Choose to place it in the same folder
image
This completes the project import.

(6) Add Chip Support Package and Programming Configuration#

image
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.
image
image
After installation, you also need to select the specific chip model; otherwise, it cannot be compiled.
image
Next, configure the programming settings. We choose openocd; my programmer is an ST-Link, so there’s no need to change the interface configuration.

(7) Compile and Program#

Once all configurations are complete, we are ready to compile.
image
First, we need to open the plugin settings, search for elf, and check the box to convert alf to elf.
image
Then we open the builder options, click on the linker, and uncheck the option to not generate HEX; we want to generate it.
image
Now we can compile.
image
A lot of green text will appear, and if this appears at the end, it is successful.
image
image
Then programming can proceed.

(8) Debugging#

The debugging in the video is directly accessible by clicking on the debugging page, but when I clicked, I found that there were no corresponding options, so I had to explore the debugging configuration myself.
image
First, we go to the debugging page to create a launch file.
image
Find the openocd debugging configuration.
image
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 searched for some information and learned that the project folder path can be directly written as “.” to replace it. Also, “\” is used for Windows file paths, while “/” is used for Linux file paths. However, there is no difference here; it’s just that “\” requires an extra character.
image
The effect looks like this.
image
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 any article online, and the names of the interface and chip files can be copied from the programming configuration. The effect looks like this.
image
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 hadn't planned to write this, but a few days ago, while learning how to create a GitHub repository, I encountered a problem that wiped out all my previous templates. I had to redo everything, and during the process, I felt inspired to write this as my first blog post.

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.