on 2025-01-15 08:00 AM
This article highlights some tips on using VS Code with STM32.
In this article, we cover the following:
In this article How to use VS Code with STM32 microcontrollers, we discussed setting up your VS Code environment, creating a VS Code project, programming, and debugging through VS Code. If you have not already set up your VS Code environment, follow the steps in that article before exploring the content of this article. This article discusses common functions that can be helpful when developing your application through VS Code.
When developing your application, you may come across the need to perform a clean build of your project. To remove files that are generated by the makefile, you could use the CMake: Clean or CMake: Clean Rebuild functions to remove the previously generated files.
This can be done by typing >CMake: Clean into the search bar at the top of your screen and selecting the command.
Similarly, when changing configuration files, it is useful to use CMake Delete Cache and Reconfigure.
To perform this command, type >CMake Delete Cache into the search bar at the top of your screen, and once the command pops up, you can select it.
Another important thing to know when using VS Code to develop your application is how to add directories, source files, and include files. All of those files can be added through the CMakeLists.txt file. This file is created when your project code is generated, and you should be able to access it from your file explorer on the left panel.
Below you can see the locations where you can add project paths which are commented in the file. In addition to directories, source files, and include files, you can also define the build type, change compiler settings, add linked libraries, and make many other configurations through this file.
As you develop your STM32 applications in VS Code, you may desire to convert some of your existing STM32CubeIDE projects into VS Code projects. This is accomplished through the Embedded Tools Extension in VS Code.
When developing your application, you may want to use a Serial Monitor to see any USART communication. VS Code offers a Serial Monitor extension, so you can view USART communication within the IDE itself. This avoids the need for a third-party Serial Monitor tool.
uint8_t UARTbuffer[] = "Hello World!\r\n";
HAL_UART_Transmit(&huart2, &UARTbuffer, sizeof(UARTbuffer), 1000);
In this article, we discussed many useful points that may be helpful to you when using VS Code to develop your STM32 application. From this article you have learned to perform a clean rebuild, delete the project’s cache, and add source files and dependencies to your project. Additionally, how to create a VS Code project from an existing STM32CubeIDE project, and using the serial terminal extension.