Trevware
Trevware is a VS Code extension for developing STM32 firmware for Terps Racing EV (TREV). It brings building, debugging, ST-Link flashing, and CAN firmware updates into one workspace, with project configuration tailored to TREV boards and their bootloaders.
The extension uses STM32CubeMX-generated Makefile projects and supports C and C++. Normal builds produce the standard firmware image. CAN Flash also builds two application bank images for the bootloader's update workflow on STM32F405 and STM32L4 boards.
Features
- Build and clean STM32 firmware projects from VS Code.
- Flash firmware over ST-Link/OpenOCD or CAN through a PCAN adapter.
- Generate STM32F405 and STM32L4 application bank linker scripts and firmware images.
- Read CAN bootloader metadata into
flashing/metadata.log.
- Keep board identity and firmware version separate from compiler and source configuration.
- Generate build tasks, Cortex-Debug launch configuration, and IntelliSense settings.
- Discover source files and headers, configure compiler flags, and link static libraries.
- Check for the required build tools and offer automatic installation.
Getting started
Requirements
- VS Code with the Cortex-Debug extension.
- STM32CubeMX for generating the initial project.
- GNU Arm Embedded Toolchain (
arm-none-eabi), Make, and OpenOCD. Trevware can check for these tools and offer to install them, or you can configure their paths in VS Code settings.
- An ST-Link probe for OpenOCD flashing and debugging.
CAN flashing also requires Python 3, Git for the flasher submodule, a PCAN adapter with the PEAK PCAN Basic driver, and a board running a compatible TREV CAN bootloader.
Set up a firmware project
- In STM32CubeMX, select Makefile under Project Manager > Project > Toolchain/IDE.
- Keep Copy all used libraries into the project folder enabled and generate the code.
- Open the generated project folder in VS Code, with its
.ioc file at the top level. Trevware only shows its tab and creates trevware.config.yaml for folders with a top-level .ioc file.
- Click the Terps Racing icon in the activity bar and install or configure any missing build tools.
- Select Build to generate the workspace configuration and compile the firmware.
- Review
trevware.config.yaml, especially the board ID, firmware version, and whether the board supports CAN flashing.
An existing flashing/stm32-build.config.yaml can also describe a custom project without a CubeMX Makefile. It must provide the required MCU, linker, source, and compiler configuration. A top-level .ioc file is still required for project detection.
Commands
| Action |
Behavior |
| Build |
Compile the project and generate its workspace configuration. |
| Clean Build |
Remove previous build outputs and rebuild. |
| Flash |
Build and program the firmware using ST-Link/OpenOCD. |
| Debug |
Start the generated Cortex-Debug session. |
| Flash (below the CAN separator) |
Build both application bank images and pass them to the CAN flasher. |
| Read Metadata |
Read the configured board's bootloader metadata and save the output to flashing/metadata.log. |
| Set Board ID |
Prompt for a new board ID and save it to the project config after the bootloader confirms it. |
The Actions menu shows Build, Clean Build, Flash, and Debug first. When can_flashing_supported is true, a --- CAN --- separator and the CAN actions appear below them: Flash, Read Metadata, and Set Board ID. After the first build, use Ctrl+Shift+B on Windows/Linux or Cmd+Shift+B on macOS to run the normal build task.
Trevware exposes its actions as tools in VS Code chat (VS Code 1.99 or newer). In the Chat view,
select Agent, open Configure Tools, and enable the Trevware tools. You can ask for an action
in plain language or reference a tool directly:
| Reference |
Action |
#trevwareBuild |
Build firmware. |
#trevwareCleanBuild |
Clean and rebuild firmware. |
#trevwareFlash |
Build and flash using ST-Link/OpenOCD. |
#trevwareCanFlash |
Build both banks and flash over CAN. |
#trevwareReadCanMetadata |
Read bootloader metadata and return its log. |
#trevwareStartDebug |
Start the generated Cortex-Debug session. |
#trevwareCheckBuildTools |
Check tool readiness and return configured paths. |
#trevwareInstallBuildTools |
Install and validate the build tools. |
For example: “Use #trevwareBuild to build release firmware” or “Read the board's CAN metadata.”
Build tools accept debug: false for release firmware and default to debug firmware.
Project actions operate on the first workspace folder and require an existing CubeMX Makefile
or Trevware build configuration. Build once before starting a debug session.
Tools require a trusted workspace and show a confirmation describing the action and project.
Build and flash tools wait for their tasks to finish; failures are returned to chat with available
compiler diagnostics. Full task output remains in the task terminal. Cancelling a build, flash,
or metadata read stops its active task/process. Tool installation continues once started.
Only one Trevware chat action can run at a time.
CAN tools follow the project's CAN setting and validate support when invoked.
Project configuration
The root trevware.config.yaml contains the board metadata:
board_id: 0
reset_msg_can_id: 0
firmware_version: 0
can_flashing_supported: true
| Field |
Purpose |
board_id |
Board identifier passed to the CAN flasher. Accepts integers from 0 through 255. |
reset_msg_can_id |
CAN reset-message ID stored in the project metadata; must be an integer. |
firmware_version |
Integer image version passed to the CAN flasher. |
can_flashing_supported |
Boolean enabling CAN actions and supported application bank layouts; defaults to true in generated configuration. |
Normal build, ST-Link flash, and debug actions always use the original single-image layout, regardless of can_flashing_supported. Set it to false to hide and disable CAN actions.
Build output names come from the CubeMX Makefile's target, or the workspace folder name when no target is available.
Edit flashing/stm32-build.config.yaml to configure source files, include directories, exclusions, compiler definitions and flags, static libraries, language, and the linker script. The generated YAML includes comments explaining its settings.
For C++ builds, set the build configuration's language to C++. You can provide main.cpp; if the project still uses main.c, Trevware creates a build copy at build/main.cpp when needed.
Trevware generates these supporting files:
| Path |
Purpose |
flashing/STM32Make.make |
Makefile used by the extension. |
flashing/.stm32env |
Local compiler and OpenOCD paths. |
flashing/openocd.cfg |
Probe and target configuration for flashing and debugging. |
.vscode/tasks.json |
Workspace build tasks. |
.vscode/launch.json |
Cortex-Debug launch configuration. |
.vscode/c_cpp_properties.json |
IntelliSense configuration. |
The current VS Code settings and command IDs retain the stm32-for-vscode prefix inherited from the original extension. Tool settings include stm32-for-vscode.armToolchainPath, stm32-for-vscode.makePath, and stm32-for-vscode.openOCDPath.
CAN flashing
CAN Flash supports STM32F405 and STM32L4 projects with can_flashing_supported: true and a bootloader that uses the TREV VCU CAN protocol. It builds both application bank binaries, checks that each fits its bank, and passes them with the configured board ID and firmware version to the CAN flasher. The bootloader selects which bank to update. trev-cantools repository
For automatic bootloader entry, the running application must handle the CAN reset request sent by the flasher. You can also start the transfer while the board is already in its bootloader.
When an STM32 project is opened, Trevware adds or initializes flashing/trev-cantools for every MCU family, even when CAN flashing is disabled. Automatic setup requires a firmware Git checkout and GitHub credentials with read access to the private trev-cantools repository. CAN Flash also ensures that the flasher is available. Trevware honors the firmware project's pinned trev-cantools revision.
Once the flasher is available, install its Python dependencies using the same Python interpreter configured for Trevware:
python -m pip install -r flashing/trev-cantools/requirements.txt
Use python3 if that is your interpreter's command. If the initial CAN Flash invocation stopped because dependencies were missing, install them and run it again.
Configure the CAN connection in VS Code settings.
| Setting |
Default |
Purpose |
stm32-for-vscode.pythonPath |
Automatic Python discovery |
Python 3 interpreter used for CAN commands. |
stm32-for-vscode.canChannel |
PCAN_USBBUS1 |
PCAN channel. |
stm32-for-vscode.canBitrate |
500000 |
CAN bitrate in bits per second. |
Read CAN Metadata uses the flasher's read command on STM32F405 and STM32L4 and writes its output to flashing/metadata.log. If the flasher is missing, invoke CAN Flash to set it up first.
Set CAN Board ID addresses the board using board_id in trevware.config.yaml. With the board in its bootloader, enter an ID from 0 through 255. Trevware updates board_id after the bootloader confirms the save over CAN.
Application bank layouts
CAN Flash generates the following application regions for STM32F405 and STM32L4 projects with CAN flashing enabled:
| MCU |
Image |
Linker script in flashing/ |
Flash origin |
Length |
Last address |
| STM32F405 |
Bank A |
STM32F405_Sectors_5_6.ld |
0x08020000 |
256 KB |
0x0805FFFF |
| STM32F405 |
Bank B |
STM32F405_Sectors_7_8.ld |
0x08060000 |
256 KB |
0x0809FFFF |
| STM32L4 |
Bank A |
STM32L4_Bank_A.ld |
0x08009000 |
106 KiB |
0x080237FF |
| STM32L4 |
Bank B |
STM32L4_Bank_B.ld |
0x08023800 |
106 KiB |
0x0803DFFF |
For STM32L4, the generated scripts preserve RAM regions and sections from the configured ldscript. That script must contain one FLASH memory region, and the source list must contain one system_stm32l4xx.c. A generated wrapper sets VTOR to the linked application address after Cube's SystemInit for the bank images.
Build and Clean Build produce only the standard image using the original linker script and startup code. CAN Flash additionally builds Bank A and Bank B. Debug outputs are:
build/debug/<target>.*
build/debug/bank-a/<target>-bank-a.*
build/debug/bank-b/<target>-bank-b.*
Release builds use the same structure under build/release/. Outputs include ELF, HEX, BIN, and disassembly files.
Flash STM32 programs the standard image over ST-Link/OpenOCD, and the generated debug configuration uses the standard ELF, regardless of the CAN setting.
The bank images require an existing compatible bootloader. Trevware does not build or install that bootloader; the STM32L4 application bank scripts leave the area below 0x08009000 and the reserved 8 KiB at 0x0803E000–0x0803FFFF untouched.
Automatic extension releases
Every push to main or master runs the Build and publish extension GitHub Actions workflow. It installs locked dependencies, type-checks and lints the code, builds the production bundle, and publishes a VSIX to GitHub Releases. A failed check or build prevents publishing.
The packaged version uses the major and minor version from package.json, with the workflow run number added to its patch version. For example, base version 1.2.0 and run 15 produce 1.2.15. Version changes happen only in the runner; the workflow does not commit back to the branch. Releases are tagged build-<run number> and point to the pushed commit. Re-running a workflow replaces that run's VSIX.
GitHub's built-in GITHUB_TOKEN publishes the release; no additional secret is needed. This workflow publishes downloadable GitHub releases. VS Code Marketplace publishing requires separate publisher credentials and is not configured here.
To install a release, download its .vsix file and run Extensions: Install from VSIX... in VS Code. To build a VSIX locally, use Node.js 22 or newer, run npm ci, then npm run package.
Credits and license
Trevware is based on STM32 for VSCode by Bureau Moeilijke Dingen, adapted for Terps Racing EV's firmware development and CAN update workflow. It is distributed under the MIT license, with the original copyright notices retained.