Your description here
This repo includes a setup for developing on STM32 using a custom build toolchain which allows you to use other GIT repositories as modules.
- Fork this project or use it as a template. (There are some differences)
- Change the STM32CUBEMX project accordingly via the
HMT26_template.iocfile or more easily via the STM32CUBEMX editor. - Click generate code in STM32CUBEMX
- Use your favorite IDE. If you're using vscode, use the included devcontainer. See below how to open the devcontainer via a task.
- To create your own code, you can use the Project folder.
- Run the
usb-passthrough-install.batto installusbipdon Windows. - Use
usb-passthrough-list.batto find where your STLink is connected. - Create a copy of the
usb-port.cfg.templateand rename it tousb-port.cfgand edit the usb port to the one you just found. - Run
usb-passthrough-bind.bat - To enable SSH passthrough for Windows to the devcontainer (assuming that you have the ssh keys in .ssh), you must run
sudo powershell (path\to\the\script)\enable-ssh-passthrough.ps1. You can verify that SSH passthrough works by entering the dev container (read some more below) and runningssh git@github.com. It should return something along the lines of "Hi [name]! You've successfully authenticated, but GitHub does not provide shell access".
There is one file in this project related to the ST32CUBEMX project. ST32CUBEMX can be installed via the website, then going to downloads, entering your email and then installing it via the installer that you got in your email.
The ST32CUBEMX project is used to automatically generate code. In there you can set the pinout, which peripherals to enable, and which functionality to use of the STM32. The default project in here enables the entire team to have the same general configuration. Of course, you have to change it per PCB type / codebase.
If you wish to change the name of the project, you can do that quite easily. You can change the name of the HMT26_template.ioc file, then you have to edit the two fields of the file:
ProjectManager.ProjectFileName=HMT26_template.ioc
ProjectManager.ProjectName=HMT26_template
STM32CUBEMX should then notice the changed project name.
The versions will be included at compile-time in a file called version.c. The version.h already exists before compilation, so you can include that in your file where you need the GIT hash. You can then use the variable with the first 6 tokens of the git hash in your project.
extern const uint32_t GIT_HASH;This is its definition.
To include modules, add the module name, SSH Git URL and hash/version to the modules.txt file:
example ssh@gitlab.com/example.ssh main
Important
You must have followed the setup for windows above!!!
- Open the devcontainer using the
Rebuild & Reopen Devcontainertask (so open it via the keybindings below), not the default one from VSCode. This task attaches the USB port everytime you enter the devcontainer. - Build and flash using the shortcut below
- Install OpenOCD from source (via package manager are almost always outdated).
- Install arm-eabi-none from source.
- You can now easily flash and build from linux. Make sure to setup the $PATH variables and launch.json correcctly.
| Action | Shortcut |
|---|---|
| Open task | ctrl+shift+P then Run task then your task |
| Build and flash (in container) | ctrl+shift+b |
Erik wanted to add custom keybindings for certain tasks, but this did not work. He tried to follow the vscode docs and this stackoverflow post, but did not manage to get it to work. So fix it if you'd like!
So the only reason that this template is public, is so that the workflow for template syncing is simpler.
Use the .templatesyncignore file to ignore certain files when the template is updated.
How to request a template sync? Well it should happen once every week automatically. Additionally, you can manually sync with the template by going to the Actions tab of your project, then clicking left on Sync changes from template, then requesting a manual rerun. This should create a pull request with the changes.
The project uses docker so that we are not dependent of the OS.
Make sure to have Docker Desktop installed and running.
To build the docker image
docker build -t stm32-dev -f .devcontainer/Dockerfile .
Then to run a container with the repo mounted
docker run --rm -it -v ${PWD}:/work -w /work stm32-dev bash
required on Windows bind mounts, not sure if others will have issues, but git has a safety check
git config --global --add safe.directory /work
Build (+ some other stuff)
rm -rf build
cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug
cmake --build build -j
if you want to run the tests in test folders do the following
rm -rf build-host
cmake -S tests -B build-host -DCMAKE_BUILD_TYPE=Debug
cmake --build build-host -j
ctest --test-dir build-host --output-on-failure
If gcc and g++ not working then first of that is very interesting and probably a problem but to check run
gcc --version
g++ --version
and fix
RUN apt-get update && apt-get install -y \
build-essential \
&& rm -rf /var/lib/apt/lists/*
docker build -t stm32-dev -f .devcontainer/Dockerfile .
you just run in the cmd. Image and analyze builds the docker image and does static analysis
.\scripts\image.ps1
.\scripts\analyze.ps1
The report is generated in build-host/clang-tidy.txt
The build script builds the code, test runs the tests. You will figure it out
.\scripts\build.ps1
.\scripts\test.ps1
Static analysis can be made nicer with clion integration.
winget install --id LLVM.LLVM -e
And again add the bin file to the path variables. You got this i believe in you.
check with
clang-tidy --version
clangd --version
To run the pipeline locally
winget install nektos.act
act --version
then
act -W .github/workflows/ci.yml
Template created by Daan Posthumus. Edited by Erik van Weelderen.
Feel free to use it.