While working on the next revision of the moteus controller, I started by bringing up a software toolchain on a NUCLEO-G474RE board. Unfortunately, even the most recent mbed 5.14 doesn’t yet support that processor. Thus, I have a half-baked solution which pulls in the ST CUBE sources for that controller into the mbed tree as a patch.
The patch only implements wrappers for the things I care about, so it isn’t a complete solution. Since I am not really using any mbed libraries anymore in any project, that isn’t a whole lot. Right now I’m just using it for the one function that sets up the board, a linker script, and the pin mappings. I will probably eventually just make a rules_stm32 and ditch mbed entirely but for now that is more work than it is worth.
When working on the firmware for Super Mega Microbot’s improved actuators, I decided to try using mbed-os from ARM for the STM32 libraries instead of the HAL libraries. I always found that the HAL libraries had a terrible API, and yet they still required that any non-trivial usage of the hardware devolve into register twiddling to be effective. mbed presents a pretty nice C++ API for the features they do support, which is only a little less capable than HAL, but still makes it trivial to drop down to register twiddling when necessary (and includes all of the HAL by reference).
Most people probably use mbed through their online IDE. While this is a remarkable convenience, I am a big fan of reproducibility of builds and also of host based testing. mbed provides mbed-cli which gets part of the way there by letting you build offline. Unfortunately, it still doesn’t provide great support for projects that both deploy to a target and have automated unit tests. It actually has zero support for unit tests that can run on the host.
As many have guessed, I’m a big fan of bazel https://bazel.build, for building software projects. Despite being raw around the edges, it does a lot of things right. Its philosophy is to be fast, correct, and reproducible. While it doesn’t support flagless multi-platform builds yet (#6519), it does provide some minimal multi-platform support. It also has robust capabilities for pulling in external projects, including entire toolchains and build environments. Finally, it has excellent support for host based unit tests.
To make it work, you do have to configure a toolchain though. That I’ve now done for at least STM32F4 based mbed targets. It is published under an Apache 2.0 license at: https://github.com/mjbots/rules_mbed
- Seamless toolchain provisioning: It configures bazel to automatically download a recent GNU gcc toolchain from ARM (2018q2).
- Processor support: Currently all STM32F4 processors are supported, although others could be added with minimal effort.
- Host based testing: Common modules that rely only on the standard library can have unit tests run on the host using any C/C++ testing tools such as boost::test.
- Simultaneous multi-target configuration: Multiple targets (currently limited to the same CPU family) can be built with a single bazel command. Multiple families can be configured within the same source tree.
Once you have it installed in a project, building all host based tests is as simple as:
tools/bazel test //...
and building all binary output files is as simple as:
tools/bazel test -c opt --cpu=stm32f4 //...