In the previous post we have known that Visual Studio Code is a lightweight editor for small coding projects. However, you might still wonder how to actually take advantage of this small but powerful editor. In this post, we will see together how to develop embedded system projects in Visual Studio Code.
VS Code has an open-source solution for STM32 application developments. This solution is based on an extension called Platform IO. This extension does no more than integrating the ARM-GCC toolchain as well as OpenOCD debugger with Python scripts for automatic compiling, uploading and debugging. It provides a variety of popular STM32 frameworks, such as Arduino, Standard Peripheral Library, STM32Cube, etc. It also supports almost all types of popular STM32 development boards in the market. With this extension, we can easy code, compile and upload codes to the MCU all in VS Code. In a word, it is a combination of VS Code’s excellent coding autocomplete feature and the open-source ARM-GCC toolchain.
Although Platform IO has provided a large number of framework for a variety of boards, certain types of boards may lack support from some framework. Take my development experience for an example, I use STM32 value-line discovery (STM32VLDISCOVERY) board for project use, while the IDE does not offer a standard peripheral library framework support for it, which means that I cannot use standard peripheral library function calls in my project development. So how can I modify the core and add the support manually? Here comes the trick.
- Install the Platform IO IDE from VS Code’s extension page.
- Install the STM32 official support from the extension home page in VS Code.
- Clone the source from my personal GitHub repository.
- If Platform IO IDE is installed successfully, there should be a root folder called
.platformioin your computer. Find it out.
- Copy everything in folder
stm32vldiscovery-splfrom the GitHub repository you just cloned into the
Some explanations for my modification:
packages/framework-spl, there are two folders:
platformio/ldscriptscontains the linker script for STM32VLDISCOVERY board;
stm32contains the STM32F10x standard peripheral library from the STMicroelectronics official website.
platforms/ststm32, there are also two folders:
boardscontains a JSON file for the STM32VLDISCOVERY board. In the file,
stm32vldiscovery.cfgboard config file (already in the original Platform IO core) have been added, and the required defined macro
STM32F10X_MD_VLhas been added for the board;
builders/frameworkscontains a Python script for the standard peripheral library framework. In the file, standard peripheral library support for STM32F10x devices has been added.