Development Environment
The SPARK SDK provides a seamless development experience with Visual Studio Code (VS Code), a popular and powerful source code editor. The SDK is designed to simplify the development process by providing a virtual environment that comes pre-packaged with all necessary dependencies. This allows users and developers to quickly establish a development environment without the need to install dependencies directly onto their computer’s operating system. This section provides guidance on setting up the development environment using VS Code and introduces the required extensions for debugging and optimizing the coding experience.
This feature is optional, but highly recommended for those who wish to utilize the same development tools as SPARK developers.
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:
spark-microsystems.spark-sdk-vscode: The official SPARK SDK extension.
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.
Warning
This approach is recommended only for quick prototyping, as it might create issues when starting from an existing project or when updating SDK versions in the future. For complex projects, it is recommended to add the SPARK SDK as a submodule to the project and to use a custom toolchain to build. Refer to mouse and headset reference designs as examples.
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.
Rename app/example/my_app/facade/hello_world_facade.h to app/example/my_app/facade/my_app_facade.h.
Open the app/example/my_app/CMakeLists.txt file and change any reference to hello_world to my_app.
Open the app/example/my_app/swc_cfg_<radio_model>/CMakeLists.txt file and change any reference to hello_world to my_app.
Add the application to the CMakePresets.json in the project root.
Below are the 3 important configurations (base, target and application) that make up the CMakePresets.json file.
Base Configuration
{ "name": "base", "description": "Base configuration for all presets", "hidden": true, "generator": "Ninja", "binaryDir": "${sourceDir}/build/${presetName}", "cacheVariables": { "CMAKE_BUILD_TYPE": "RelWithDebInfo", "RADIO_INTERFACE_QSPI": "OFF", "RPC_ENABLED": "OFF", "RTOS_ENABLED": "OFF", "SWC_EXT_API_ENABLE": "OFF", "WPS_ENABLE_PHY_STATS_PER_BANDS": "OFF" } },This configuration is the starting point for all presets. It should not be modified. If any of the cacheVariables need to differ from base, they can be overwritten in the application configuration.
Target Configuration - Quasar
{ "name": "quasar", "description": "Base configuration quasar target", "hidden": true, "cacheVariables": { "HARDWARE": "QUASAR", "MCU_DRIVER": "STMU5XX" } },This configuration is hardware-specific. If the new application is expected to function on a SPARK EVK board, then no modifications need to be made. However, if adding custom hardware, a new target configuration should be created with its own HARDWARE and MCU_DRIVER cacheVariables. An example of custom hardware is presented below.
Target Configuration - Custom Hardware
{ "name": "custom_hardware", "description": "Base configuration custom hardware target", "hidden": true, "cacheVariables": { "HARDWARE": "CUSTOM", "MCU_DRIVER": "CUSTOM_MCU" } },In this example, the custom hardware uses a generic name and description. The cacheVariables for HARDWARE and MCU_DRIVER are new, which implies that the CMakeLists.txt files need to be modified to take into consideration the new variables.
Note
The base and target configurations are hidden and will be inherited by the application configuration.
Application Configuration - Hello World
{ "name": "hello-world-quasar", "description": "Hello-World example for SR11xx with Quasar", "hidden": false, "inherits": [ "base", "quasar" ], "cacheVariables": { "APP": "Hello-World", "TRANSCEIVER": "SR1100" } },Above is the Hello World configuration. It inherits from the base and quasar configurations, but can also overwrite the cacheVariables that it inherits. The configuration is not hidden and will appear in the list when choosing CMake: Select Configure Preset from the Command Palette. A new application configuration must be added when creating a new app. An example for “My app” is presented below.
Application Configuration - My app
{ "name": "my-app-custom-hardware", "description": "My App example for SR10xx with custom hardware", "hidden": false, "inherits": [ "base", "custom_hardware" ], "cacheVariables": { "APP": "my-app", "TRANSCEIVER": "SR1000" } },In this example, the applicaton configuration is given a generic name and description, as well as inherits base and custom_hardware configurations. The APP variable is new and therefore it needs to be added to the CMakeLists.txt as shown in the next step.
Add my_app to the list example application app/example/CMakeLists.txt.
elseif (APP STREQUAL "my_app") add_subdirectory(my_app)Depending on the EVK used, duplicate the backend/<evk_name>_backend/hello_world_backend folder and rename it to backend/<evk_name>_backend/my_app_backend.
Open backend/<evk_name>_backend/my_app_backend/CMakeLists.txt and change any reference to hello_world_backend to my_app_backend.
Add my_app to the list example application backend/<evk_name>_backend/CMakeLists.txt.
elseif (APP STREQUAL "my_app") add_subdirectory(my_app_backend)Replace all occurences of
hello_worldwithmy_appin the new sources files.Select the my_app preset 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.
SDK Release Static Libraries
The SDK release package provides prebuilt static libraries for the Wireless Core and the SPARK Radio PHY. Applications continue to link against the public SDK CMake targets, such as swc. The SDK build system resolves the required prebuilt libraries and their dependencies during the application build.
The Wireless Core prebuilt library is provided in:
core/wireless/prebuilt/
The SPARK Radio PHY prebuilt library is provided in:
driver/spark_radio/sr_phy/prebuilt/
Application-level SPARK Radio setup and access must be done through the Wireless Core public API, swc_api.h. The SPARK Radio PHY library is a dependency of the Wireless Core library and is not intended to be used directly by applications.
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