Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ workspace.code-workspace

.cache
compile_commands.json

/result
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,18 @@ Open up a terminal
3. `make` <-- Pick out the name of your target device from the supported boards list. For instance, I have a Trampa **VESC 100/250**, so my target is `100_250`
4. `make 100_250` <-- This will build the **VESC 100/250** firmware and place it into the `bldc/builds/100_250/` directory

## Building with Nix

Nix is a build tool which manages all dependencies. With [Nix flakes](https://nixos.wiki/wiki/Flakes)
enabled, build the general-purpose firmware package from the repository root.

```bash
nix build .#bldc-fw
```

The packaged firmware and `res_fw.qrc` are available under `result/`.
All boards are built by default. `make *_flash` helpers are not supported with nix.

## Other tools

**Linux Optional - Add udev rules to use the stlink v2 programmer without being root**
Expand Down
61 changes: 61 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 39 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
description = "Packages VESC firmware into a flake.";

inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-26.05";
flake-utils.url = "github:numtide/flake-utils";
};

outputs =
{
self,
nixpkgs,
flake-utils,
}:
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = import nixpkgs {
inherit system;
};
bldc-fw = pkgs.callPackage ./pkgs/bldc.nix {
src = self;
};
in
{
packages = {
inherit bldc-fw;
default = bldc-fw;
};
}
)
// {
overlays.default = final: _prev: {
bldc-fw = final.callPackage ./pkgs/bldc.nix {
src = self;
};
};
};
}
7 changes: 0 additions & 7 deletions package_firmware.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,10 @@
import subprocess
import sys

# https://stackoverflow.com/questions/14989858/get-the-current-git-hash-in-a-python-script
def get_git_revision_short_hash() -> str:
return subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD']).decode('ascii').strip()

# Get the origin and destination directories
build_dir = os.path.dirname(os.path.abspath(__file__)) + '/build'
package_dir = os.path.dirname(os.path.abspath(__file__)) + '/package'

# Get the short git hash
git_hash = get_git_revision_short_hash()

# Define default destination filenames
no_limits_name = "VESC_default_no_hw_limits.bin"
default_name = "VESC_default.bin"
Expand Down
56 changes: 56 additions & 0 deletions pkgs/bldc.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Builds res_fw.qrc for the specified firmware versions.
{
src,
# List of bldc board names to be built, i.e. a list of bldc "fw_*" Makefile
# targets without the "fw_" prefix.
# Can also be the string "all", which builds all standard board firmwares.
fwBoards ? [ ],

gcc-arm-embedded-14,
git,
python3,
stdenv,
}:

let
fwTargets =
if fwBoards == "all" then
[ "all_fw" ]
# VESC Tool doesn't build if the provided res_fw.qrc file is empty for some
# reason. Therefore always include "general purpose" firmware.
else
builtins.map (board: "fw_${board}") (fwBoards ++ [ "gp" ]);
in
stdenv.mkDerivation rec {
pname = "bldc-fw";
version = src.shortRev or src.dirtyShortRev or "unknown";

BLDC_FW_SHORT_SHA = src.shortRev or "unknown";

inherit src;

dontPatch = true;
dontFixup = true;

buildPhase = ''
${
if builtins.length fwTargets != 0 then
"make -j $NIX_BUILD_CORES ${builtins.concatStringsSep " " fwTargets}"
else
""
}

python package_firmware.py
'';
installPhase = ''
mkdir -p $out

cp -r ./package/* $out/
'';

nativeBuildInputs = [
gcc-arm-embedded-14
python3
git
];
}