Development Environment
The SPARK SDK provides a seamless development experience with Visual Studio Code (VS Code), a popular and powerful source code editor. This section will guide you through setting up your development environment using VS Code and introduce the required extensions for debugging and for an optimized coding experience.
Prerequisites
Ensure that you have already followed the steps outlined in the Getting started section of the documentation, which covers the installation and setup of the SPARK SDK virtual environment. Having the virtual environment initialized is a prerequisite for testing example applications or writing your own.
Recommended extensions
The SPARK SDK is distributed with the /.vscode/extensions.json file which contains a list of VS Code extensions specifically tailored for STM32 microcontroller development. These extensions provide additional functionality and language support. The recommended extensions are:
marus25.cortex-debug: Provides debugging support for Cortex-M microcontrollers.
ms-vscode.cpptools: Offers C++ language support and advanced code editing features.
twxs.cmake: Adds CMake language support for building and configuring projects.
ms-vscode.cmake-tools: Offers a complete CMake build system integration within VS Code.
rioj7.command-variable: Enables the use of variables in VS Code commands for enhanced customization.
ms-python.python: Provides Python language support.
Creating a New Application Alongside the Example Applications
The most straight forward way to create a project for a new application is to start from an existing one that is similar. Use the procedure listed below to create a project for a new application called “My App” which is similar to the Hello World example.
Open a file explorer and duplicate the app/example/hello_world folder and rename it to app/example/my_app.
Rename app/example/my_app/hello_world_coord.c to app/my_app/my_app_coord.c. Do the same for the _node.c file.
Open the app/example/my_app/CMakeLists.txt file and change any reference to hello_world to my_app.
Open .vscode/cmake-variants.json and add a new entry for my_app.
"my_app": { "short": "My App", "settings": { "APP": "my_app" } }Add my_app variant to the list example application app/example/CMakeLists.txt.
elseif (APP STREQUAL "my_app") add_subdirectory(my_app)Duplicate the bsp/interface/app/hello_world folder and rename it to bsp/interface/app/my_app
Rename iface_hello_word.h and iface_hello_word_evk.c to iface_my_app.h and iface_my_app_evk.c.
Open bsp/interface/app/my_app/CMakeLists.txt and change any reference to hello_world to my_app.
Add my_app variant to the list example application bsp/interface/app/CMakeLists.txt.
elseif (APP STREQUAL "my_app") add_subdirectory(my_app)Replace any
#include "x_hello_world.h"with#include "x_my_app.h"in the new sources files.Select the my_app variant in VS Code and build the project.
At this point, the My App project should be functional and can be built just like the Hello World project. The content of my_app.c and swc_cfg.h can now be edited to reflect the My App application requirements.
Build System
The SPARK SDK uses CMake build system for project building and configuration. With CMakeLists, developers can define project structure, dependencies, and compile options in a concise and platform-independent manner. It supports various toolchains and platforms, allowing for seamless cross-platform development. With CMake, you can easily manage complex projects and specify library dependencies.
CMake external resources
The official CMake documentation is a comprehensive resource that covers all aspects of CMake, including syntax, commands, variables, and modules. You can access it at: https://cmake.org/documentation/
The CMake tutorial provides step-by-step instructions and examples to help you get started with CMake. It covers basic concepts, creating CMakeLists files, building projects, and more. You can find the tutorial here: https://cmake.org/cmake/help/latest/guide/tutorial/index.html