Modified: 2024-01
This document will provide the resources developers need to get started working on the firmware for this project. We control our software versions tightly to reduce developer entropy. Please reference our required software documentation here for the correct software versions. For each section it is implied that you install the version referenced in this document.
- Toolchain Installation
- OpenOCD Installation
- CMake Installation
- VSCode Setup
- Compiling the Firmware
- Debugging
- Flashing the Firmware
- Issues
We first need to install the ARM toolchain on our local development machine. Note that these downloads are large and may take some time.
Note for Windows Installations - The binary files included as part of these software installations should be included as part of your system path. If the installer has the option, be sure to enable system path discovery.
Get the CMSIS arm-none-eabi-gcc
toolchain for ARM Cortex microcontrollers:
brew install --cask gcc-arm-embedded
Download the required version from the windows install link here
This project depends on a number of Python libraries. This is desireable because unlike system packages, python package versions can be checked into source control and enforced for all developers. You will need to install python3
and setup a virtual environment.
Activate the virtual environment, upgrade pip and install the dependancies with pip
:
python3 -m pip install --upgrade pip
python3 -m pip install -r requirements.txt
Get openocd
using brew
. Be sure to specify the required version:
brew install open-ocd@0.11.0
Download xPack OpenOCD from the github release link here
If you prefer not to use VSCode for editing or debugging you can skip this section.
In order to setup VSCode for development with STM32 microcontrollers, it is recommended you install the following extensions:
ms-vscode.cpptools
- C/C++ intellisense supportmarus25.cortex-debug
- STM32 Debugger Supporttwxs.cmake
- Provides CMake language intellisense
Create a .vscode
folder in the repository root and copy the files in the vscode directory into it. The files included provide the following capability:
c_cpp_properties.json
-> configuration for C/C++ intellisense and static analysis tools.launch.json
-> plugin for vscode debugging interface powered bycortex-debug
Because the c_cpp_properties.json
requires a compile commands file to be generated, you will need to build the firmware in order to realize these features. This is because intellisense is configured to look for a compile_commands.json
file in the build
directory to know how to find all the include headers and source files. When the firmware is built successfully a compile_commands.json
file will be present and you will be able to use intellisense features.
Clone this repository and navigate to the repository root:
git clone git@github.com:dronectl/raptor.git
cd raptor
Activate your python virtual environment then initialize the build system using cmake
. For development we should set the CMAKE_BUILD_TYPE
to DEBUG
:
Compile commands will be automatically generated by cmake which will be read by VSCode via the
c_cpp_properties.json
configuration.
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=DEBUG
...
Compile the firmware:
Hint: speed up build times by specifying
-j
(jobs) to enable multicore builds. Passing-j
with no job limit will allow any number of simultaneous jobs to run.
make -j
...
Once complete the binary should be built as raptor.elf
in the build
directory. You should also have a compile_commands.json
file which will now enable intellisense features (for VSCode users). If everything is done correctly there should be no red underline or default colored function names or variables indicating an unknown symbol. Below is an example of properly configured intellisense:
The flash step is powered by OpenOCD.
OpenOCD will retrieve the binary from
build/raptor.elf
and program the MCU using this configuration spec.
Plugin the evaluation board to your PC over mini USB and flash the microcontroller using the flash
directive:
make flash
This section will cover the steps to debug firmware using either VSCode powered by cortex-debug
or STM32CubeIDE. Depending on the debugging job, one or both of these tools may be used. It is important that all developers are familiar with STM32CubeIDE at minimum since it is the most feature rich debugging platform.
You must build the project with
-DCMAKE_BUILD_TYPE=DEBUG
to enable debug symbols.
Once the project binary is built, we can launch the vscode debugger using the F5
key. Under the hood VSCode references the launch.json
configuration file to use OpenOCD to flash the firmware and open a GDB server. To setup this configuration be sure to follow the steps in the VSCode Setup Here is a sample view of the debugger view:
Below is a list of capabilities provided by the cortex-debug
extension:
- Cortex peripheral register read and set
- Variable inspection and watchpoints
- Live breakpoints
- Task seperated call stacks
- Task runtime statistics
- MCU memory inspection
STM32CubeIDE is the most feature-rich debugging platform so for extensive debugging tasks it may be the preferred option. For example, some of the Serial Wire View features are not currently supported by the cortex-debug
VSCode extention.
We can follow these steps to debug the firmware in CubeIDE. Note that these steps are performed on MacOS but the same steps can be followed on any platform:
- Open CubeIDE (launch folder does not matter)
- Open a new project from file system:
- Select an external directory
- Select the
cube
folder in the repository root:
- Select Finish
- Select the predefined
raptor
debug configuration
- Verify the debugger works and matches as shown
Under the hood the raptor
debug configuration points to the firmware binary from build/raptor.elf
and uses the source references defined by the Cube project configuration settings.
If there are any issues with this documentation please contact me at christian911@sympatico.ca or create a new issue.