PER Firmware
Loading...
Searching...
No Matches
PER Monorepo Setup

This guide sets up the complete PER software development environment.

Table of Contents

  • 1. Clone the Repository
    • 1.1 Install Git
    • 1.2 Clone the Repository
  • 2. Install Visual Studio Code
    • 2.1 Install Recommended Extensions
  • 3. Install Platform + Unit Testing Tools
    • 3A. macOS
      • 3A.1 Install Homebrew
      • 3A.2 Install Apple's Command Line Tools
      • 3A.3 Install Firmware and Test Tools
    • 3B. Linux
      • 3B.1 Update the System
      • 3B.2 Install Development Tools
    • 3C. Windows - WSL
      • 3C.1 Install WSL
      • 3C.2 Update Ubuntu
      • 3C.3 Use VS Code inside of WSL
      • 3C.4 USB / ST-LINK Access
  • 4. Install Python Dependencies
  • 5. Install Rust/DAQ Tools
    • 5.1 Rust
    • 5.2 Linux / WSL DAQ Dependencies
    • 5.3 DaqCloud Database Tools
  • 6. Build the Repository
  • 7. Individual Build Commands
    • 7.1 Build All Firmware
    • 7.2 Run Firmware Static Analysis
    • 7.3 DAQ Workspace
    • 7.4 Build and Run Host Tests
  • 8. Build from VS Code
  • 9. Hardware Debugging

Platforms supported

It is possible to build the PER software on macOS, Linux, and Windows. However, if you are using Windows, you should either use WSL 2, a Linux virtual machine, or dual boot into Linux. (If you use a VM or dual boot, follow the Linux instructions.)

1. Clone the Repository

1.1 Install Git

Git is required on every platform.

Check that it is installed:

git --version

If you don't have git, see: Section 3.

1.2 Clone the Repository

Open a terminal and move to the directory where you want to keep the PER code. (Recommended: your home directory.)

Then clone the repository:

git clone --depth 1 https://github.com/PurdueElectricRacing/monorepo.git

Then initialize the submodules:

cd monorepo
git submodule update --init --depth 1

Check that it worked and submodules were also cloned:

ls
ls firmware/external/cmsis-device-g4/

You should see something like:

build_all.py daq Dockerfile docs firmware generators
LICENSE nix_flake README.md requirements.txt tests
CODE_OF_CONDUCT.md _htmresc LICENSE.md Release_Notes.html Source
CONTRIBUTING.md Include README.md SECURITY.md

2. Install Visual Studio Code

VS Code is the recommended editor for PER development.

Download and install VS Code:

After installing VS Code, open the repository:

cd monorepo # note: depends on where you cloned the repository
code .

You can also open it from the VS Code GUI: File -> Open Folder -> then navigate to where you cloned monorepo

2.1 Install Recommended Extensions

When VS Code prompts you to install the recommended extensions, install all of them.

You can also open the Extensions panel:

  • Windows/Linux: Ctrl + Shift + X
  • macOS: Cmd + Shift + X
  • Or click the Extensions icon on the left sidebar

and select Install All under the recommended extensions.

3. Install Platform + Unit Testing Tools

Install the tools for your operating system.

The FIL build requires Make (make) and Clang (clang++). Both tools must be available on PATH. See PER FIL tests for details.

3A. macOS

3A.1 Install Homebrew

Install Homebrew if it is not already installed.

Check:

brew --version

3A.2 Install Apple's Command Line Tools

Run:

xcode-select --install

These provide Make (make), the host compiler, and other standard development tools used by the project.

3A.3 Install Firmware and Test Tools

Run:

brew install \
git \
cmake \
ninja \
openocd \
stlink \
python3 \
lcov \
googletest \
cppcheck \
llvm

Override default Xcode LLVM:

echo 'export PATH="/opt/homebrew/opt/llvm/bin:$PATH"' >> ~/.zshrc
export LDFLAGS="-L/opt/homebrew/opt/llvm/lib"
export CPPFLAGS="-I/opt/homebrew/opt/llvm/include"
export CMAKE_PREFIX_PATH="/opt/homebrew/opt/llvm"

Install the ARM embedded compiler:

brew install --cask gcc-arm-embedded

Check:

git --version
cmake --version
ninja --version
python3 --version
arm-none-eabi-gcc --version
openocd --version
make --version
llvm-cov --version
clang++ --version

3B. Linux

If you are using linux, you probably already know what you're doing. However, here is an overview of the setup for Debian/apt-based distributions (Ubuntu, Debian, Pop!_OS, etc.).

3B.1 Update the System

sudo apt update
sudo apt upgrade

3B.2 Install Development Tools

sudo apt install \
git \
cmake \
ninja-build \
make \
gcc \
g++ \
clang \
llvm \
python3 \
python3-pip \
python3-venv \
gcc-arm-none-eabi \
openocd \
stlink-tools \
cppcheck \
lcov \
libgtest-dev \
pkg-config \
libudev-dev \
usbutils \
gdb-multiarch \
binutils-multiarch

Check:

git --version
cmake --version
ninja --version
python3 --version
arm-none-eabi-gcc --version
openocd --version
make --version
clang++ --version

3C. Windows - WSL

If your primary OS is Windows, it is highly advised to use:

  • WSL 2 with Ubuntu or
  • Dual boot into Linux or
  • A Linux virtual machine

for PER development.

Below are the instructions for WSL 2.

3C.1 Install WSL

Follow Microsoft's WSL installation guide: https://learn.microsoft.com/en-us/windows/wsl/install

After installation, install the most recent Ubuntu distribution. (As of the time of writing, Ubuntu 26.04 is the latest version.)

Open a WSL terminal and check:

uname -a

3C.2 Update Ubuntu

Inside WSL:

sudo apt update
sudo apt upgrade

Then follow the Linux instructions in Section 3B inside of WSL.

Additionally for WSL, run:

sudo apt install \
xdg-desktop-portal \
zenity

3C.3 Use VS Code inside of WSL

Install the normal Windows version of VS Code.

Then install the WSL extension.

From the WSL terminal, enter the repository and run:

code .

VS Code should open the repository using the WSL environment.

You can also open the repository inside of WSL + VS Code by Ctrl + Shift + P -> "WSL: Reopen Folder in WSL".

3C.4 USB / ST-LINK Access

Building inside WSL does not require USB access.

However. You will need additional USB configuration to connect an ST-LINK debugger directly to WSL.

This can be configured like so:

4. Install Python Dependencies

PER's build and code-generation tooling uses Python.

The repository currently pins its Python dependencies in requirements.txt.

For best integration with the VS Code tasks/launch configurations, install the dependencies to your system Python:

python3 -m pip install -r requirements.txt
Note
If you encounter an “externally managed environment” error, you can run:
python3 -m pip install -r requirements.txt --break-system-packages

5. Install Rust/DAQ Tools

5.1 Rust

Install Rust using rustup.

Run:

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

Then restart your terminal.

Use the stable Rust toolchain:

rustup default stable

Check:

rustc --version
cargo --version

5.2 Linux / WSL DAQ Dependencies

Linux needs additional packages for serial-device enumeration:

sudo apt install libudev-dev pkg-config

These were already installed in the Linux setup section.

5.3 DaqCloud Database Tools

On Ubuntu or Ubuntu inside WSL, install the SQLite CLI:

sudo apt update
sudo apt install sqlite3

Install the Diesel CLI with bundled SQLite support:

cargo install diesel_cli --version 2.3.3 --locked --no-default-features --features sqlite-bundled

Check:

diesel --version
sqlite3 --version

6. Build the Repository

The repository's main build entry point is:

python3 build_all.py

This builds the firmware, builds and tests all DAQ workspace targets, runs the generator and firmware host-test workflow, then builds FIL and runs the PER integration tests.

If this completes successfully, your development environment is set up correctly.

7. Individual Build Commands

You can also build individual parts of the repository.

7.1 Build All Firmware

python3 firmware/build_firmware.py

7.2 Run Firmware Static Analysis

python3 firmware/check_firmware.py

7.3 DAQ Workspace

From the repository root, build all workspace members and targets:

cargo build --manifest-path daq/Cargo.toml --workspace --all-targets --locked

To build only DaqApp from the repository root:

cargo build --manifest-path daq/daqapp/Cargo.toml --locked

Running binaries is supported only from their individual package directories. From the repository root, run DaqApp with:

cd daq/daqapp && cargo run

From the repository root, run DaqCli with:

cd daq/daqcli && cargo run

From the repository root, run DaqCloud with:

cd daq/daqcloud && cargo run

7.4 Run Generator and Firmware Host Tests

python3 tests/run_tests.py

This also generates the host-test coverage report.

8. Build from VS Code

Once the repository is open in VS Code, use:

  • Windows/Linux: Ctrl + Shift + B
  • macOS: Cmd + Shift + B

This will run the default build task, which builds the entire repository.

You can also use:

  • Ctrl/Cmd + Shift + B -> "Tasks: Run Task"

Then select the individual build task you want to run.

9. Hardware Debugging

Once your software build works, you can connect an ST-LINK debugger and flash firmware.

In VS Code:

  1. Open Run and Debug
  2. Select the appropriate MCU target
  3. Connect the ST-LINK to the target board
  4. Press the green ▶ button

The repository contains VS Code launch configurations for the supported targets.